From 9f4afd7a91bf04f7ac877467a38aea31d6bb06ad Mon Sep 17 00:00:00 2001 From: Greg Hays Date: Sun, 10 Sep 2023 11:47:07 -0700 Subject: [PATCH] CODE RUB: PostImpressions Exceptions Upgrade v2.10.0 Closes: #510 --- ...ImpressionServiceTests.Exception.Modify.cs | 170 ++++-- ...stImpressionServiceTests.Exceptions.Add.cs | 526 +++++++++--------- ...ssionServiceTests.Exceptions.RemoveById.cs | 72 ++- ...sionServiceTests.Exceptions.RetrieveAll.cs | 47 +- ...ionServiceTests.Exceptions.RetrieveById.cs | 43 +- .../PostImpressionServiceTests.Logic.Add.cs | 28 +- ...PostImpressionServiceTests.Logic.Modify.cs | 56 +- ...ImpressionServiceTests.Logic.RemoveById.cs | 20 +- ...mpressionServiceTests.Logic.RetrieveAll.cs | 27 +- ...pressionServiceTests.Logic.RetrieveById.cs | 20 +- ...mpressionServiceTests.Validation.Modify.cs | 241 +++++--- ...tImpressionServiceTests.Validations.Add.cs | 75 ++- ...sionServiceTests.Validations.RemoveById.cs | 56 +- ...onServiceTests.Validations.RetrieveById.cs | 13 +- .../PostImpressionServiceTests.cs | 11 +- .../AlreadyExistsPostImpressionException.cs | 20 +- .../FailedPostImpressionServiceException.cs | 20 +- .../FailedPostImpressionStorageException.cs | 20 +- .../InvalidPostImpressionException.cs | 7 +- ...InvalidPostImpressionReferenceException.cs | 19 +- .../LockedPostImpressionException.cs | 10 +- .../Exceptions/NullPostImpressionException.cs | 18 +- .../PostImpressionDependencyException.cs | 20 +- ...ImpressionDependencyValidationException.cs | 20 +- .../PostImpressionServiceException.cs | 20 +- .../PostImpressionValidationException.cs | 11 +- .../PostImpressionService.Exceptions.cs | 2 +- .../PostImpressionService.Validations.cs | 17 +- .../PostImpressions/PostImpressionService.cs | 48 +- 29 files changed, 1013 insertions(+), 644 deletions(-) diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exception.Modify.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exception.Modify.cs index 5f5df766..3d99f72d 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exception.Modify.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exception.Modify.cs @@ -18,49 +18,64 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.PostImpressions public partial class PostImpressionServiceTests { [Fact] - public async Task ShouldThrowCriticalDependencyExceptionOnModifyIfSqlErrorOccursAndLogItAsync() + private async Task ShouldThrowCriticalDependencyExceptionOnModifyIfSqlErrorOccursAndLogItAsync() { - //given + // given DateTimeOffset randomDateTime = GetRandomDateTime(); - PostImpression randomPostImpression = CreateRandomModifyPostImpression(randomDateTime); + + PostImpression randomPostImpression = + CreateRandomModifyPostImpression(randomDateTime); + PostImpression somePostImpression = randomPostImpression; Guid postId = somePostImpression.PostId; Guid profileId = somePostImpression.ProfileId; SqlException sqlException = GetSqlException(); var failedPostImpressionStorageException = - new FailedPostImpressionStorageException(sqlException); + new FailedPostImpressionStorageException( + message: "Failed post impression storage error has occurred, contact support.", + innerException: sqlException); var expectedPostImpressionDependencyException = - new PostImpressionDependencyException(failedPostImpressionStorageException); + new PostImpressionDependencyException( + message: "Post impression dependency error has occurred, please contact support.", + innerException: failedPostImpressionStorageException); this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()).Throws(sqlException); + broker.GetCurrentDateTimeOffset()) + .Throws(sqlException); this.storageBrokerMock.Setup(broker => - broker.SelectPostImpressionByIdAsync(postId, profileId)).Throws(sqlException); + broker.SelectPostImpressionByIdAsync(postId, profileId)) + .Throws(sqlException); - //when + // when ValueTask modifyPostImpression = this.postImpressionService.ModifyPostImpressionAsync(somePostImpression); PostImpressionDependencyException actualPostImpressionDependencyException = - await Assert.ThrowsAsync(modifyPostImpression.AsTask); + await Assert.ThrowsAsync( + modifyPostImpression.AsTask); - //then - actualPostImpressionDependencyException.Should().BeEquivalentTo(expectedPostImpressionDependencyException); + // then + actualPostImpressionDependencyException.Should().BeEquivalentTo( + expectedPostImpressionDependencyException); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTimeOffset(), Times.Once); this.loggingBrokerMock.Verify(broker => - broker.LogCritical(It.Is(SameExceptionAs(expectedPostImpressionDependencyException))), Times.Once); + broker.LogCritical(It.Is(SameExceptionAs( + expectedPostImpressionDependencyException))), + Times.Once); this.storageBrokerMock.Verify(broker => - broker.SelectPostImpressionByIdAsync(postId, profileId), Times.Never); + broker.SelectPostImpressionByIdAsync(postId, profileId), + Times.Never); this.storageBrokerMock.Verify(broker => - broker.UpdatePostImpressionAsync(somePostImpression), Times.Never); + broker.UpdatePostImpressionAsync(somePostImpression), + Times.Never); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); @@ -68,50 +83,65 @@ public async Task ShouldThrowCriticalDependencyExceptionOnModifyIfSqlErrorOccurs } [Fact] - public async Task ShouldThrowDependencyExceptionOnModifyIfDatabaseUpdateExceptionOccursAndLogItAsync() + private async Task ShouldThrowDependencyExceptionOnModifyIfDatabaseUpdateExceptionOccursAndLogItAsync() { - //given + // given int minutesInPast = GetRandomNegativeNumber(); DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); - PostImpression randomPostImpression = CreateRandomPostImpression(randomDateTime); + + PostImpression randomPostImpression = + CreateRandomPostImpression(randomDateTime); + PostImpression somePostIpression = randomPostImpression; Guid postId = somePostIpression.PostId; Guid profileId = somePostIpression.ProfileId; - somePostIpression.CreatedDate = randomDateTime.AddMinutes(minutesInPast); + + somePostIpression.CreatedDate = + randomDateTime.AddMinutes(minutesInPast); + var databaseUpdateException = new DbUpdateException(); var failedPostImpressionStorageException = - new FailedPostImpressionStorageException(databaseUpdateException); + new FailedPostImpressionStorageException( + message: "Failed post impression storage error has occurred, contact support.", + innerException: databaseUpdateException); var expectedPostImpressionDependencyException = - new PostImpressionDependencyException(failedPostImpressionStorageException); + new PostImpressionDependencyException( + message: "Post impression dependency error has occurred, please contact support.", + innerException: failedPostImpressionStorageException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()).Returns(randomDateTime); this.storageBrokerMock.Setup(broker => - broker.SelectPostImpressionByIdAsync(postId, profileId)).ThrowsAsync(databaseUpdateException); + broker.SelectPostImpressionByIdAsync(postId, profileId)) + .ThrowsAsync(databaseUpdateException); - //when + // when ValueTask modifyPostImpression = this.postImpressionService.ModifyPostImpressionAsync(somePostIpression); PostImpressionDependencyException actualPostImpressionDependencyException = - await Assert.ThrowsAsync(modifyPostImpression.AsTask); + await Assert.ThrowsAsync( + modifyPostImpression.AsTask); - //then + // then actualPostImpressionDependencyException.Should().BeEquivalentTo( expectedPostImpressionDependencyException); this.storageBrokerMock.Verify(broker => - broker.SelectPostImpressionByIdAsync(postId, profileId), Times.Once); - + broker.SelectPostImpressionByIdAsync(postId, profileId), + Times.Once); + this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), Times.Once); + broker.GetCurrentDateTimeOffset(), + Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionDependencyException))), Times.Once); + expectedPostImpressionDependencyException))), + Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); @@ -119,23 +149,35 @@ public async Task ShouldThrowDependencyExceptionOnModifyIfDatabaseUpdateExceptio } [Fact] - public async Task ShouldThrowDependencyValidationExceptionOnModifyIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync() + private async Task ShouldThrowDependencyValidationExceptionOnModifyIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync() { - //given + // given int minutesInPast = GetRandomNegativeNumber(); DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); - PostImpression randomPostImpression = CreateRandomPostImpression(randomDateTime); + + PostImpression randomPostImpression = + CreateRandomPostImpression(randomDateTime); + PostImpression somePostImpression = randomPostImpression; - randomPostImpression.CreatedDate = randomDateTime.AddMinutes(minutesInPast); + + randomPostImpression.CreatedDate = + randomDateTime.AddMinutes(minutesInPast); + Guid postId = somePostImpression.PostId; Guid profileId = somePostImpression.ProfileId; - var databaseUpdateConcurrencyException = new DbUpdateConcurrencyException(); + + var databaseUpdateConcurrencyException = + new DbUpdateConcurrencyException(); var lockedPostImpressionException = - new LockedPostImpressionException(databaseUpdateConcurrencyException); + new LockedPostImpressionException( + message: "Locked post impression record exception, please try again later", + innerException: databaseUpdateConcurrencyException); var expectedPostImpressionDependencyValidationException = - new PostImpressionDependencyValidationException(lockedPostImpressionException); + new PostImpressionDependencyValidationException( + message: "Post impression dependency validation occurred, please try again.", + innerException: lockedPostImpressionException); this.storageBrokerMock.Setup(broker => broker.SelectPostImpressionByIdAsync(postId, profileId)) @@ -144,26 +186,29 @@ public async Task ShouldThrowDependencyValidationExceptionOnModifyIfDatabaseUpda this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()).Returns(randomDateTime); - //when + // when ValueTask modifyPostImpression = this.postImpressionService.ModifyPostImpressionAsync(somePostImpression); PostImpressionDependencyValidationException actualPostImpressionDependencyValidationException = await Assert.ThrowsAsync(modifyPostImpression.AsTask); - //then + // then actualPostImpressionDependencyValidationException.Should().BeEquivalentTo( expectedPostImpressionDependencyValidationException); this.storageBrokerMock.Verify(broker => - broker.SelectPostImpressionByIdAsync(postId, profileId), Times.Once); + broker.SelectPostImpressionByIdAsync(postId, profileId), + Times.Once); this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), Times.Once); + broker.GetCurrentDateTimeOffset(), + Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionDependencyValidationException))), Times.Once); + expectedPostImpressionDependencyValidationException))), + Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); @@ -171,54 +216,69 @@ public async Task ShouldThrowDependencyValidationExceptionOnModifyIfDatabaseUpda } [Fact] - public async Task ShouldThrowServiceExceptionOnModifyIfDatabaseUpdateErrorOccursAndLogItAsync() + private async Task ShouldThrowServiceExceptionOnModifyIfDatabaseUpdateErrorOccursAndLogItAsync() { - //given + // given int minutesInPast = GetRandomNegativeNumber(); DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); - PostImpression randomPostImpression = CreateRandomPostImpression(randomDateTime); + + PostImpression randomPostImpression = + CreateRandomPostImpression(randomDateTime); + PostImpression somePostImpression = randomPostImpression; Guid postId = somePostImpression.PostId; Guid profileId = somePostImpression.ProfileId; - somePostImpression.CreatedDate = randomDateTime.AddMinutes(minutesInPast); + + somePostImpression.CreatedDate = + randomDateTime.AddMinutes(minutesInPast); + var serviceException = new Exception(); var failedPostImpressionService = - new FailedPostImpressionServiceException(serviceException); + new FailedPostImpressionServiceException( + message: "Failed post impression service occurred, please contact support.", + innerException: serviceException); var expectedPostImpressionServiceException = - new PostImpressionServiceException(failedPostImpressionService); + new PostImpressionServiceException( + message: "Post impression service error occurred, please contact support.", + innerException: failedPostImpressionService); - this.storageBrokerMock.Setup(broker => - broker.SelectPostImpressionByIdAsync(postId, profileId)).ThrowsAsync(serviceException); + this.storageBrokerMock.Setup(broker => + broker.SelectPostImpressionByIdAsync(postId, profileId)) + .ThrowsAsync(serviceException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()).Returns(randomDateTime); - //when + // when ValueTask modifyPostImpression = this.postImpressionService.ModifyPostImpressionAsync(somePostImpression); PostImpressionServiceException actualPostImpressionServiceException = - await Assert.ThrowsAsync(modifyPostImpression.AsTask); + await Assert.ThrowsAsync( + modifyPostImpression.AsTask); - //then + // then actualPostImpressionServiceException.Should().BeEquivalentTo( expectedPostImpressionServiceException); this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), Times.Once); + broker.GetCurrentDateTimeOffset(), + Times.Once); this.storageBrokerMock.Verify(broker => - broker.SelectPostImpressionByIdAsync(postId, profileId), Times.Once); + broker.SelectPostImpressionByIdAsync(postId, profileId), + Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionServiceException))), Times.Once); + expectedPostImpressionServiceException))), + Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); } } -} +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.Add.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.Add.cs index 1b998fdd..d9cf2f4b 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.Add.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.Add.cs @@ -16,252 +16,280 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.PostImpressions { - public partial class PostImpressionServiceTests - { - [Fact] - public async Task ShouldThrowCriticalDependencyExceptionOnAddIfSqlErrorOccursAndLogItAsync() - { - //given - DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); - PostImpression somePostImpression = CreateRandomPostImpression(randomDateTime); - SqlException sqlException = GetSqlException(); - - var failedPostImpressionStorageException = - new FailedPostImpressionStorageException(sqlException); - - var expectedPostImpressionDependencyException = - new PostImpressionDependencyException(failedPostImpressionStorageException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Throws(sqlException); - - //when - ValueTask addPostImpressionTask = - this.postImpressionService.AddPostImpressions(somePostImpression); - - PostImpressionDependencyException actualPostImpressionDependencyException = - await Assert.ThrowsAsync( - addPostImpressionTask.AsTask); - - //then - actualPostImpressionDependencyException.Should().BeEquivalentTo( - expectedPostImpressionDependencyException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.loggingBrokerMock.Verify(broker => - broker.LogCritical(It.Is(SameExceptionAs( - expectedPostImpressionDependencyException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.InsertPostImpressionAsync(It.IsAny()), - Times.Never); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowDependencyValidationExceptionOnAddIfPostImpressionAlreadyExistsAndLogItAsync() - { - //given - PostImpression randomPostImpression = CreateRandomPostImpression(); - PostImpression alreadyExistsPostImpression = randomPostImpression; - string randomMessage = GetRandomMessage(); - - var duplicateKeyException = - new DuplicateKeyException(randomMessage); - - var alreadyExistsPostImpressionException = - new AlreadyExistsPostImpressionException(duplicateKeyException); - - var expectedPostImpressionDependencyValidationException = - new PostImpressionDependencyValidationException(alreadyExistsPostImpressionException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Throws(duplicateKeyException); - - //when - ValueTask addPostImpressionTask = - this.postImpressionService.AddPostImpressions(alreadyExistsPostImpression); - - PostImpressionDependencyValidationException actualPostImpressionDependencyValidationException = - await Assert.ThrowsAsync( - addPostImpressionTask.AsTask); - - //then - actualPostImpressionDependencyValidationException.Should().BeEquivalentTo( - expectedPostImpressionDependencyValidationException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.InsertPostImpressionAsync(It.IsAny()), - Times.Never); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionDependencyValidationException))), - Times.Once); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowDependencyExceptionOnAddIfDatabaseUpdateErrorOccursAndLogItAsync() - { - //given - PostImpression somePostImpression = CreateRandomPostImpression(); - - var databaseUpdateException = - new DbUpdateException(); - - var failedPostImpressionStorageException = - new FailedPostImpressionStorageException(databaseUpdateException); - - var expectedPostImpressionDependencyException = - new PostImpressionDependencyException(failedPostImpressionStorageException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Throws(databaseUpdateException); - - //when - ValueTask addPostImpressionTask = - this.postImpressionService.AddPostImpressions(somePostImpression); - - PostImpressionDependencyException actualPostImpressionDependencyException = - await Assert.ThrowsAsync( - addPostImpressionTask.AsTask); - - //then - actualPostImpressionDependencyException.Should().BeEquivalentTo( - expectedPostImpressionDependencyException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.InsertPostImpressionAsync(It.IsAny()), - Times.Never); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionDependencyException))), - Times.Once); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async void ShouldThrowDependencyValidationExceptionOnAddIfReferenceErrorOccursAndLogItAsync() - { - //given - PostImpression somePostImpression = CreateRandomPostImpression(); - string randomMessage = GetRandomMessage(); - string exceptionMessage = randomMessage; - - var foreignKeyConstraintConflictException = - new ForeignKeyConstraintConflictException(exceptionMessage); - - var invalidPostImpressionReferenceException = - new InvalidPostImpressionReferenceException(foreignKeyConstraintConflictException); - - var expectedPostImpressionDependencyValidationException = - new PostImpressionDependencyValidationException(invalidPostImpressionReferenceException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Throws(foreignKeyConstraintConflictException); - - //when - ValueTask addPostImpressionTask = - this.postImpressionService.AddPostImpressions(somePostImpression); - - PostImpressionDependencyValidationException actualPostImpressionDependencyValidationException = - await Assert.ThrowsAsync( - addPostImpressionTask.AsTask); - - //then - actualPostImpressionDependencyValidationException.Should().BeEquivalentTo( - expectedPostImpressionDependencyValidationException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once()); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionDependencyValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.InsertPostImpressionAsync(It.IsAny()), - Times.Never); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowServiceExceptionOnAddIfServiceErrorOccursAndLogItAsync() - { - //given - PostImpression somePostImpression = CreateRandomPostImpression(); - var serviceException = new Exception(); - - var failedPostImpressionServiceException = - new FailedPostImpressionServiceException(serviceException); - - var expectedPostImpressionServiceException = - new PostImpressionServiceException(failedPostImpressionServiceException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Throws(serviceException); - - //when - ValueTask addPostImpressionTask = - this.postImpressionService.AddPostImpressions(somePostImpression); - - PostImpressionServiceException actualPostImpressionServiceException = - await Assert.ThrowsAsync( - addPostImpressionTask.AsTask); - - //then - actualPostImpressionServiceException.Should().BeEquivalentTo( - expectedPostImpressionServiceException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.InsertPostImpressionAsync(It.IsAny()), - Times.Never); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionServiceException))), - Times.Once); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class PostImpressionServiceTests + { + [Fact] + private async Task ShouldThrowCriticalDependencyExceptionOnAddIfSqlErrorOccursAndLogItAsync() + { + // given + DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); + + PostImpression somePostImpression = + CreateRandomPostImpression(randomDateTime); + + SqlException sqlException = GetSqlException(); + + var failedPostImpressionStorageException = + new FailedPostImpressionStorageException( + message: "Failed post impression storage error has occurred, contact support.", + innerException: sqlException); + + var expectedPostImpressionDependencyException = + new PostImpressionDependencyException( + message: "Post impression dependency error has occurred, please contact support.", + innerException: failedPostImpressionStorageException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Throws(sqlException); + + // when + ValueTask addPostImpressionTask = + this.postImpressionService.AddPostImpressions(somePostImpression); + + PostImpressionDependencyException actualPostImpressionDependencyException = + await Assert.ThrowsAsync( + addPostImpressionTask.AsTask); + + // then + actualPostImpressionDependencyException.Should().BeEquivalentTo( + expectedPostImpressionDependencyException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.loggingBrokerMock.Verify(broker => + broker.LogCritical(It.Is(SameExceptionAs( + expectedPostImpressionDependencyException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.InsertPostImpressionAsync( + It.IsAny()), + Times.Never); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowDependencyValidationExceptionOnAddIfPostImpressionAlreadyExistsAndLogItAsync() + { + // given + PostImpression randomPostImpression = CreateRandomPostImpression(); + PostImpression alreadyExistsPostImpression = randomPostImpression; + string randomMessage = GetRandomMessage(); + + var duplicateKeyException = + new DuplicateKeyException(randomMessage); + + var alreadyExistsPostImpressionException = + new AlreadyExistsPostImpressionException( + message: "Post impression with the same id already exists.", + innerException: duplicateKeyException); + + var expectedPostImpressionDependencyValidationException = + new PostImpressionDependencyValidationException( + message: "Post impression dependency validation occurred, please try again.", + innerException: alreadyExistsPostImpressionException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Throws(duplicateKeyException); + + // when + ValueTask addPostImpressionTask = + this.postImpressionService.AddPostImpressions(alreadyExistsPostImpression); + + PostImpressionDependencyValidationException actualPostImpressionDependencyValidationException = + await Assert.ThrowsAsync( + addPostImpressionTask.AsTask); + + // then + actualPostImpressionDependencyValidationException.Should().BeEquivalentTo( + expectedPostImpressionDependencyValidationException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.InsertPostImpressionAsync( + It.IsAny()), + Times.Never); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedPostImpressionDependencyValidationException))), + Times.Once); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowDependencyExceptionOnAddIfDatabaseUpdateErrorOccursAndLogItAsync() + { + // given + PostImpression somePostImpression = CreateRandomPostImpression(); + + var databaseUpdateException = + new DbUpdateException(); + + var failedPostImpressionStorageException = + new FailedPostImpressionStorageException( + message: "Failed post impression storage error has occurred, contact support.", + innerException: databaseUpdateException); + + var expectedPostImpressionDependencyException = + new PostImpressionDependencyException( + message: "Post impression dependency error has occurred, please contact support.", + innerException: failedPostImpressionStorageException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Throws(databaseUpdateException); + + // when + ValueTask addPostImpressionTask = + this.postImpressionService.AddPostImpressions(somePostImpression); + + PostImpressionDependencyException actualPostImpressionDependencyException = + await Assert.ThrowsAsync( + addPostImpressionTask.AsTask); + + // then + actualPostImpressionDependencyException.Should().BeEquivalentTo( + expectedPostImpressionDependencyException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.InsertPostImpressionAsync( + It.IsAny()), + Times.Never); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedPostImpressionDependencyException))), + Times.Once); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async void ShouldThrowDependencyValidationExceptionOnAddIfReferenceErrorOccursAndLogItAsync() + { + // given + PostImpression somePostImpression = CreateRandomPostImpression(); + string randomMessage = GetRandomMessage(); + string exceptionMessage = randomMessage; + + var foreignKeyConstraintConflictException = + new ForeignKeyConstraintConflictException(exceptionMessage); + + var invalidPostImpressionReferenceException = + new InvalidPostImpressionReferenceException( + message: "Invalid post impression reference error occurred.", + innerException: foreignKeyConstraintConflictException); + + var expectedPostImpressionDependencyValidationException = + new PostImpressionDependencyValidationException( + message: "Post impression dependency validation occurred, please try again.", + innerException: invalidPostImpressionReferenceException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Throws(foreignKeyConstraintConflictException); + + // when + ValueTask addPostImpressionTask = + this.postImpressionService.AddPostImpressions(somePostImpression); + + PostImpressionDependencyValidationException actualPostImpressionDependencyValidationException = + await Assert.ThrowsAsync( + addPostImpressionTask.AsTask); + + // then + actualPostImpressionDependencyValidationException.Should().BeEquivalentTo( + expectedPostImpressionDependencyValidationException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once()); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedPostImpressionDependencyValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.InsertPostImpressionAsync( + It.IsAny()), + Times.Never); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowServiceExceptionOnAddIfServiceErrorOccursAndLogItAsync() + { + //given + PostImpression somePostImpression = CreateRandomPostImpression(); + var serviceException = new Exception(); + + var failedPostImpressionServiceException = + new FailedPostImpressionServiceException( + message: "Failed post impression service occurred, please contact support.", + innerException: serviceException); + + var expectedPostImpressionServiceException = + new PostImpressionServiceException( + message: "Post impression service error occurred, please contact support.", + innerException: failedPostImpressionServiceException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Throws(serviceException); + + // when + ValueTask addPostImpressionTask = + this.postImpressionService.AddPostImpressions(somePostImpression); + + PostImpressionServiceException actualPostImpressionServiceException = + await Assert.ThrowsAsync( + addPostImpressionTask.AsTask); + + // then + actualPostImpressionServiceException.Should().BeEquivalentTo( + expectedPostImpressionServiceException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.InsertPostImpressionAsync( + It.IsAny()), + Times.Never); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedPostImpressionServiceException))), + Times.Once); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + } + } +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.RemoveById.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.RemoveById.cs index ad2f661d..f6d840b7 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.RemoveById.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.RemoveById.cs @@ -18,24 +18,29 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.PostImpressions public partial class PostImpressionServiceTests { [Fact] - public async Task ShouldThrowServiceExceptionOnDeleteWhenExceptionOccursAndLogItAsync() + private async Task ShouldThrowServiceExceptionOnDeleteWhenExceptionOccursAndLogItAsync() { - //given + // given PostImpression somePostImpression = CreateRandomPostImpression(); var serviceException = new Exception(); var failedPostImpressionServiceException = - new FailedPostImpressionServiceException(serviceException); + new FailedPostImpressionServiceException( + message: "Failed post impression service occurred, please contact support.", + innerException: serviceException); var expectedPostImpressionServiceException = - new PostImpressionServiceException(failedPostImpressionServiceException); + new PostImpressionServiceException( + message: "Post impression service error occurred, please contact support.", + innerException: failedPostImpressionServiceException); this.storageBrokerMock.Setup(broker => broker.SelectPostImpressionByIdAsync( It.IsAny(), - It.IsAny())).ThrowsAsync(serviceException); + It.IsAny())) + .ThrowsAsync(serviceException); - //when + // when ValueTask deletePostImpressionTask = this.postImpressionService.RemovePostImpressionAsync(somePostImpression); @@ -43,18 +48,20 @@ public async Task ShouldThrowServiceExceptionOnDeleteWhenExceptionOccursAndLogIt await Assert.ThrowsAsync( deletePostImpressionTask.AsTask); - //then + // then actualPostImpressionServiceException.Should().BeEquivalentTo( expectedPostImpressionServiceException); this.storageBrokerMock.Verify(broker => broker.SelectPostImpressionByIdAsync( It.IsAny(), - It.IsAny()), Times.Once); + It.IsAny()), + Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionServiceException))), Times.Once); + expectedPostImpressionServiceException))), + Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); @@ -62,24 +69,28 @@ await Assert.ThrowsAsync( } [Fact] - public async Task ShouldThrowDependencyExceptionOnDeleteWhenSqlExceptionOccursAndLogItAsync() + private async Task ShouldThrowDependencyExceptionOnDeleteWhenSqlExceptionOccursAndLogItAsync() { - //given + // given PostImpression somePostImpression = CreateRandomPostImpression(); SqlException sqlException = GetSqlException(); var failedPostImpressionStorageException = - new FailedPostImpressionStorageException(sqlException); + new FailedPostImpressionStorageException( + message: "Failed post impression storage error has occurred, contact support.", + innerException: sqlException); var expectedPostImpressionDependencyException = - new PostImpressionDependencyException(failedPostImpressionStorageException); + new PostImpressionDependencyException( + message: "Post impression dependency error has occurred, please contact support.", + innerException: failedPostImpressionStorageException); this.storageBrokerMock.Setup(broker => broker.SelectPostImpressionByIdAsync( It.IsAny(), It.IsAny())).ThrowsAsync(sqlException); - //when + // when ValueTask deletePostImpressionTask = this.postImpressionService.RemovePostImpressionAsync(somePostImpression); @@ -87,18 +98,20 @@ public async Task ShouldThrowDependencyExceptionOnDeleteWhenSqlExceptionOccursAn await Assert.ThrowsAsync( deletePostImpressionTask.AsTask); - //then + // then actualPostImpressionDependencyException.Should().BeEquivalentTo( expectedPostImpressionDependencyException); this.storageBrokerMock.Verify(broker => broker.SelectPostImpressionByIdAsync( It.IsAny(), - It.IsAny()), Times.Once); + It.IsAny()), + Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogCritical(It.Is(SameExceptionAs( - expectedPostImpressionDependencyException))), Times.Once); + expectedPostImpressionDependencyException))), + Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); @@ -106,19 +119,23 @@ await Assert.ThrowsAsync( } [Fact] - public async Task ShouldThrowDependencyValidationOnRemoveIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync() + private async Task ShouldThrowDependencyValidationOnRemoveIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync() { - //given + // given PostImpression somePostImpression = CreateRandomPostImpression(); var databaseUpdateConcurrencyException = new DbUpdateConcurrencyException(); var lockedPostImpressionException = - new LockedPostImpressionException(databaseUpdateConcurrencyException); + new LockedPostImpressionException( + message: "Locked post impression record exception, please try again later", + innerException: databaseUpdateConcurrencyException); var expectedPostImpressionDependencyValidationException = - new PostImpressionDependencyValidationException(lockedPostImpressionException); + new PostImpressionDependencyValidationException( + message: "Post impression dependency validation occurred, please try again.", + innerException: lockedPostImpressionException); this.storageBrokerMock.Setup(broker => broker.SelectPostImpressionByIdAsync( @@ -126,7 +143,7 @@ public async Task ShouldThrowDependencyValidationOnRemoveIfDatabaseUpdateConcurr It.IsAny())) .ThrowsAsync(databaseUpdateConcurrencyException); - //when + // when ValueTask removePostImpressionByIdTask = this.postImpressionService.RemovePostImpressionAsync(somePostImpression); @@ -134,7 +151,7 @@ public async Task ShouldThrowDependencyValidationOnRemoveIfDatabaseUpdateConcurr await Assert.ThrowsAsync( removePostImpressionByIdTask.AsTask); - //then + // then actualPostImpressionDependencyValidationException.Should().BeEquivalentTo( expectedPostImpressionDependencyValidationException); @@ -145,14 +162,17 @@ await Assert.ThrowsAsync( this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionDependencyValidationException))), Times.Once); + expectedPostImpressionDependencyValidationException))), + Times.Once); this.storageBrokerMock.Verify(broker => - broker.DeletePostImpressionAsync(It.IsAny()), Times.Never); + broker.DeletePostImpressionAsync( + It.IsAny()), + Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); } } -} +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.RetrieveAll.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.RetrieveAll.cs index 98b54b69..2a825257 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.RetrieveAll.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.RetrieveAll.cs @@ -15,28 +15,32 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.PostImpressions public partial class PostImpressionServiceTests { [Fact] - public void ShouldThrowCriticalDependencyExceptionOnRetrieveAllWhenSqlExceptionOccursAndLogIt() + private void ShouldThrowCriticalDependencyExceptionOnRetrieveAllWhenSqlExceptionOccursAndLogIt() { - //given + // given SqlException sqlException = GetSqlException(); var failedPostImpressionStorageException = - new FailedPostImpressionStorageException(sqlException); + new FailedPostImpressionStorageException( + message: "Failed post impression storage error has occurred, contact support.", + innerException: sqlException); var expectedPostImpressionDependencyException = new - PostImpressionDependencyException(failedPostImpressionStorageException); + PostImpressionDependencyException( + message: "Post impression dependency error has occurred, please contact support.", + innerException: failedPostImpressionStorageException); this.storageBrokerMock.Setup(broker => broker.SelectAllPostImpressions()).Throws(sqlException); - //when + // when Action retrieveAllPostImpressions = () => this.postImpressionService.RetrieveAllPostImpressions(); PostImpressionDependencyException actualPostImpressionDependencyException = Assert.Throws(retrieveAllPostImpressions); - - //then + + // then actualPostImpressionDependencyException.Should().BeEquivalentTo( expectedPostImpressionDependencyException); @@ -53,42 +57,49 @@ public void ShouldThrowCriticalDependencyExceptionOnRetrieveAllWhenSqlExceptionO } [Fact] - public void ShouldThrowServiceExceptionOnRetrieveAllIfServiceErrorOccursAndLogItAsync() + private void ShouldThrowServiceExceptionOnRetrieveAllIfServiceErrorOccursAndLogItAsync() { - //given + // given string exceptionMessage = GetRandomMessage(); var serviceException = new Exception(exceptionMessage); var failedPostImpressionServiceException = - new FailedPostImpressionServiceException(serviceException); + new FailedPostImpressionServiceException( + message: "Failed post impression service occurred, please contact support.", + innerException: serviceException); var expectedPostImpressionServiceException = - new PostImpressionServiceException(failedPostImpressionServiceException); + new PostImpressionServiceException( + message: "Post impression service error occurred, please contact support.", + innerException: failedPostImpressionServiceException); this.storageBrokerMock.Setup(broker => broker.SelectAllPostImpressions()).Throws(serviceException); - //when + // when Action retrieveAllPostImpressionsAction = () => this.postImpressionService.RetrieveAllPostImpressions(); - PostImpressionServiceException actualPostImpressionServiceException = - Assert.Throws(retrieveAllPostImpressionsAction); + PostImpressionServiceException actualPostImpressionServiceException = + Assert.Throws( + retrieveAllPostImpressionsAction); - //then + // then actualPostImpressionServiceException.Should().BeEquivalentTo( expectedPostImpressionServiceException); this.storageBrokerMock.Verify(broker => - broker.SelectAllPostImpressions(), Times.Once); + broker.SelectAllPostImpressions(), + Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionServiceException))), Times.Once); + expectedPostImpressionServiceException))), + Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); } } -} +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.RetrieveById.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.RetrieveById.cs index 794ad758..733aded3 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.RetrieveById.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Exceptions.RetrieveById.cs @@ -17,24 +17,28 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.PostImpressions public partial class PostImpressionServiceTests { [Fact] - public async Task ShouldThrowCriticalDependencyExceptionOnRetrieveByIdIfSqlErrorOccursAndLogItAsync() + private async Task ShouldThrowCriticalDependencyExceptionOnRetrieveByIdIfSqlErrorOccursAndLogItAsync() { - //given + // given Guid somePostId = Guid.NewGuid(); Guid someProfileId = Guid.NewGuid(); SqlException sqlException = GetSqlException(); var failedPostImpressionStorageException = - new FailedPostImpressionStorageException(sqlException); + new FailedPostImpressionStorageException( + message: "Failed post impression storage error has occurred, contact support.", + innerException: sqlException); var expectedPostImpressionDependencyException = - new PostImpressionDependencyException(failedPostImpressionStorageException); + new PostImpressionDependencyException( + message: "Post impression dependency error has occurred, please contact support.", + innerException: failedPostImpressionStorageException); this.storageBrokerMock.Setup(broker => broker.SelectPostImpressionByIdAsync(somePostId, someProfileId)) .ThrowsAsync(sqlException); - //when + // when ValueTask retrievePostImpressionByIdTask = this.postImpressionService.RetrievePostImpressionByIdAsync(somePostId, someProfileId); @@ -42,13 +46,14 @@ public async Task ShouldThrowCriticalDependencyExceptionOnRetrieveByIdIfSqlError await Assert.ThrowsAsync( retrievePostImpressionByIdTask.AsTask); - //then + // then actualPostImpressionDependencyException.Should().BeEquivalentTo( expectedPostImpressionDependencyException); this.storageBrokerMock.Verify(broker => - broker.SelectPostImpressionByIdAsync(It.IsAny(), (It.IsAny())), - Times.Once); + broker.SelectPostImpressionByIdAsync( + It.IsAny(), (It.IsAny())), + Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogCritical(It.Is(SameExceptionAs( @@ -61,37 +66,43 @@ await Assert.ThrowsAsync( } [Fact] - public async Task ShouldThrowServiceExceptionOnRetrieveByIdIfServiceErrorOccursAndLogItAsync() + private async Task ShouldThrowServiceExceptionOnRetrieveByIdIfServiceErrorOccursAndLogItAsync() { - //given + // given Guid somePostId = Guid.NewGuid(); Guid someProfileId = Guid.NewGuid(); var serviceException = new Exception(); var failedPostImpressionServiceException = - new FailedPostImpressionServiceException(serviceException); + new FailedPostImpressionServiceException( + message: "Failed post impression service occurred, please contact support.", + innerException: serviceException); var expectedPostImpressionServiceException = - new PostImpressionServiceException(failedPostImpressionServiceException); + new PostImpressionServiceException( + message: "Post impression service error occurred, please contact support.", + innerException: failedPostImpressionServiceException); this.storageBrokerMock.Setup(broker => broker.SelectPostImpressionByIdAsync(somePostId, someProfileId)) .ThrowsAsync(serviceException); - //when + // when ValueTask retrievePostImpressionByIdTask = - this.postImpressionService.RetrievePostImpressionByIdAsync(somePostId, someProfileId); + this.postImpressionService.RetrievePostImpressionByIdAsync( + somePostId, someProfileId); PostImpressionServiceException actualPostImpressionServiceException = await Assert.ThrowsAsync( retrievePostImpressionByIdTask.AsTask); - //then + // then actualPostImpressionServiceException.Should().BeEquivalentTo( expectedPostImpressionServiceException); this.storageBrokerMock.Verify(broker => - broker.SelectPostImpressionByIdAsync(It.IsAny(), (It.IsAny())), + broker.SelectPostImpressionByIdAsync( + It.IsAny(), (It.IsAny())), Times.Once); this.loggingBrokerMock.Verify(broker => diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.Add.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.Add.cs index f92997d6..5f2ef544 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.Add.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.Add.cs @@ -16,14 +16,20 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.PostImpressions public partial class PostImpressionServiceTests { [Fact] - public async Task ShouldAddPostImpressionAsync() + private async Task ShouldAddPostImpressionAsync() { - //given - DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); - PostImpression randomPostImpression = CreateRandomPostImpression(randomDateTime); + // given + DateTimeOffset randomDateTime = + GetRandomDateTimeOffset(); + + PostImpression randomPostImpression = + CreateRandomPostImpression(randomDateTime); + PostImpression inputPostImpression = randomPostImpression; PostImpression storagePostImpression = inputPostImpression; - PostImpression expectedPostImpression = storagePostImpression.DeepClone(); + + PostImpression expectedPostImpression = + storagePostImpression.DeepClone(); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()) @@ -33,12 +39,14 @@ public async Task ShouldAddPostImpressionAsync() broker.InsertPostImpressionAsync(inputPostImpression)) .ReturnsAsync(storagePostImpression); - //when - PostImpression actualPostImpression = await this.postImpressionService + // when + PostImpression actualPostImpression = + await this.postImpressionService .AddPostImpressions(inputPostImpression); - //then - actualPostImpression.Should().BeEquivalentTo(expectedPostImpression); + // then + actualPostImpression.Should().BeEquivalentTo( + expectedPostImpression); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTimeOffset(), @@ -53,4 +61,4 @@ public async Task ShouldAddPostImpressionAsync() this.loggingBrokerMock.VerifyNoOtherCalls(); } } -} +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.Modify.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.Modify.cs index 99363d1a..e06321d6 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.Modify.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.Modify.cs @@ -16,21 +16,36 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.PostImpressions public partial class PostImpressionServiceTests { [Fact] - public async Task ShouldModifyPostImpressionAsync() + private async Task ShouldModifyPostImpressionAsync() { - //given - DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); - PostImpression randomPostImpression = CreateRandomModifyPostImpression(randomDateTime); - PostImpression inputPostImpression = randomPostImpression; - PostImpression storagePostImpression = inputPostImpression.DeepClone(); - storagePostImpression.UpdatedDate = randomPostImpression.CreatedDate; - PostImpression updatePostImpression = inputPostImpression; - PostImpression expectedPostImpression = updatePostImpression.DeepClone(); + // given + DateTimeOffset randomDateTime = + GetRandomDateTimeOffset(); + + PostImpression randomPostImpression = + CreateRandomModifyPostImpression(randomDateTime); + + PostImpression inputPostImpression = + randomPostImpression; + + PostImpression storagePostImpression = + inputPostImpression.DeepClone(); + + storagePostImpression.UpdatedDate = + randomPostImpression.CreatedDate; + + PostImpression updatePostImpression = + inputPostImpression; + + PostImpression expectedPostImpression = + updatePostImpression.DeepClone(); + Guid postId = inputPostImpression.PostId; Guid profileId = inputPostImpression.ProfileId; this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()).Returns(randomDateTime); + broker.GetCurrentDateTimeOffset()).Returns( + randomDateTime); this.storageBrokerMock.Setup(broker => broker.SelectPostImpressionByIdAsync(postId, profileId)) @@ -40,25 +55,30 @@ public async Task ShouldModifyPostImpressionAsync() broker.UpdatePostImpressionAsync(inputPostImpression)) .ReturnsAsync(updatePostImpression); - //when + // when PostImpression actualPostImpression = - await this.postImpressionService.ModifyPostImpressionAsync(inputPostImpression); + await this.postImpressionService.ModifyPostImpressionAsync( + inputPostImpression); - //then - actualPostImpression.Should().BeEquivalentTo(expectedPostImpression); + // then + actualPostImpression.Should().BeEquivalentTo( + expectedPostImpression); this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), Times.Once); + broker.GetCurrentDateTimeOffset(), + Times.Once); this.storageBrokerMock.Verify(broker => - broker.SelectPostImpressionByIdAsync(postId, profileId), Times.Once); + broker.SelectPostImpressionByIdAsync(postId, profileId), + Times.Once); this.storageBrokerMock.Verify(broker => - broker.UpdatePostImpressionAsync(inputPostImpression), Times.Once); + broker.UpdatePostImpressionAsync(inputPostImpression), + Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); } } -} +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.RemoveById.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.RemoveById.cs index 582b15aa..d9743a0e 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.RemoveById.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.RemoveById.cs @@ -15,16 +15,20 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.PostImpressions public partial class PostImpressionServiceTests { [Fact] - public async Task ShouldRemovePostImpressionByIdAsync() + private async Task ShouldRemovePostImpressionByIdAsync() { - //given + // given Guid randomPostId = Guid.NewGuid(); Guid randomProfileId = Guid.NewGuid(); Guid inputPostId = randomPostId; Guid inputProfileId = randomProfileId; - PostImpression randomPostImpression = CreateRandomPostImpression(); + + PostImpression randomPostImpression = + CreateRandomPostImpression(); + randomPostImpression.PostId = inputPostId; randomPostImpression.ProfileId = inputProfileId; + PostImpression storagePostImpression = randomPostImpression; PostImpression expectedPostImpression = storagePostImpression; @@ -36,18 +40,20 @@ public async Task ShouldRemovePostImpressionByIdAsync() broker.DeletePostImpressionAsync(storagePostImpression)) .ReturnsAsync(expectedPostImpression); - //when + // when PostImpression actualPostImpression = await this.postImpressionService .RemovePostImpressionAsync(randomPostImpression); - //then + // then actualPostImpression.Should().BeEquivalentTo(expectedPostImpression); this.storageBrokerMock.Verify(broker => - broker.SelectPostImpressionByIdAsync(inputPostId, inputProfileId), Times.Once()); + broker.SelectPostImpressionByIdAsync(inputPostId, inputProfileId), + Times.Once()); this.storageBrokerMock.Verify(broker => - broker.DeletePostImpressionAsync(storagePostImpression), Times.Once()); + broker.DeletePostImpressionAsync(storagePostImpression), + Times.Once()); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.RetrieveAll.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.RetrieveAll.cs index 95495aa1..488c7875 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.RetrieveAll.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.RetrieveAll.cs @@ -14,30 +14,37 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.PostImpressions public partial class PostImpressionServiceTests { [Fact] - public void ShouldReturnPostImpressions() + private void ShouldReturnPostImpressions() { - //given - IQueryable randomPostImpressions = CreateRandomPostImpressions(); - IQueryable storagePostImpressions = randomPostImpressions; - IQueryable expectedPostImpressions = storagePostImpressions; + // given + IQueryable randomPostImpressions = + CreateRandomPostImpressions(); + + IQueryable storagePostImpressions = + randomPostImpressions; + + IQueryable expectedPostImpressions = + storagePostImpressions; this.storageBrokerMock.Setup(broker => broker.SelectAllPostImpressions()) .Returns(storagePostImpressions); - //when + // when IQueryable actualPostImpressions = this.postImpressionService.RetrieveAllPostImpressions(); - //then - actualPostImpressions.Should().BeEquivalentTo(expectedPostImpressions); + // then + actualPostImpressions.Should().BeEquivalentTo( + expectedPostImpressions); this.storageBrokerMock.Verify(broker => - broker.SelectAllPostImpressions(), Times.Once); + broker.SelectAllPostImpressions(), + Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); } } -} +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.RetrieveById.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.RetrieveById.cs index e087ff4d..9a609f75 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.RetrieveById.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Logic.RetrieveById.cs @@ -16,16 +16,22 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.PostImpressions public partial class PostImpressionServiceTests { [Fact] - public async Task ShouldRetrieveGroupPostByIdAsync() + private async Task ShouldRetrieveGroupPostByIdAsync() { // given Guid randomPostId = Guid.NewGuid(); Guid randomProfileId = Guid.NewGuid(); Guid inputPostId = randomPostId; Guid inputProfileId = randomProfileId; - PostImpression randomPostImpression = CreateRandomPostImpression(); - PostImpression storagePostImpression = randomPostImpression; - PostImpression expectedPostImpression = storagePostImpression.DeepClone(); + + PostImpression randomPostImpression = + CreateRandomPostImpression(); + + PostImpression storagePostImpression = + randomPostImpression; + + PostImpression expectedPostImpression = + storagePostImpression.DeepClone(); this.storageBrokerMock.Setup(broker => broker.SelectPostImpressionByIdAsync(inputPostId, inputProfileId)) @@ -33,10 +39,12 @@ public async Task ShouldRetrieveGroupPostByIdAsync() // when PostImpression actualPostImpression = - await this.postImpressionService.RetrievePostImpressionByIdAsync(inputPostId, inputProfileId); + await this.postImpressionService.RetrievePostImpressionByIdAsync( + inputPostId, inputProfileId); // then - actualPostImpression.Should().BeEquivalentTo(expectedPostImpression); + actualPostImpression.Should().BeEquivalentTo( + expectedPostImpression); this.storageBrokerMock.Verify(broker => broker.SelectPostImpressionByIdAsync(inputPostId, inputProfileId), diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validation.Modify.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validation.Modify.cs index 01a33c31..81eadbe9 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validation.Modify.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validation.Modify.cs @@ -19,14 +19,18 @@ public partial class PostImpressionServiceTests [Fact] public async Task ShouldThrowValidationExceptionOnModifyIfPostImpressionIsNullAndLogItAsync() { - //given + // given PostImpression nullPostImpression = null; - var nullPostImpressionException = new NullPostImpressionException(); + + var nullPostImpressionException = + new NullPostImpressionException(); PostImpressionValidationException expectedPostValidationException = - new PostImpressionValidationException(nullPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: nullPostImpressionException); - //when + // when ValueTask modifyPostImpressionTask = this.postImpressionService.ModifyPostImpressionAsync(nullPostImpression); @@ -34,15 +38,17 @@ public async Task ShouldThrowValidationExceptionOnModifyIfPostImpressionIsNullAn await Assert.ThrowsAsync( modifyPostImpressionTask.AsTask); - //then + // then actualPostImpressionValidationException.Should().BeEquivalentTo( expectedPostValidationException); this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs(expectedPostValidationException))), Times.Once); + broker.LogError(It.Is(SameExceptionAs(expectedPostValidationException))), + Times.Once); this.storageBrokerMock.Verify(broker => - broker.UpdatePostImpressionAsync(nullPostImpression), Times.Never); + broker.UpdatePostImpressionAsync(nullPostImpression), + Times.Never); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); @@ -50,16 +56,17 @@ await Assert.ThrowsAsync( [Theory] [InlineData(null)] - public async Task ShouldThrowValidationExceptionOnModifyIfPostImpressionIsInvalidAndLogItAsync(Guid invalidId) + private async Task ShouldThrowValidationExceptionOnModifyIfPostImpressionIsInvalidAndLogItAsync(Guid invalidId) { - //given + // given var invalidPostImpression = new PostImpression { PostId = invalidId, ProfileId = invalidId }; - var invalidPostImpressionException = new InvalidPostImpressionException(); + var invalidPostImpressionException = + new InvalidPostImpressionException(); invalidPostImpressionException.AddData( key: nameof(PostImpression.PostId), @@ -82,9 +89,11 @@ public async Task ShouldThrowValidationExceptionOnModifyIfPostImpressionIsInvali }); var expectedPostImpressionValidationException = - new PostImpressionValidationException(invalidPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: invalidPostImpressionException); - //when + // when ValueTask modifyPostImpressionTask = this.postImpressionService.ModifyPostImpressionAsync(invalidPostImpression); @@ -92,7 +101,7 @@ public async Task ShouldThrowValidationExceptionOnModifyIfPostImpressionIsInvali await Assert.ThrowsAsync( modifyPostImpressionTask.AsTask); - //then + // then actualPostValidationException.Should().BeEquivalentTo( expectedPostImpressionValidationException); @@ -101,10 +110,12 @@ await Assert.ThrowsAsync( this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionValidationException))), Times.Once); + expectedPostImpressionValidationException))), + Times.Once); this.storageBrokerMock.Verify(broker => - broker.UpdatePostImpressionAsync(invalidPostImpression), Times.Never); + broker.UpdatePostImpressionAsync(invalidPostImpression), + Times.Never); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); @@ -112,45 +123,57 @@ await Assert.ThrowsAsync( } [Fact] - public async Task ShouldThrowValidationExceptionOnModifyIfUpdatedDateIsSameAsCreatedDateAndLogItAsync() + private async Task ShouldThrowValidationExceptionOnModifyIfUpdatedDateIsSameAsCreatedDateAndLogItAsync() { - //given + // given DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); - PostImpression randomPostImpression = CreateRandomPostImpression(randomDateTime); + + PostImpression randomPostImpression = + CreateRandomPostImpression(randomDateTime); + PostImpression invalidPostImpression = randomPostImpression; - var invalidPostImpressionException = new InvalidPostImpressionException(); + + var invalidPostImpressionException = + new InvalidPostImpressionException(); invalidPostImpressionException.AddData( key: nameof(PostImpression.UpdatedDate), values: $"Date is the same as {nameof(PostImpression.CreatedDate)}"); var expectedPostImpressionValidationException = - new PostImpressionValidationException(invalidPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: invalidPostImpressionException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()).Returns(randomDateTime); - //when + // when ValueTask modifyPostImpressionTask = - this.postImpressionService.ModifyPostImpressionAsync(invalidPostImpression); + this.postImpressionService.ModifyPostImpressionAsync( + invalidPostImpression); PostImpressionValidationException actualPostImpressionValidationException = - await Assert.ThrowsAsync(modifyPostImpressionTask.AsTask); + await Assert.ThrowsAsync( + modifyPostImpressionTask.AsTask); - //then + // then actualPostImpressionValidationException.Should().BeEquivalentTo( expectedPostImpressionValidationException); this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), Times.Once); + broker.GetCurrentDateTimeOffset(), + Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionValidationException))), Times.Once); + expectedPostImpressionValidationException))), + Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectPostImpressionByIdAsync( - invalidPostImpression.PostId, invalidPostImpression.ProfileId), Times.Never); + invalidPostImpression.PostId, invalidPostImpression.ProfileId), + Times.Never); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); @@ -159,26 +182,33 @@ public async Task ShouldThrowValidationExceptionOnModifyIfUpdatedDateIsSameAsCre [Theory] [MemberData(nameof(InvalidSeconds))] - public async Task ShouldThrowValidationExceptionOnModifyIfUpdatedDateIsNotRecentAndLogItAsync(int minuts) + private async Task ShouldThrowValidationExceptionOnModifyIfUpdatedDateIsNotRecentAndLogItAsync(int minutes) { - //given + // given DateTimeOffset dateTime = GetRandomDateTimeOffset(); - PostImpression randomPostImpression = CreateRandomPostImpression(dateTime); + + PostImpression randomPostImpression = + CreateRandomPostImpression(dateTime); + PostImpression inputPostImpression = randomPostImpression; - inputPostImpression.UpdatedDate = dateTime.AddMinutes(minuts); - var invalidPostImpressionException = new InvalidPostImpressionException(); + inputPostImpression.UpdatedDate = dateTime.AddMinutes(minutes); + + var invalidPostImpressionException = + new InvalidPostImpressionException(); invalidPostImpressionException.AddData( key: nameof(PostImpression.UpdatedDate), values: "Date is not recent"); var expectedPostImpressionValidationException = - new PostImpressionValidationException(invalidPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: invalidPostImpressionException); dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()).Returns(dateTime); - //when + // when ValueTask modifyPostImpressionTask = this.postImpressionService.ModifyPostImpressionAsync(inputPostImpression); @@ -186,19 +216,23 @@ public async Task ShouldThrowValidationExceptionOnModifyIfUpdatedDateIsNotRecent await Assert.ThrowsAsync( modifyPostImpressionTask.AsTask); - //then + // then actualPostImpressionValidationException.Should().BeEquivalentTo( expectedPostImpressionValidationException); this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), Times.Once); + broker.GetCurrentDateTimeOffset(), + Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionValidationException))), Times.Once); + expectedPostImpressionValidationException))), + Times.Once); this.storageBrokerMock.Verify(broker => - broker.SelectPostImpressionByIdAsync(It.IsAny(), It.IsAny()), Times.Never); + broker.SelectPostImpressionByIdAsync( + It.IsAny(), It.IsAny()), + Times.Never); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); @@ -206,14 +240,20 @@ await Assert.ThrowsAsync( } [Fact] - public async Task ShouldThrowValidationExceptionOnModifyIfPostImpressionDoesNotExistAndLogItAsync() + private async Task ShouldThrowValidationExceptionOnModifyIfPostImpressionDoesNotExistAndLogItAsync() { - //given + // given int randomNegativeMinutes = GetRandomNegativeNumber(); DateTimeOffset dateTime = GetRandomDateTimeOffset(); - PostImpression randomPostImpression = CreateRandomPostImpression(dateTime); + + PostImpression randomPostImpression = + CreateRandomPostImpression(dateTime); + PostImpression nonExistPostImpression = randomPostImpression; - nonExistPostImpression.CreatedDate = dateTime.AddMinutes(randomNegativeMinutes); + + nonExistPostImpression.CreatedDate = + dateTime.AddMinutes(randomNegativeMinutes); + PostImpression nullPostImpression = null; var notFoundPostImpressionException = @@ -222,7 +262,9 @@ public async Task ShouldThrowValidationExceptionOnModifyIfPostImpressionDoesNotE nonExistPostImpression.ProfileId); var expectedPostImpressionValidationException = - new PostImpressionValidationException(notFoundPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: notFoundPostImpressionException); this.storageBrokerMock.Setup(broker => broker.SelectPostImpressionByIdAsync(nonExistPostImpression.PostId, @@ -231,28 +273,33 @@ public async Task ShouldThrowValidationExceptionOnModifyIfPostImpressionDoesNotE this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()).Returns(dateTime); - //when + // when ValueTask modifyPostImpressionTask = - this.postImpressionService.ModifyPostImpressionAsync(nonExistPostImpression); + this.postImpressionService.ModifyPostImpressionAsync( + nonExistPostImpression); PostImpressionValidationException actualPostImpressionValidationException = - await Assert.ThrowsAsync(modifyPostImpressionTask.AsTask); + await Assert.ThrowsAsync( + modifyPostImpressionTask.AsTask); - //then + // then actualPostImpressionValidationException.Should().BeEquivalentTo( expectedPostImpressionValidationException); this.storageBrokerMock.Verify(broker => broker.SelectPostImpressionByIdAsync( nonExistPostImpression.PostId, - nonExistPostImpression.ProfileId), Times.Once); + nonExistPostImpression.ProfileId), + Times.Once); this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), Times.Once); + broker.GetCurrentDateTimeOffset(), + Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionValidationException))), Times.Once); + expectedPostImpressionValidationException))), + Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); @@ -260,17 +307,32 @@ public async Task ShouldThrowValidationExceptionOnModifyIfPostImpressionDoesNotE } [Fact] - public async Task ShouldThrowValidationExceptionOnModifyIfStorageCreatedDateNotSameAsCreatedDateAndLogItAsync() + private async Task ShouldThrowValidationExceptionOnModifyIfStorageCreateDateNotSameAsCreateDateAndLogItAsync() { - //given + // given int randomNumber = GetRandomNumber(); int randomMinutes = randomNumber; - DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); - PostImpression randomPostImpression = CreateRandomModifyPostImpression(randomDateTime); - PostImpression invalidPostImpression = randomPostImpression.DeepClone(); - PostImpression storagePostImpression = randomPostImpression.DeepClone(); - storagePostImpression.CreatedDate = storagePostImpression.CreatedDate.AddMinutes(randomMinutes); - storagePostImpression.UpdatedDate = storagePostImpression.UpdatedDate.AddMinutes(randomMinutes); + + DateTimeOffset randomDateTime = + GetRandomDateTimeOffset(); + + PostImpression randomPostImpression = + CreateRandomModifyPostImpression(randomDateTime); + + PostImpression invalidPostImpression = + randomPostImpression.DeepClone(); + + PostImpression storagePostImpression = + randomPostImpression.DeepClone(); + + storagePostImpression.CreatedDate = + storagePostImpression.CreatedDate.AddMinutes( + randomMinutes); + + storagePostImpression.UpdatedDate = + storagePostImpression.UpdatedDate.AddMinutes( + randomMinutes); + Guid postId = invalidPostImpression.PostId; Guid profileId = invalidPostImpression.ProfileId; @@ -279,10 +341,13 @@ public async Task ShouldThrowValidationExceptionOnModifyIfStorageCreatedDateNotS invalidPostImpressionException.AddData( key: nameof(PostImpression.CreatedDate), - values: $"Date is not the same as {nameof(PostImpression.CreatedDate)}"); + values: $"Date is not the same as {nameof( + PostImpression.CreatedDate)}"); var expectedPostImpressionValidationException = - new PostImpressionValidationException(invalidPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: invalidPostImpressionException); this.storageBrokerMock.Setup(broker => broker.SelectPostImpressionByIdAsync(postId, profileId)) @@ -291,27 +356,32 @@ public async Task ShouldThrowValidationExceptionOnModifyIfStorageCreatedDateNotS this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()).Returns(randomDateTime); - //when + // when ValueTask modifyPostImpressionTask = - this.postImpressionService.ModifyPostImpressionAsync(invalidPostImpression); + this.postImpressionService.ModifyPostImpressionAsync( + invalidPostImpression); PostImpressionValidationException actualPostImpressionValidationException = - await Assert.ThrowsAsync(modifyPostImpressionTask.AsTask); + await Assert.ThrowsAsync( + modifyPostImpressionTask.AsTask); - //then + // then actualPostImpressionValidationException.Should().BeEquivalentTo( expectedPostImpressionValidationException); this.storageBrokerMock.Verify(broker => broker.SelectPostImpressionByIdAsync(invalidPostImpression.PostId, - invalidPostImpression.ProfileId), Times.Once); + invalidPostImpression.ProfileId), + Times.Once); this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), Times.Once); + broker.GetCurrentDateTimeOffset(), + Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionValidationException))), Times.Once); + expectedPostImpressionValidationException))), + Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); @@ -319,14 +389,20 @@ public async Task ShouldThrowValidationExceptionOnModifyIfStorageCreatedDateNotS } [Fact] - public async Task ShouldThrowValidationExceptionOnModifyIfStorageUpdatedDateSameAsUpdatedDateAndLogItAsync() + private async Task ShouldThrowValidationExceptionOnModifyIfStorageUpdatedDateSameAsUpdatedDateAndLogItAsync() { - //given + // given DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); - PostImpression randomPostImpression = CreateRandomModifyPostImpression(randomDateTime); + + PostImpression randomPostImpression = + CreateRandomModifyPostImpression(randomDateTime); + PostImpression invalidPostImpression = randomPostImpression; + PostImpression storagePostImpression = invalidPostImpression.DeepClone(); + invalidPostImpression.UpdatedDate = storagePostImpression.UpdatedDate; + var invalidPostImpressionException = new InvalidPostImpressionException(); invalidPostImpressionException.AddData( @@ -334,40 +410,47 @@ public async Task ShouldThrowValidationExceptionOnModifyIfStorageUpdatedDateSame values: $"Date is the same as {nameof(PostImpression.UpdatedDate)}"); var expectedPostImpressionValidationException = - new PostImpressionValidationException(invalidPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: invalidPostImpressionException); this.storageBrokerMock.Setup(broker => broker.SelectPostImpressionByIdAsync( - invalidPostImpression.PostId, invalidPostImpression.ProfileId)).ReturnsAsync(storagePostImpression); + invalidPostImpression.PostId, invalidPostImpression.ProfileId)). + ReturnsAsync(storagePostImpression); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()).Returns(randomDateTime); - //when + // when ValueTask modifyPostImpressionTask = this.postImpressionService.ModifyPostImpressionAsync(invalidPostImpression); PostImpressionValidationException actualPostImpressionValidationException = - await Assert.ThrowsAsync(modifyPostImpressionTask.AsTask); + await Assert.ThrowsAsync( + modifyPostImpressionTask.AsTask); - //then + // then actualPostImpressionValidationException.Should().BeEquivalentTo( expectedPostImpressionValidationException); this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), Times.Once); + broker.GetCurrentDateTimeOffset(), + Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionValidationException))), Times.Once); + expectedPostImpressionValidationException))), + Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectPostImpressionByIdAsync( - invalidPostImpression.PostId, invalidPostImpression.ProfileId), Times.Once); + invalidPostImpression.PostId, invalidPostImpression.ProfileId), + Times.Once); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); } } -} +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validations.Add.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validations.Add.cs index decf9017..168c9cdc 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validations.Add.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validations.Add.cs @@ -16,9 +16,9 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.PostImpressions public partial class PostImpressionServiceTests { [Fact] - public async Task ShouldThrowValidationExceptionOnAddIfPostImpressionIsNullAndLogItAsync() + private async Task ShouldThrowValidationExceptionOnAddIfPostImpressionIsNullAndLogItAsync() { - //given + // given PostImpression nullPostImpression = null; var nullPostImpressionException = @@ -27,7 +27,7 @@ public async Task ShouldThrowValidationExceptionOnAddIfPostImpressionIsNullAndLo var expectedPostImpressionValidationException = new PostImpressionValidationException(nullPostImpressionException); - //when + // when ValueTask addPostImpressionTask = this.postImpressionService.AddPostImpressions(nullPostImpression); @@ -35,7 +35,7 @@ public async Task ShouldThrowValidationExceptionOnAddIfPostImpressionIsNullAndLo await Assert.ThrowsAsync( addPostImpressionTask.AsTask); - //then + // then actualPostImpressionValidationException.Should().BeEquivalentTo( expectedPostImpressionValidationException); @@ -50,9 +50,9 @@ await Assert.ThrowsAsync( } [Fact] - public async Task ShouldThrowValidationExceptionOnAddIfPostImpressionIsInvalidAndLogItAsync() + private async Task ShouldThrowValidationExceptionOnAddIfPostImpressionIsInvalidAndLogItAsync() { - //given + // given Guid invalidGuid = Guid.Empty; var invalidPostImpression = new PostImpression @@ -89,9 +89,11 @@ public async Task ShouldThrowValidationExceptionOnAddIfPostImpressionIsInvalidAn values: "Date is required"); var expectedPostImpressionValidationException = - new PostImpressionValidationException(invalidPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: invalidPostImpressionException); - //when + // when ValueTask addPostImpressionTask = this.postImpressionService.AddPostImpressions(invalidPostImpression); @@ -99,7 +101,7 @@ public async Task ShouldThrowValidationExceptionOnAddIfPostImpressionIsInvalidAn await Assert.ThrowsAsync( addPostImpressionTask.AsTask); - //then + // then actualPostImpressionValidationException.Should().BeEquivalentTo( expectedPostImpressionValidationException); @@ -122,12 +124,15 @@ await Assert.ThrowsAsync( } [Fact] - public async Task ShouldThrowValidationExceptionOnAddIfCreateAndUpdateDatesIsNotSameAndLogItAsync() + private async Task ShouldThrowValidationExceptionOnAddIfCreateAndUpdateDatesIsNotSameAndLogItAsync() { - //given + // given int randomNumber = GetRandomNumber(); DateTimeOffset randomDateTimeOffset = GetRandomDateTimeOffset(); - PostImpression randomPostImpression = CreateRandomPostImpression(randomDateTimeOffset); + + PostImpression randomPostImpression = + CreateRandomPostImpression(randomDateTimeOffset); + PostImpression invalidPostImpression = randomPostImpression; invalidPostImpression.UpdatedDate = @@ -141,13 +146,15 @@ public async Task ShouldThrowValidationExceptionOnAddIfCreateAndUpdateDatesIsNot values: $"Date is not the same as {nameof(PostImpression.CreatedDate)}"); var expectedPostImpressionValidationException = - new PostImpressionValidationException(invalidPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: invalidPostImpressionException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()) .Returns(randomDateTimeOffset); - //when + // when ValueTask addPostImpressionTask = this.postImpressionService.AddPostImpressions(invalidPostImpression); @@ -155,7 +162,7 @@ public async Task ShouldThrowValidationExceptionOnAddIfCreateAndUpdateDatesIsNot await Assert.ThrowsAsync( addPostImpressionTask.AsTask); - //then + // then actualPostImpressionValidationException.Should().BeEquivalentTo( expectedPostImpressionValidationException); @@ -179,7 +186,7 @@ await Assert.ThrowsAsync( [Theory] [MemberData(nameof(MinutesBeforeOrAfter))] - public async Task ShouldThrowValidationExceptionOnAddIfCreatedDateIsNotRecentAndLogItAsync( + private async Task ShouldThrowValidationExceptionOnAddIfCreatedDateIsNotRecentAndLogItAsync( int minutesBeforeOrAfter) { // given @@ -200,7 +207,9 @@ public async Task ShouldThrowValidationExceptionOnAddIfCreatedDateIsNotRecentAnd values: "Date is not recent"); var expectedPostImpressionValidationException = - new PostImpressionValidationException(invalidPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: invalidPostImpressionException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()) @@ -237,11 +246,14 @@ await Assert.ThrowsAsync( } [Fact] - public async Task ShouldThrowValidationExceptionOnAddIfEnumsAreInvalidAndLogItAsync() + private async Task ShouldThrowValidationExceptionOnAddIfEnumsAreInvalidAndLogItAsync() { - //given + // given DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); - PostImpression randomPostImpression = CreateRandomPostImpression(randomDateTime); + + PostImpression randomPostImpression = + CreateRandomPostImpression(randomDateTime); + PostImpression invalidPostImpression = randomPostImpression; invalidPostImpression.Impression = GetInvalidEnum(); var invalidPostImpressionException = new InvalidPostImpressionException(); @@ -254,33 +266,38 @@ public async Task ShouldThrowValidationExceptionOnAddIfEnumsAreInvalidAndLogItAs broker.GetCurrentDateTimeOffset()).Returns(randomDateTime); var expectedPostImpressionValidationException = - new PostImpressionValidationException(invalidPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: invalidPostImpressionException); - //when + // when ValueTask addPostImpressionTask = this.postImpressionService.AddPostImpressions(invalidPostImpression); PostImpressionValidationException actualPostImpressionValidationException = - await Assert.ThrowsAsync(addPostImpressionTask.AsTask); + await Assert.ThrowsAsync( + addPostImpressionTask.AsTask); - //then + // then actualPostImpressionValidationException.Should().BeEquivalentTo( expectedPostImpressionValidationException); this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), Times.Once()); + broker.GetCurrentDateTimeOffset(), + Times.Once()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionValidationException))), Times.Once); + expectedPostImpressionValidationException))), + Times.Once); this.storageBrokerMock.Verify(broker => - broker.InsertPostImpressionAsync(It.IsAny()), Times.Never); + broker.InsertPostImpressionAsync(It.IsAny()), + Times.Never); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); } - } -} +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validations.RemoveById.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validations.RemoveById.cs index 0a290c2d..e92aef4c 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validations.RemoveById.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validations.RemoveById.cs @@ -16,11 +16,13 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.PostImpressions public partial class PostImpressionServiceTests { [Fact] - public async Task ShouldThrowValidatonExceptionOnRemoveIfIdIsInvalidAndLogItAsync() + private async Task ShouldThrowValidatonExceptionOnRemoveIfIdIsInvalidAndLogItAsync() { - //given + // given var postImpression = new PostImpression(); - var invalidPostImpressionException = new InvalidPostImpressionException(); + + var invalidPostImpressionException = + new InvalidPostImpressionException(); invalidPostImpressionException.AddData( key: nameof(PostImpression.PostId), @@ -31,9 +33,11 @@ public async Task ShouldThrowValidatonExceptionOnRemoveIfIdIsInvalidAndLogItAsyn values: "Id is required"); var expectedPostImpressionValidationException = - new PostImpressionValidationException(invalidPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: invalidPostImpressionException); - //when + // when ValueTask removePostImpressionTask = this.postImpressionService.RemovePostImpressionAsync(postImpression); @@ -41,7 +45,7 @@ public async Task ShouldThrowValidatonExceptionOnRemoveIfIdIsInvalidAndLogItAsyn await Assert.ThrowsAsync( removePostImpressionTask.AsTask); - //then + // then actualPostImpressionValidationException.Should().BeEquivalentTo( expectedPostImpressionValidationException); @@ -50,12 +54,14 @@ await Assert.ThrowsAsync( expectedPostImpressionValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => - broker.SelectPostImpressionByIdAsync(postImpression.PostId, postImpression.ProfileId), - Times.Never); + broker.SelectPostImpressionByIdAsync( + postImpression.PostId, postImpression.ProfileId), + Times.Never); this.storageBrokerMock.Verify(broker => broker.DeletePostImpressionAsync( - It.IsAny()), Times.Never); + It.IsAny()), + Times.Never); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); @@ -63,11 +69,14 @@ await Assert.ThrowsAsync( } [Fact] - public async Task ShouldThrowNotFoundExceptionOnRemoveIdsPostImpressionIsNotFoundAndLogItAsync() + private async Task ShouldThrowNotFoundExceptionOnRemoveIdsPostImpressionIsNotFoundAndLogItAsync() { - //given + // given DateTimeOffset randomDateTime = GetRandomDateTime(); - PostImpression randomPostImpression = CreateRandomPostImpression(randomDateTime); + + PostImpression randomPostImpression = + CreateRandomPostImpression(randomDateTime); + Guid inputPostId = randomPostImpression.PostId; Guid inputProfile = randomPostImpression.ProfileId; PostImpression nullStoragePostImpression = null; @@ -76,38 +85,45 @@ public async Task ShouldThrowNotFoundExceptionOnRemoveIdsPostImpressionIsNotFoun new NotFoundPostImpressionException(inputPostId, inputProfile); var expectedPostImpressionValidationException = - new PostImpressionValidationException(notFoundPostImpressionException); + new PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: notFoundPostImpressionException); this.storageBrokerMock.Setup(broker => broker.SelectPostImpressionByIdAsync(inputPostId, inputProfile)) .ReturnsAsync(nullStoragePostImpression); - //when + // when ValueTask removePostImpressionTask = - this.postImpressionService.RemovePostImpressionAsync(randomPostImpression); + this.postImpressionService.RemovePostImpressionAsync( + randomPostImpression); PostImpressionValidationException actualPostImpressionValidationException = await Assert.ThrowsAsync( removePostImpressionTask.AsTask); - //then + // then actualPostImpressionValidationException.Should().BeEquivalentTo( expectedPostImpressionValidationException); this.storageBrokerMock.Verify(broker => - broker.SelectPostImpressionByIdAsync(It.IsAny(), It.IsAny()), + broker.SelectPostImpressionByIdAsync( + It.IsAny(), It.IsAny()), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( - expectedPostImpressionValidationException))), Times.Once); + expectedPostImpressionValidationException))), + Times.Once); this.storageBrokerMock.Verify(broker => - broker.DeletePostImpressionAsync(It.IsAny()), Times.Never); + broker.DeletePostImpressionAsync( + It.IsAny()), + Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); } } -} +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validations.RetrieveById.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validations.RetrieveById.cs index a0743cc6..4c23da9e 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validations.RetrieveById.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.Validations.RetrieveById.cs @@ -22,7 +22,8 @@ public async Task ShouldThrowValidationExceptionOnRetrieveByIdIfIdIsInvalidAndLo Guid invalidPostId = Guid.Empty; Guid invalidProfileId = Guid.Empty; - var invalidPostImpressionException = new InvalidPostImpressionException(); + var invalidPostImpressionException = + new InvalidPostImpressionException(); invalidPostImpressionException.AddData( key: nameof(PostImpression.PostId), @@ -33,11 +34,14 @@ public async Task ShouldThrowValidationExceptionOnRetrieveByIdIfIdIsInvalidAndLo values: "Id is required"); var expectedPostImpressionValidationException = new - PostImpressionValidationException(invalidPostImpressionException); + PostImpressionValidationException( + message: "Post impression validation errors occurred, please try again.", + innerException: invalidPostImpressionException); // when ValueTask retrievePostImpressionByIdTask = - this.postImpressionService.RetrievePostImpressionByIdAsync(invalidPostId, invalidProfileId); + this.postImpressionService.RetrievePostImpressionByIdAsync( + invalidPostId, invalidProfileId); PostImpressionValidationException actualPostImpressionValidationException = await Assert.ThrowsAsync( @@ -53,7 +57,8 @@ await Assert.ThrowsAsync( Times.Once); this.storageBrokerMock.Verify(broker => - broker.SelectPostImpressionByIdAsync(invalidPostId, invalidProfileId), + broker.SelectPostImpressionByIdAsync( + invalidPostId, invalidProfileId), Times.Never); this.loggingBrokerMock.VerifyNoOtherCalls(); diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.cs index b02161c4..b32f7073 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/PostImpressions/PostImpressionServiceTests.cs @@ -42,7 +42,9 @@ public PostImpressionServiceTests() public static TheoryData MinutesBeforeOrAfter() { int randomNumber = GetRandomNumber(); - int randomNegativeNumber = GetRandomNegativeNumber(); + + int randomNegativeNumber = + GetRandomNegativeNumber(); return new TheoryData { @@ -95,9 +97,12 @@ private static PostImpression CreateRandomPostImpression(DateTimeOffset dates) = private static PostImpression CreateRandomModifyPostImpression(DateTimeOffset dates) { int randomDaysInPast = GetRandomNegativeNumber(); - PostImpression randomPostImpression = CreateRandomPostImpression(dates); - randomPostImpression.CreatedDate = randomPostImpression.CreatedDate + PostImpression randomPostImpression = + CreateRandomPostImpression(dates); + + randomPostImpression.CreatedDate = + randomPostImpression.CreatedDate .AddDays(randomDaysInPast); return randomPostImpression; diff --git a/Taarafo.Core/Models/PostImpressions/Exceptions/AlreadyExistsPostImpressionException.cs b/Taarafo.Core/Models/PostImpressions/Exceptions/AlreadyExistsPostImpressionException.cs index b7b97408..46b93a86 100644 --- a/Taarafo.Core/Models/PostImpressions/Exceptions/AlreadyExistsPostImpressionException.cs +++ b/Taarafo.Core/Models/PostImpressions/Exceptions/AlreadyExistsPostImpressionException.cs @@ -8,10 +8,16 @@ namespace Taarafo.Core.Models.PostImpressions.Exceptions { - public class AlreadyExistsPostImpressionException : Xeption - { - public AlreadyExistsPostImpressionException(Exception innerException) - : base(message: "Post impression with the same id already exists.", innerException) - { } - } -} + public class AlreadyExistsPostImpressionException : Xeption + { + public AlreadyExistsPostImpressionException(Exception innerException) + : base( + message: "Post impression with the same id already exists.", + innerException: innerException) + { } + + public AlreadyExistsPostImpressionException(string message, Exception innerException) + : base(message, innerException) + { } + } +} \ No newline at end of file diff --git a/Taarafo.Core/Models/PostImpressions/Exceptions/FailedPostImpressionServiceException.cs b/Taarafo.Core/Models/PostImpressions/Exceptions/FailedPostImpressionServiceException.cs index d4401f44..7149a253 100644 --- a/Taarafo.Core/Models/PostImpressions/Exceptions/FailedPostImpressionServiceException.cs +++ b/Taarafo.Core/Models/PostImpressions/Exceptions/FailedPostImpressionServiceException.cs @@ -8,10 +8,16 @@ namespace Taarafo.Core.Models.PostImpressions.Exceptions { - public class FailedPostImpressionServiceException : Xeption - { - public FailedPostImpressionServiceException(Exception innerException) - : base(message: "Failed post impression service occurred, please contact support.", innerException) - { } - } -} + public class FailedPostImpressionServiceException : Xeption + { + public FailedPostImpressionServiceException(Exception innerException) + : base( + message: "Failed post impression service occurred, please contact support.", + innerException: innerException) + { } + + public FailedPostImpressionServiceException(string message, Exception innerException) + : base(message, innerException) + { } + } +} \ No newline at end of file diff --git a/Taarafo.Core/Models/PostImpressions/Exceptions/FailedPostImpressionStorageException.cs b/Taarafo.Core/Models/PostImpressions/Exceptions/FailedPostImpressionStorageException.cs index 5ec6a23e..5a53f926 100644 --- a/Taarafo.Core/Models/PostImpressions/Exceptions/FailedPostImpressionStorageException.cs +++ b/Taarafo.Core/Models/PostImpressions/Exceptions/FailedPostImpressionStorageException.cs @@ -8,10 +8,16 @@ namespace Taarafo.Core.Models.PostImpressions.Exceptions { - public class FailedPostImpressionStorageException : Xeption - { - public FailedPostImpressionStorageException(Exception innerException) - : base(message: "Failed post impression storage error has occurred, contact support.", innerException) - { } - } -} + public class FailedPostImpressionStorageException : Xeption + { + public FailedPostImpressionStorageException(Exception innerException) + : base( + message: "Failed post impression storage error has occurred, contact support.", + innerException: innerException) + { } + + public FailedPostImpressionStorageException(string message, Exception innerException) + : base(message, innerException) + { } + } +} \ No newline at end of file diff --git a/Taarafo.Core/Models/PostImpressions/Exceptions/InvalidPostImpressionException.cs b/Taarafo.Core/Models/PostImpressions/Exceptions/InvalidPostImpressionException.cs index c3adec58..1859e868 100644 --- a/Taarafo.Core/Models/PostImpressions/Exceptions/InvalidPostImpressionException.cs +++ b/Taarafo.Core/Models/PostImpressions/Exceptions/InvalidPostImpressionException.cs @@ -10,7 +10,12 @@ namespace Taarafo.Core.Models.PostImpressions.Exceptions public class InvalidPostImpressionException : Xeption { public InvalidPostImpressionException() - : base(message: "Invalid post impression. Please correct the errors and try again.") + : base( + message: "Invalid post impression. Please correct the errors and try again.") + { } + + public InvalidPostImpressionException(string message) + : base(message) { } } } \ No newline at end of file diff --git a/Taarafo.Core/Models/PostImpressions/Exceptions/InvalidPostImpressionReferenceException.cs b/Taarafo.Core/Models/PostImpressions/Exceptions/InvalidPostImpressionReferenceException.cs index 488f3103..cb19d154 100644 --- a/Taarafo.Core/Models/PostImpressions/Exceptions/InvalidPostImpressionReferenceException.cs +++ b/Taarafo.Core/Models/PostImpressions/Exceptions/InvalidPostImpressionReferenceException.cs @@ -8,11 +8,16 @@ namespace Taarafo.Core.Models.PostImpressions.Exceptions { - public class InvalidPostImpressionReferenceException : Xeption - { - public InvalidPostImpressionReferenceException(Exception innerException) - : base(message: "Invalid post impression reference error occurred.", innerException) - { } - } -} + public class InvalidPostImpressionReferenceException : Xeption + { + public InvalidPostImpressionReferenceException(Exception innerException) + : base( + message: "Invalid post impression reference error occurred.", + innerException: innerException) + { } + public InvalidPostImpressionReferenceException(string message, Exception innerException) + : base(message, innerException) + { } + } +} \ No newline at end of file diff --git a/Taarafo.Core/Models/PostImpressions/Exceptions/LockedPostImpressionException.cs b/Taarafo.Core/Models/PostImpressions/Exceptions/LockedPostImpressionException.cs index 5ecc9690..7429fcfe 100644 --- a/Taarafo.Core/Models/PostImpressions/Exceptions/LockedPostImpressionException.cs +++ b/Taarafo.Core/Models/PostImpressions/Exceptions/LockedPostImpressionException.cs @@ -11,7 +11,13 @@ namespace Taarafo.Core.Models.PostImpressions.Exceptions public class LockedPostImpressionException : Xeption { public LockedPostImpressionException(Exception innerException) - : base(message: "Locked post impression record exception, please try again later", innerException) + : base( + message: "Locked post impression record exception, please try again later", + innerException: innerException) + { } + + public LockedPostImpressionException(string message, Exception innerException) + : base(message, innerException) { } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Models/PostImpressions/Exceptions/NullPostImpressionException.cs b/Taarafo.Core/Models/PostImpressions/Exceptions/NullPostImpressionException.cs index dcaa37c1..1b6dc0f3 100644 --- a/Taarafo.Core/Models/PostImpressions/Exceptions/NullPostImpressionException.cs +++ b/Taarafo.Core/Models/PostImpressions/Exceptions/NullPostImpressionException.cs @@ -7,10 +7,14 @@ namespace Taarafo.Core.Models.PostImpressions.Exceptions { - public class NullPostImpressionException : Xeption - { - public NullPostImpressionException() - : base(message: "Post impression is null.") - { } - } -} + public class NullPostImpressionException : Xeption + { + public NullPostImpressionException() + : base(message: "Post impression is null.") + { } + + public NullPostImpressionException(string message) + : base(message) + { } + } +} \ No newline at end of file diff --git a/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionDependencyException.cs b/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionDependencyException.cs index d47415dd..d9cca986 100644 --- a/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionDependencyException.cs +++ b/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionDependencyException.cs @@ -7,10 +7,16 @@ namespace Taarafo.Core.Models.PostImpressions.Exceptions { - public class PostImpressionDependencyException : Xeption - { - public PostImpressionDependencyException(Xeption innerException) - : base(message: "Post impression dependency error has occurred, please contact support.", innerException) - { } - } -} + public class PostImpressionDependencyException : Xeption + { + public PostImpressionDependencyException(Xeption innerException) + : base( + message: "Post impression dependency error has occurred, please contact support.", + innerException: innerException) + { } + + public PostImpressionDependencyException(string message, Xeption innerException) + : base(message, innerException) + { } + } +} \ No newline at end of file diff --git a/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionDependencyValidationException.cs b/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionDependencyValidationException.cs index 2f1b2fe1..5deb4852 100644 --- a/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionDependencyValidationException.cs +++ b/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionDependencyValidationException.cs @@ -7,10 +7,16 @@ namespace Taarafo.Core.Models.PostImpressions.Exceptions { - public class PostImpressionDependencyValidationException : Xeption - { - public PostImpressionDependencyValidationException(Xeption innerException) - : base(message: "Post impression dependency validation occurred, please try again.", innerException) - { } - } -} + public class PostImpressionDependencyValidationException : Xeption + { + public PostImpressionDependencyValidationException(Xeption innerException) + : base( + message: "Post impression dependency validation occurred, please try again.", + innerException: innerException) + { } + + public PostImpressionDependencyValidationException(string message, Xeption innerException) + : base(message, innerException) + { } + } +} \ No newline at end of file diff --git a/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionServiceException.cs b/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionServiceException.cs index a7c2dcbb..bbe9f972 100644 --- a/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionServiceException.cs +++ b/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionServiceException.cs @@ -8,10 +8,16 @@ namespace Taarafo.Core.Models.PostImpressions.Exceptions { - public class PostImpressionServiceException : Xeption - { - public PostImpressionServiceException(Exception innerException) - : base(message: "Post impression service error occurred, please contact support.", innerException) - { } - } -} + public class PostImpressionServiceException : Xeption + { + public PostImpressionServiceException(Exception innerException) + : base( + message: "Post impression service error occurred, please contact support.", + innerException: innerException) + { } + + public PostImpressionServiceException(string message, Exception innerException) + : base(message, innerException) + { } + } +} \ No newline at end of file diff --git a/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionValidationException.cs b/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionValidationException.cs index 9db3ad1b..163efc58 100644 --- a/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionValidationException.cs +++ b/Taarafo.Core/Models/PostImpressions/Exceptions/PostImpressionValidationException.cs @@ -10,8 +10,13 @@ namespace Taarafo.Core.Models.PostImpressions.Exceptions public class PostImpressionValidationException : Xeption { public PostImpressionValidationException(Xeption innerException) - : base(message: "Post impression validation errors occurred, please try again.", - innerException) + : base( + message: "Post impression validation errors occurred, please try again.", + innerException: innerException) + { } + + public PostImpressionValidationException(string message, Xeption innerException) + : base(message, innerException) { } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Services/Foundations/PostImpressions/PostImpressionService.Exceptions.cs b/Taarafo.Core/Services/Foundations/PostImpressions/PostImpressionService.Exceptions.cs index 92e2dc5b..5b8e6971 100644 --- a/Taarafo.Core/Services/Foundations/PostImpressions/PostImpressionService.Exceptions.cs +++ b/Taarafo.Core/Services/Foundations/PostImpressions/PostImpressionService.Exceptions.cs @@ -149,4 +149,4 @@ private PostImpressionServiceException CreateAndLogServiceException(Exception ex return postImpressionServiceException; } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Services/Foundations/PostImpressions/PostImpressionService.Validations.cs b/Taarafo.Core/Services/Foundations/PostImpressions/PostImpressionService.Validations.cs index 3257355f..157581d8 100644 --- a/Taarafo.Core/Services/Foundations/PostImpressions/PostImpressionService.Validations.cs +++ b/Taarafo.Core/Services/Foundations/PostImpressions/PostImpressionService.Validations.cs @@ -4,8 +4,6 @@ // --------------------------------------------------------------- using System; -using System.Data; -using System.Reflection.Metadata; using Taarafo.Core.Models.PostImpressions; using Taarafo.Core.Models.PostImpressions.Exceptions; @@ -44,7 +42,7 @@ private void ValidatePostImpressionOnModify(PostImpression postImpression) (Rule: IsInvalid(postImpression.ProfileId), Parameter: nameof(PostImpression.ProfileId)), (Rule: IsInvalid(postImpression.CreatedDate), Parameter: nameof(PostImpression.CreatedDate)), (Rule: IsInvalid(postImpression.UpdatedDate), Parameter: nameof(PostImpression.UpdatedDate)), - (Rule:IsNotRecent(postImpression.UpdatedDate),Parameter:nameof(PostImpression.UpdatedDate)), + (Rule: IsNotRecent(postImpression.UpdatedDate), Parameter: nameof(PostImpression.UpdatedDate)), (Rule: IsSame( firstDate: postImpression.UpdatedDate, @@ -54,9 +52,13 @@ private void ValidatePostImpressionOnModify(PostImpression postImpression) Parameter: nameof(PostImpression.UpdatedDate))); } - private static void ValidateAginstStoragePostImpressionOnModify(PostImpression inputPostImpression,PostImpression storagePostImpression) + private static void ValidateAginstStoragePostImpressionOnModify( + PostImpression inputPostImpression, PostImpression storagePostImpression) { - ValidateStoragePostImpression(storagePostImpression, inputPostImpression.PostId, inputPostImpression.ProfileId); + ValidateStoragePostImpression( + storagePostImpression, + inputPostImpression.PostId, + inputPostImpression.ProfileId); Validate( (Rule: IsNotSame( @@ -71,7 +73,7 @@ private static void ValidateAginstStoragePostImpressionOnModify(PostImpression i secondDate: storagePostImpression.UpdatedDate, secondDateName: nameof(PostImpression.UpdatedDate)), - Parameter: nameof(PostImpression.UpdatedDate))); + Parameter: nameof(PostImpression.UpdatedDate))); } private void ValidatePostImpressionId(Guid postId, Guid profileId) => @@ -96,7 +98,8 @@ private static void ValidatePostImpressionOnRemove(PostImpression postImpression (Rule: IsInvalid(postImpression.ProfileId), Parameter: nameof(PostImpression.ProfileId))); } - private static void ValidateStoragePostImpression(PostImpression maybePostImpression, Guid postId, Guid profileId) + private static void ValidateStoragePostImpression( + PostImpression maybePostImpression, Guid postId, Guid profileId) { if (maybePostImpression is null) { diff --git a/Taarafo.Core/Services/Foundations/PostImpressions/PostImpressionService.cs b/Taarafo.Core/Services/Foundations/PostImpressions/PostImpressionService.cs index eb8b02b3..de8ae66c 100644 --- a/Taarafo.Core/Services/Foundations/PostImpressions/PostImpressionService.cs +++ b/Taarafo.Core/Services/Foundations/PostImpressions/PostImpressionService.cs @@ -41,42 +41,42 @@ public IQueryable RetrieveAllPostImpressions() => TryCatch(() => this.storageBroker.SelectAllPostImpressions()); public ValueTask RetrievePostImpressionByIdAsync(Guid postId, Guid profileId) => - TryCatch(async () => - { - ValidatePostImpressionId(postId, profileId); + TryCatch(async () => + { + ValidatePostImpressionId(postId, profileId); - PostImpression maybePostImpression = - await this.storageBroker.SelectPostImpressionByIdAsync(postId, profileId); + PostImpression maybePostImpression = + await this.storageBroker.SelectPostImpressionByIdAsync(postId, profileId); - ValidateStoragePostImpression(maybePostImpression, postId, profileId); + ValidateStoragePostImpression(maybePostImpression, postId, profileId); - return maybePostImpression; - }); + return maybePostImpression; + }); public ValueTask ModifyPostImpressionAsync(PostImpression postImpression) => - TryCatch(async () => - { - ValidatePostImpressionOnModify(postImpression); + TryCatch(async () => + { + ValidatePostImpressionOnModify(postImpression); - var maybePostImpression = await this.storageBroker.SelectPostImpressionByIdAsync( - postImpression.PostId, postImpression.ProfileId); + var maybePostImpression = await this.storageBroker.SelectPostImpressionByIdAsync( + postImpression.PostId, postImpression.ProfileId); - ValidateAginstStoragePostImpressionOnModify(postImpression, maybePostImpression); + ValidateAginstStoragePostImpressionOnModify(postImpression, maybePostImpression); - return await this.storageBroker.UpdatePostImpressionAsync(postImpression); - }); + return await this.storageBroker.UpdatePostImpressionAsync(postImpression); + }); public ValueTask RemovePostImpressionAsync(PostImpression postImpression) => - TryCatch(async () => - { - ValidatePostImpressionOnRemove(postImpression); + TryCatch(async () => + { + ValidatePostImpressionOnRemove(postImpression); - PostImpression somePostImpression = - await this.storageBroker.SelectPostImpressionByIdAsync(postImpression.PostId, postImpression.ProfileId); + PostImpression somePostImpression = + await this.storageBroker.SelectPostImpressionByIdAsync(postImpression.PostId, postImpression.ProfileId); - ValidateStoragePostImpression(somePostImpression, postImpression.PostId, postImpression.ProfileId); + ValidateStoragePostImpression(somePostImpression, postImpression.PostId, postImpression.ProfileId); - return await this.storageBroker.DeletePostImpressionAsync(somePostImpression); - }); + return await this.storageBroker.DeletePostImpressionAsync(somePostImpression); + }); } } \ No newline at end of file