From 45d1f78b248cc384e073d8a8275fd2e2cf5831e7 Mon Sep 17 00:00:00 2001 From: Greg Hays Date: Thu, 7 Sep 2023 18:28:16 -0700 Subject: [PATCH] CODE RUB: Profiles Exceptions Upgrade v2.10.0 Closes: #513 --- .../ProfileServiceTests.Exceptions.Add.cs | 52 +- .../ProfileServiceTests.Exceptions.Modify.cs | 560 +++++++++-------- ...ofileServiceTests.Exceptions.RemoveById.cs | 304 ++++----- ...fileServiceTests.Exceptions.RetrieveAll.cs | 182 +++--- ...ileServiceTests.Exceptions.RetrieveById.cs | 186 +++--- .../Profiles/ProfileServiceTests.Logic.Add.cs | 82 +-- .../ProfileServiceTests.Logic.Modify.cs | 137 ++-- .../ProfileServiceTests.Logic.RemoveById.cs | 86 +-- .../ProfileServiceTests.Logic.RetrieveAll.cs | 50 +- .../ProfileServiceTests.Logic.RetrieveById.cs | 73 ++- .../ProfileServiceTests.Validations.Add.cs | 444 ++++++------- .../ProfileServiceTests.Validations.Modify.cs | 586 +++++++++--------- ...fileServiceTests.Validations.RemoveById.cs | 188 +++--- ...leServiceTests.Validations.RetrieveById.cs | 176 +++--- .../Profiles/ProfileServiceTests.cs | 2 +- .../AlreadyExistsProfileException.cs | 10 +- .../FailedProfileServiceException.cs | 10 +- .../FailedProfileStorageException.cs | 8 +- .../Exceptions/InvalidProfileException.cs | 10 +- .../InvalidProfileReferenceException.cs | 10 +- .../Exceptions/LockedProfileException.cs | 10 +- .../Exceptions/NotFoundProfileException.cs | 6 +- .../Exceptions/NullProfileException.cs | 19 +- .../Exceptions/ProfileDependencyException.cs | 20 +- .../ProfileDependencyValidationException.cs | 20 +- .../Exceptions/ProfileServiceException.cs | 10 +- .../Exceptions/ProfileValidationException.cs | 11 +- .../Profiles/ProfileService.Exceptions.cs | 2 +- .../Profiles/ProfileService.Validations.cs | 2 +- .../Foundations/Profiles/ProfileService.cs | 2 +- 30 files changed, 1708 insertions(+), 1550 deletions(-) diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.Add.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.Add.cs index 8bb62eb2..45f8e521 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.Add.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.Add.cs @@ -19,7 +19,7 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles public partial class ProfileServiceTests { [Fact] - public async Task ShouldThrowCriticalDependencyExceptionOnAddIfSqlErrorOccursAndLogItAsync() + private async Task ShouldThrowCriticalDependencyExceptionOnAddIfSqlErrorOccursAndLogItAsync() { // given DateTimeOffset randomDateTime = GetRandomDateTime(); @@ -27,10 +27,14 @@ public async Task ShouldThrowCriticalDependencyExceptionOnAddIfSqlErrorOccursAnd SqlException sqlException = GetSqlException(); var failedProfileStorageException = - new FailedProfileStorageException(sqlException); + new FailedProfileStorageException( + message: "Failed profile storage error occurred, contact support.", + innerException: sqlException); var expectedProfileDependencyException = - new ProfileDependencyException(failedProfileStorageException); + new ProfileDependencyException( + message: "Profile dependency error occurred, contact support.", + innerException: failedProfileStorageException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()) @@ -67,7 +71,7 @@ await Assert.ThrowsAsync( } [Fact] - public async Task ShouldThrowDependencyValidationExceptionOnAddIfProfileAlreadyExsitsAndLogItAsync() + private async Task ShouldThrowDependencyValidationExceptionOnAddIfProfileAlreadyExsitsAndLogItAsync() { // given Profile randomProfile = CreateRandomProfile(); @@ -78,10 +82,14 @@ public async Task ShouldThrowDependencyValidationExceptionOnAddIfProfileAlreadyE new DuplicateKeyException(randomMessage); var alreadyExistsProfileException = - new AlreadyExistsProfileException(duplicateKeyException); + new AlreadyExistsProfileException( + message: "Profile with the same id already exists.", + innerException: duplicateKeyException); var expectedProfileDependencyValidationException = - new ProfileDependencyValidationException(alreadyExistsProfileException); + new ProfileDependencyValidationException( + message: "Profile dependency validation occurred, please try again.", + innerException: alreadyExistsProfileException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()) @@ -118,7 +126,7 @@ await Assert.ThrowsAsync( } [Fact] - public async void ShouldThrowValidationExceptionOnAddIfReferenceErrorOccursAndLogItAsync() + private async void ShouldThrowValidationExceptionOnAddIfReferenceErrorOccursAndLogItAsync() { // given Profile someProfile = CreateRandomProfile(); @@ -129,10 +137,14 @@ public async void ShouldThrowValidationExceptionOnAddIfReferenceErrorOccursAndLo new ForeignKeyConstraintConflictException(exceptionMessage); var invalidProfileReferenceException = - new InvalidProfileReferenceException(foreignKeyConstraintConflictException); + new InvalidProfileReferenceException( + message: "Invalid profile reference error occurred.", + innerException: foreignKeyConstraintConflictException); var expectedProfileDependencyValidationException = - new ProfileDependencyValidationException(invalidProfileReferenceException); + new ProfileDependencyValidationException( + message: "Profile dependency validation occurred, please try again.", + innerException: invalidProfileReferenceException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()) @@ -169,7 +181,7 @@ await Assert.ThrowsAsync( } [Fact] - public async Task ShouldThrowDependencyExceptionOnAddIfDatabaseUpdateErrorOccursAndLogItAsync() + private async Task ShouldThrowDependencyExceptionOnAddIfDatabaseUpdateErrorOccursAndLogItAsync() { // given Profile someProfile = CreateRandomProfile(); @@ -178,10 +190,14 @@ public async Task ShouldThrowDependencyExceptionOnAddIfDatabaseUpdateErrorOccurs new DbUpdateException(); var failedProfileStorageException = - new FailedProfileStorageException(databaseUpdateException); + new FailedProfileStorageException( + message: "Failed profile storage error occurred, contact support.", + innerException: databaseUpdateException); var expectedProfileDependencyException = - new ProfileDependencyException(failedProfileStorageException); + new ProfileDependencyException( + message: "Profile dependency error occurred, contact support.", + innerException: failedProfileStorageException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()) @@ -218,17 +234,21 @@ await Assert.ThrowsAsync( } [Fact] - public async Task ShouldThrowServiceExceptionOnAddIfServiceErrorOccursAndLogItAsync() + private async Task ShouldThrowServiceExceptionOnAddIfServiceErrorOccursAndLogItAsync() { // given Profile someProfile = CreateRandomProfile(); var serviceException = new Exception(); var failedProfileServiceException = - new FailedProfileServiceException(serviceException); + new FailedProfileServiceException( + message: "Failed profile service occurred, please contact support", + innerException: serviceException); var expectedProfileServiceException = - new ProfileServiceException(failedProfileServiceException); + new ProfileServiceException( + message: "Profile service error occurred, contact support.", + innerException: failedProfileServiceException); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTimeOffset()) @@ -264,4 +284,4 @@ await Assert.ThrowsAsync( this.loggingBrokerMock.VerifyNoOtherCalls(); } } -} +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.Modify.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.Modify.cs index b455615d..43b2b004 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.Modify.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.Modify.cs @@ -16,272 +16,294 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public async Task ShouldThrowCriticalDependencyExceptionOnModifyIfSqlErrorOccursAndLogItAsync() - { - // given - Profile randomProfile = CreateRandomProfile(); - SqlException sqlException = GetSqlException(); - - var failedProfileStorageException = - new FailedProfileStorageException(sqlException); - - var expectedProfileDependencyException = - new ProfileDependencyException(failedProfileStorageException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Throws(sqlException); - - // when - ValueTask modifyProfileTask = - this.profileService.ModifyProfileAsync(randomProfile); - - ProfileDependencyException actualProfileDependencyException = - await Assert.ThrowsAsync( - modifyProfileTask.AsTask); - - // then - actualProfileDependencyException.Should().BeEquivalentTo( - expectedProfileDependencyException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(randomProfile.Id), - Times.Never); - - this.storageBrokerMock.Verify(broker => - broker.UpdateProfileAsync(randomProfile), - Times.Never); - - this.loggingBrokerMock.Verify(broker => - broker.LogCritical(It.Is(SameExceptionAs( - expectedProfileDependencyException))), - Times.Once); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async void ShouldThrowValidationExceptionOnModifyIfReferenceErrorOccursAndLogItAsync() - { - // given - Profile someProfile = - CreateRandomProfile(); - - Profile foreignKeyConflictedProfile = - someProfile; - - string randomMessage = - GetRandomMessage(); - - string exceptionMessage = - randomMessage; - - var foreignKeyConstraintConflictException = - new ForeignKeyConstraintConflictException(exceptionMessage); - - var invalidProfileReferenceException = - new InvalidProfileReferenceException(foreignKeyConstraintConflictException); - - var profileDependencyValidationException = - new ProfileDependencyValidationException(invalidProfileReferenceException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Throws(foreignKeyConstraintConflictException); - - // when - ValueTask modifyProfileTask = - this.profileService.ModifyProfileAsync(foreignKeyConflictedProfile); - - ProfileDependencyValidationException actualProfileDependencyValidationException = - await Assert.ThrowsAsync( - modifyProfileTask.AsTask); - - // then - actualProfileDependencyValidationException.Should().BeEquivalentTo( - profileDependencyValidationException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(foreignKeyConflictedProfile.Id), - Times.Never); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs(profileDependencyValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.UpdateProfileAsync(foreignKeyConflictedProfile), - Times.Never); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowDependencyExceptionOnModifyIfDatabaseUpdateExceptionOccursAndLogItAsync() - { - // given - Profile randomProfile = CreateRandomProfile(); - var databaseUpdateException = new DbUpdateException(); - - var failedProfileStorageException = - new FailedProfileStorageException(databaseUpdateException); - - var expectedProfileDependencyException = - new ProfileDependencyException(failedProfileStorageException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Throws(databaseUpdateException); - - // when - ValueTask modifyProfileTask = - this.profileService.ModifyProfileAsync(randomProfile); - - ProfileDependencyException actualProfileDependencyException = - await Assert.ThrowsAsync( - modifyProfileTask.AsTask); - - // then - actualProfileDependencyException.Should().BeEquivalentTo( - expectedProfileDependencyException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(randomProfile.Id), - Times.Never); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileDependencyException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.UpdateProfileAsync(randomProfile), - Times.Never); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowDependencyValidationExceptionOnModifyIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync() - { - // given - Profile randomProfile = CreateRandomProfile(); - var databaseUpdateConcurrencyException = new DbUpdateConcurrencyException(); - - var lockedProfileException = - new LockedProfileException(databaseUpdateConcurrencyException); - - var expectedProfileDependencyValidationException = - new ProfileDependencyValidationException(lockedProfileException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Throws(databaseUpdateConcurrencyException); - - // when - ValueTask modifyProfileTask = - this.profileService.ModifyProfileAsync(randomProfile); - - ProfileDependencyValidationException actualProfileDependencyValidationException = - await Assert.ThrowsAsync( - modifyProfileTask.AsTask); - - // then - actualProfileDependencyValidationException.Should().BeEquivalentTo( - expectedProfileDependencyValidationException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(randomProfile.Id), - Times.Never); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileDependencyValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.UpdateProfileAsync(randomProfile), - Times.Never); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowServiceExceptionOnModifyIfServiceErrorOccursAndLogItAsync() - { - // given - Profile randomProfile = CreateRandomProfile(); - var serviceException = new Exception(); - - var failedProfileException = - new FailedProfileServiceException(serviceException); - - var expectedProfileServiceException = - new ProfileServiceException(failedProfileException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Throws(serviceException); - - // when - ValueTask modifyProfileTask = - this.profileService.ModifyProfileAsync(randomProfile); - - ProfileServiceException actualProfileServiceException = - await Assert.ThrowsAsync( - modifyProfileTask.AsTask); - - // then - actualProfileServiceException.Should().BeEquivalentTo( - expectedProfileServiceException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(randomProfile.Id), - Times.Never); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileServiceException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.UpdateProfileAsync(randomProfile), - Times.Never); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class ProfileServiceTests + { + [Fact] + private async Task ShouldThrowCriticalDependencyExceptionOnModifyIfSqlErrorOccursAndLogItAsync() + { + // given + Profile randomProfile = CreateRandomProfile(); + SqlException sqlException = GetSqlException(); + + var failedProfileStorageException = + new FailedProfileStorageException( + message: "Failed profile storage error occurred, contact support.", + innerException: sqlException); + + var expectedProfileDependencyException = + new ProfileDependencyException( + message: "Profile dependency error occurred, contact support.", + innerException: failedProfileStorageException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Throws(sqlException); + + // when + ValueTask modifyProfileTask = + this.profileService.ModifyProfileAsync(randomProfile); + + ProfileDependencyException actualProfileDependencyException = + await Assert.ThrowsAsync( + modifyProfileTask.AsTask); + + // then + actualProfileDependencyException.Should().BeEquivalentTo( + expectedProfileDependencyException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(randomProfile.Id), + Times.Never); + + this.storageBrokerMock.Verify(broker => + broker.UpdateProfileAsync(randomProfile), + Times.Never); + + this.loggingBrokerMock.Verify(broker => + broker.LogCritical(It.Is(SameExceptionAs( + expectedProfileDependencyException))), + Times.Once); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async void ShouldThrowValidationExceptionOnModifyIfReferenceErrorOccursAndLogItAsync() + { + // given + Profile someProfile = + CreateRandomProfile(); + + Profile foreignKeyConflictedProfile = + someProfile; + + string randomMessage = + GetRandomMessage(); + + string exceptionMessage = + randomMessage; + + var foreignKeyConstraintConflictException = + new ForeignKeyConstraintConflictException(exceptionMessage); + + var invalidProfileReferenceException = + new InvalidProfileReferenceException( + message: "Invalid profile reference error occurred.", + innerException: foreignKeyConstraintConflictException); + + var profileDependencyValidationException = + new ProfileDependencyValidationException( + message: "Profile dependency validation occurred, please try again.", + innerException: invalidProfileReferenceException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Throws(foreignKeyConstraintConflictException); + + // when + ValueTask modifyProfileTask = + this.profileService.ModifyProfileAsync(foreignKeyConflictedProfile); + + ProfileDependencyValidationException actualProfileDependencyValidationException = + await Assert.ThrowsAsync( + modifyProfileTask.AsTask); + + // then + actualProfileDependencyValidationException.Should().BeEquivalentTo( + profileDependencyValidationException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(foreignKeyConflictedProfile.Id), + Times.Never); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs(profileDependencyValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.UpdateProfileAsync(foreignKeyConflictedProfile), + Times.Never); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowDependencyExceptionOnModifyIfDatabaseUpdateExceptionOccursAndLogItAsync() + { + // given + Profile randomProfile = CreateRandomProfile(); + var databaseUpdateException = new DbUpdateException(); + + var failedProfileStorageException = + new FailedProfileStorageException( + message: "Failed profile storage error occurred, contact support.", + innerException: databaseUpdateException); + + var expectedProfileDependencyException = + new ProfileDependencyException( + message: "Profile dependency error occurred, contact support.", + innerException: failedProfileStorageException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Throws(databaseUpdateException); + + // when + ValueTask modifyProfileTask = + this.profileService.ModifyProfileAsync(randomProfile); + + ProfileDependencyException actualProfileDependencyException = + await Assert.ThrowsAsync( + modifyProfileTask.AsTask); + + // then + actualProfileDependencyException.Should().BeEquivalentTo( + expectedProfileDependencyException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(randomProfile.Id), + Times.Never); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileDependencyException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.UpdateProfileAsync(randomProfile), + Times.Never); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowDependencyValidationExceptionOnModifyIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync() + { + // given + Profile randomProfile = CreateRandomProfile(); + + var databaseUpdateConcurrencyException = + new DbUpdateConcurrencyException(); + + var lockedProfileException = + new LockedProfileException( + message: "Locked profile record exception, please try again later", + innerException: databaseUpdateConcurrencyException); + + var expectedProfileDependencyValidationException = + new ProfileDependencyValidationException( + message: "Profile dependency validation occurred, please try again.", + innerException: lockedProfileException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Throws(databaseUpdateConcurrencyException); + + // when + ValueTask modifyProfileTask = + this.profileService.ModifyProfileAsync(randomProfile); + + ProfileDependencyValidationException actualProfileDependencyValidationException = + await Assert.ThrowsAsync( + modifyProfileTask.AsTask); + + // then + actualProfileDependencyValidationException.Should().BeEquivalentTo( + expectedProfileDependencyValidationException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(randomProfile.Id), + Times.Never); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileDependencyValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.UpdateProfileAsync(randomProfile), + Times.Never); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowServiceExceptionOnModifyIfServiceErrorOccursAndLogItAsync() + { + // given + Profile randomProfile = CreateRandomProfile(); + var serviceException = new Exception(); + + var failedProfileException = + new FailedProfileServiceException( + message: "Failed profile service occurred, please contact support", + innerException: serviceException); + + var expectedProfileServiceException = + new ProfileServiceException( + message: "Profile service error occurred, contact support.", + innerException: failedProfileException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Throws(serviceException); + + // when + ValueTask modifyProfileTask = + this.profileService.ModifyProfileAsync(randomProfile); + + ProfileServiceException actualProfileServiceException = + await Assert.ThrowsAsync( + modifyProfileTask.AsTask); + + // then + actualProfileServiceException.Should().BeEquivalentTo( + expectedProfileServiceException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(randomProfile.Id), + Times.Never); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileServiceException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.UpdateProfileAsync(randomProfile), + Times.Never); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + } + } +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.RemoveById.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.RemoveById.cs index faa880e1..97f38b7e 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.RemoveById.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.RemoveById.cs @@ -15,149 +15,161 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public async Task ShouldThrowCriticalDependencyExceptionOnRemoveWhenSqlExceptionOccursAndLogItAsync() - { - // given - Guid someProfileId = Guid.NewGuid(); - SqlException sqlException = GetSqlException(); - - var failedProfileStorageException = - new FailedProfileStorageException(sqlException); - - var expectedProfileDependencyException = - new ProfileDependencyException(failedProfileStorageException); - - this.storageBrokerMock.Setup(broker => - broker.SelectProfileByIdAsync(It.IsAny())) - .ThrowsAsync(sqlException); - - // when - ValueTask removeProfileByIdTask = - this.profileService.RemoveProfileByIdAsync(someProfileId); - - ProfileDependencyException actualProfileDependencyException = - await Assert.ThrowsAsync( - removeProfileByIdTask.AsTask); - - // then - actualProfileDependencyException.Should().BeEquivalentTo( - expectedProfileDependencyException); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(It.IsAny()), - Times.Once); - - this.loggingBrokerMock.Verify(broker => - broker.LogCritical(It.Is(SameExceptionAs( - expectedProfileDependencyException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.DeleteProfileAsync(It.IsAny()), - Times.Never); - - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowDependencyValidationOnRemoveIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync() - { - // given - Guid someProfileId = Guid.NewGuid(); - - var databaseUpdateConcurrencyException = - new DbUpdateConcurrencyException(); - - var lockedProfileException = - new LockedProfileException(databaseUpdateConcurrencyException); - - var expectedProfileDependencyValidationException = - new ProfileDependencyValidationException(lockedProfileException); - - this.storageBrokerMock.Setup(broker => - broker.SelectProfileByIdAsync(It.IsAny())) - .ThrowsAsync(databaseUpdateConcurrencyException); - - // when - ValueTask removeProfileByIdTask = - this.profileService.RemoveProfileByIdAsync(someProfileId); - - ProfileDependencyValidationException actualProfileDependencyValidationException = - await Assert.ThrowsAsync( - removeProfileByIdTask.AsTask); - - // then - actualProfileDependencyValidationException.Should().BeEquivalentTo( - expectedProfileDependencyValidationException); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(It.IsAny()), - Times.Once); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileDependencyValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.DeleteProfileAsync(It.IsAny()), - Times.Never); - - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowServiceExceptionOnRemoveIfExceptionOccursAndLogItAsync() - { - // given - Guid someProfileId = Guid.NewGuid(); - var serviceException = new Exception(); - - var failedProfileServiceException = - new FailedProfileServiceException(serviceException); - - var expectedProfileServiceException = - new ProfileServiceException(failedProfileServiceException); - - this.storageBrokerMock.Setup(broker => - broker.SelectProfileByIdAsync(It.IsAny())) - .ThrowsAsync(serviceException); - - // when - ValueTask removeProfileByIdTask = - this.profileService.RemoveProfileByIdAsync(someProfileId); - - ProfileServiceException actualProfileServiceException = - await Assert.ThrowsAsync( - removeProfileByIdTask.AsTask); - - // then - actualProfileServiceException.Should() - .BeEquivalentTo(expectedProfileServiceException); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(It.IsAny()), - Times.Once()); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileServiceException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.DeleteProfileAsync(It.IsAny()), - Times.Never()); - - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class ProfileServiceTests + { + [Fact] + private async Task ShouldThrowCriticalDependencyExceptionOnRemoveWhenSqlExceptionOccursAndLogItAsync() + { + // given + Guid someProfileId = Guid.NewGuid(); + SqlException sqlException = GetSqlException(); + + var failedProfileStorageException = + new FailedProfileStorageException( + message: "Failed profile storage error occurred, contact support.", + innerException: sqlException); + + var expectedProfileDependencyException = + new ProfileDependencyException( + message: "Profile dependency error occurred, contact support.", + innerException: failedProfileStorageException); + + this.storageBrokerMock.Setup(broker => + broker.SelectProfileByIdAsync(It.IsAny())) + .ThrowsAsync(sqlException); + + // when + ValueTask removeProfileByIdTask = + this.profileService.RemoveProfileByIdAsync(someProfileId); + + ProfileDependencyException actualProfileDependencyException = + await Assert.ThrowsAsync( + removeProfileByIdTask.AsTask); + + // then + actualProfileDependencyException.Should().BeEquivalentTo( + expectedProfileDependencyException); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(It.IsAny()), + Times.Once); + + this.loggingBrokerMock.Verify(broker => + broker.LogCritical(It.Is(SameExceptionAs( + expectedProfileDependencyException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.DeleteProfileAsync(It.IsAny()), + Times.Never); + + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowDependencyValidationOnRemoveIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync() + { + // given + Guid someProfileId = Guid.NewGuid(); + + var databaseUpdateConcurrencyException = + new DbUpdateConcurrencyException(); + + var lockedProfileException = + new LockedProfileException( + message: "Locked profile record exception, please try again later", + innerException: databaseUpdateConcurrencyException); + + var expectedProfileDependencyValidationException = + new ProfileDependencyValidationException( + message: "Profile dependency validation occurred, please try again.", + innerException: lockedProfileException); + + this.storageBrokerMock.Setup(broker => + broker.SelectProfileByIdAsync(It.IsAny())) + .ThrowsAsync(databaseUpdateConcurrencyException); + + // when + ValueTask removeProfileByIdTask = + this.profileService.RemoveProfileByIdAsync(someProfileId); + + ProfileDependencyValidationException actualProfileDependencyValidationException = + await Assert.ThrowsAsync( + removeProfileByIdTask.AsTask); + + // then + actualProfileDependencyValidationException.Should().BeEquivalentTo( + expectedProfileDependencyValidationException); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(It.IsAny()), + Times.Once); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileDependencyValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.DeleteProfileAsync(It.IsAny()), + Times.Never); + + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowServiceExceptionOnRemoveIfExceptionOccursAndLogItAsync() + { + // given + Guid someProfileId = Guid.NewGuid(); + var serviceException = new Exception(); + + var failedProfileServiceException = + new FailedProfileServiceException( + message: "Failed profile service occurred, please contact support", + innerException: serviceException); + + var expectedProfileServiceException = + new ProfileServiceException( + message: "Profile service error occurred, contact support.", + innerException: failedProfileServiceException); + + this.storageBrokerMock.Setup(broker => + broker.SelectProfileByIdAsync(It.IsAny())) + .ThrowsAsync(serviceException); + + // when + ValueTask removeProfileByIdTask = + this.profileService.RemoveProfileByIdAsync(someProfileId); + + ProfileServiceException actualProfileServiceException = + await Assert.ThrowsAsync( + removeProfileByIdTask.AsTask); + + // then + actualProfileServiceException.Should() + .BeEquivalentTo(expectedProfileServiceException); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(It.IsAny()), + Times.Once()); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileServiceException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.DeleteProfileAsync(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/Profiles/ProfileServiceTests.Exceptions.RetrieveAll.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.RetrieveAll.cs index 236a4533..830fc420 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.RetrieveAll.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.RetrieveAll.cs @@ -12,90 +12,98 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public void ShouldThrowCriticalDependencyExceptionOnRetrieveAllWhenSqlExceptionOccursAndLogIt() - { - // given - SqlException sqlException = GetSqlException(); - - var failedProfileStorageException = - new FailedProfileStorageException(sqlException); - - var expectedProfileDependencyException = - new ProfileDependencyException(failedProfileStorageException); - - this.storageBrokerMock.Setup(broker => - broker.SelectAllProfiles()) - .Throws(sqlException); - - // when - Action retrieveAllProfileAction = () => - this.profileService.RetrieveAllProfiles(); - - ProfileDependencyException actualProfileDependencyException = - Assert.Throws( - retrieveAllProfileAction); - - // then - actualProfileDependencyException.Should() - .BeEquivalentTo(expectedProfileDependencyException); - - this.storageBrokerMock.Verify(broker => - broker.SelectAllProfiles()); - - this.loggingBrokerMock.Verify(broker => - broker.LogCritical(It.Is(SameExceptionAs( - expectedProfileDependencyException))), - Times.Once); - - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public void ShouldThrowServiceExceptionOnRetrieveAllWhenAllServiceErrorOccursAndLogIt() - { - // given - string exceptionMessage = GetRandomMessage(); - var serviceException = new Exception(exceptionMessage); - - var faileProfileServiceException = - new FailedProfileServiceException(serviceException); - - var expectedProfileServiceException = - new ProfileServiceException(faileProfileServiceException); - - this.storageBrokerMock.Setup(broker => - broker.SelectAllProfiles()) - .Throws(serviceException); - - // when - Action retrieveAllProfilesAction = () => - this.profileService.RetrieveAllProfiles(); - - ProfileServiceException actualProfileServiceException = - Assert.Throws( - retrieveAllProfilesAction); - - // then - actualProfileServiceException.Should().BeEquivalentTo( - expectedProfileServiceException); - - this.storageBrokerMock.Verify(broker => - broker.SelectAllProfiles(), - Times.Once); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileServiceException))), - Times.Once); - - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class ProfileServiceTests + { + [Fact] + private void ShouldThrowCriticalDependencyExceptionOnRetrieveAllWhenSqlExceptionOccursAndLogIt() + { + // given + SqlException sqlException = GetSqlException(); + + var failedProfileStorageException = + new FailedProfileStorageException( + message: "Failed profile storage error occurred, contact support.", + innerException: sqlException); + + var expectedProfileDependencyException = + new ProfileDependencyException( + message: "Profile dependency error occurred, contact support.", + innerException: failedProfileStorageException); + + this.storageBrokerMock.Setup(broker => + broker.SelectAllProfiles()) + .Throws(sqlException); + + // when + Action retrieveAllProfileAction = () => + this.profileService.RetrieveAllProfiles(); + + ProfileDependencyException actualProfileDependencyException = + Assert.Throws( + retrieveAllProfileAction); + + // then + actualProfileDependencyException.Should() + .BeEquivalentTo(expectedProfileDependencyException); + + this.storageBrokerMock.Verify(broker => + broker.SelectAllProfiles()); + + this.loggingBrokerMock.Verify(broker => + broker.LogCritical(It.Is(SameExceptionAs( + expectedProfileDependencyException))), + Times.Once); + + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private void ShouldThrowServiceExceptionOnRetrieveAllWhenAllServiceErrorOccursAndLogIt() + { + // given + string exceptionMessage = GetRandomMessage(); + var serviceException = new Exception(exceptionMessage); + + var faileProfileServiceException = + new FailedProfileServiceException( + message: "Failed profile service occurred, please contact support", + innerException: serviceException); + + var expectedProfileServiceException = + new ProfileServiceException( + message: "Profile service error occurred, contact support.", + innerException: faileProfileServiceException); + + this.storageBrokerMock.Setup(broker => + broker.SelectAllProfiles()) + .Throws(serviceException); + + // when + Action retrieveAllProfilesAction = () => + this.profileService.RetrieveAllProfiles(); + + ProfileServiceException actualProfileServiceException = + Assert.Throws( + retrieveAllProfilesAction); + + // then + actualProfileServiceException.Should().BeEquivalentTo( + expectedProfileServiceException); + + this.storageBrokerMock.Verify(broker => + broker.SelectAllProfiles(), + Times.Once); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileServiceException))), + 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/Profiles/ProfileServiceTests.Exceptions.RetrieveById.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.RetrieveById.cs index 09094ed9..656c009f 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.RetrieveById.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Exceptions.RetrieveById.cs @@ -14,92 +14,100 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public async Task ShouldThrowCriticalDependencyExceptionOnRetrieveByIdIfSqlErrorOccursAndLogItAsync() - { - // given - Guid someId = Guid.NewGuid(); - SqlException sqlException = GetSqlException(); - - var failedProfileStorageException = - new FailedProfileStorageException(sqlException); - - var expectedProfileDependencyException = - new ProfileDependencyException(failedProfileStorageException); - - this.storageBrokerMock.Setup(broker => - broker.SelectProfileByIdAsync(It.IsAny())) - .ThrowsAsync(sqlException); - - // when - ValueTask retrieveProfileByIdTask = - this.profileService.RetrieveProfileByIdAsync(someId); - - ProfileDependencyException actaulProfileDependencyException = - await Assert.ThrowsAsync( - retrieveProfileByIdTask.AsTask); - - // then - actaulProfileDependencyException.Should().BeEquivalentTo( - expectedProfileDependencyException); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(It.IsAny()), - Times.Once); - - this.loggingBrokerMock.Verify(broker => - broker.LogCritical(It.Is(SameExceptionAs( - expectedProfileDependencyException))), - Times.Once); - - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowServiceExceptionOnRetrieveByIdIfDatabaseUpdateErrorOccursAndLogItAsync() - { - // given - Guid someId = Guid.NewGuid(); - var serviceException = new Exception(); - - var failedProfileServiceException = - new FailedProfileServiceException(serviceException); - - var expectedProfileServiceException = - new ProfileServiceException(failedProfileServiceException); - - this.storageBrokerMock.Setup(broker => - broker.SelectProfileByIdAsync(It.IsAny())) - .ThrowsAsync(serviceException); - - // when - ValueTask retrieveProfileByIdTask = - this.profileService.RetrieveProfileByIdAsync(someId); - - ProfileServiceException actualProfileServiceException = - await Assert.ThrowsAsync( - retrieveProfileByIdTask.AsTask); - - // then - actualProfileServiceException.Should().BeEquivalentTo( - expectedProfileServiceException); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(It.IsAny()), - Times.Once); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileServiceException))), - Times.Once); - - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class ProfileServiceTests + { + [Fact] + private async Task ShouldThrowCriticalDependencyExceptionOnRetrieveByIdIfSqlErrorOccursAndLogItAsync() + { + // given + Guid someId = Guid.NewGuid(); + SqlException sqlException = GetSqlException(); + + var failedProfileStorageException = + new FailedProfileStorageException( + message: "Failed profile storage error occurred, contact support.", + innerException: sqlException); + + var expectedProfileDependencyException = + new ProfileDependencyException( + message: "Profile dependency error occurred, contact support.", + innerException: failedProfileStorageException); + + this.storageBrokerMock.Setup(broker => + broker.SelectProfileByIdAsync(It.IsAny())) + .ThrowsAsync(sqlException); + + // when + ValueTask retrieveProfileByIdTask = + this.profileService.RetrieveProfileByIdAsync(someId); + + ProfileDependencyException actaulProfileDependencyException = + await Assert.ThrowsAsync( + retrieveProfileByIdTask.AsTask); + + // then + actaulProfileDependencyException.Should().BeEquivalentTo( + expectedProfileDependencyException); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(It.IsAny()), + Times.Once); + + this.loggingBrokerMock.Verify(broker => + broker.LogCritical(It.Is(SameExceptionAs( + expectedProfileDependencyException))), + Times.Once); + + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowServiceExceptionOnRetrieveByIdIfDatabaseUpdateErrorOccursAndLogItAsync() + { + // given + Guid someId = Guid.NewGuid(); + var serviceException = new Exception(); + + var failedProfileServiceException = + new FailedProfileServiceException( + message: "Failed profile service occurred, please contact support", + innerException: serviceException); + + var expectedProfileServiceException = + new ProfileServiceException( + message: "Profile service error occurred, contact support.", + innerException: failedProfileServiceException); + + this.storageBrokerMock.Setup(broker => + broker.SelectProfileByIdAsync(It.IsAny())) + .ThrowsAsync(serviceException); + + // when + ValueTask retrieveProfileByIdTask = + this.profileService.RetrieveProfileByIdAsync(someId); + + ProfileServiceException actualProfileServiceException = + await Assert.ThrowsAsync( + retrieveProfileByIdTask.AsTask); + + // then + actualProfileServiceException.Should().BeEquivalentTo( + expectedProfileServiceException); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(It.IsAny()), + Times.Once); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileServiceException))), + 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/Profiles/ProfileServiceTests.Logic.Add.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.Add.cs index 59c8a9b4..676ef29d 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.Add.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.Add.cs @@ -13,44 +13,44 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public async Task ShouldAddProfileAsync() - { - // given - DateTimeOffset randomDateTime = GetRandomDateTime(); - Profile randomProfile = CreateRandomProfile(randomDateTime); - Profile inputProfile = randomProfile; - Profile insertedProfile = inputProfile; - Profile expectedProfile = insertedProfile.DeepClone(); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Returns(randomDateTime); - - this.storageBrokerMock.Setup(broker => - broker.InsertProfileAsync(inputProfile)) - .ReturnsAsync(insertedProfile); - - // when - Profile actualProfile = - await this.profileService.AddProfileAsync(inputProfile); - - // then - actualProfile.Should().BeEquivalentTo(expectedProfile); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.InsertProfileAsync(inputProfile), - Times.Once()); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class ProfileServiceTests + { + [Fact] + private async Task ShouldAddProfileAsync() + { + // given + DateTimeOffset randomDateTime = GetRandomDateTime(); + Profile randomProfile = CreateRandomProfile(randomDateTime); + Profile inputProfile = randomProfile; + Profile insertedProfile = inputProfile; + Profile expectedProfile = insertedProfile.DeepClone(); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Returns(randomDateTime); + + this.storageBrokerMock.Setup(broker => + broker.InsertProfileAsync(inputProfile)) + .ReturnsAsync(insertedProfile); + + // when + Profile actualProfile = + await this.profileService.AddProfileAsync(inputProfile); + + // then + actualProfile.Should().BeEquivalentTo(expectedProfile); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.InsertProfileAsync(inputProfile), + 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/Profiles/ProfileServiceTests.Logic.Modify.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.Modify.cs index c5e2b6e0..9506609c 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.Modify.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.Modify.cs @@ -13,74 +13,69 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public async Task ShouldModifyProfileAsync() - { - // given - DateTimeOffset randomDate = - GetRandomDateTimeOffset(); - - Profile randomProfile = - CreateRandomProfile(randomDate); - - Profile inputProfile = - randomProfile; - - inputProfile.UpdatedDate = - randomDate.AddMinutes(1); - - Profile storageProfile = - inputProfile; - - Profile updatedProfile = - inputProfile; - - Profile expectedProfile = - updatedProfile.DeepClone(); - - Guid inputProfileId = - inputProfile.Id; - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Returns(randomDate); - - this.storageBrokerMock.Setup(broker => - broker.SelectProfileByIdAsync( - inputProfileId)) - .ReturnsAsync(storageProfile); - - this.storageBrokerMock.Setup(broker => - broker.UpdateProfileAsync( - inputProfile)) - .ReturnsAsync(updatedProfile); - - // when - Profile actualProfile = - await this.profileService. - ModifyProfileAsync(inputProfile); - - // then - actualProfile.Should().BeEquivalentTo( - expectedProfile); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(inputProfileId), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.UpdateProfileAsync(inputProfile), - Times.Once); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class ProfileServiceTests + { + [Fact] + private async Task ShouldModifyProfileAsync() + { + // given + DateTimeOffset randomDate = + GetRandomDateTimeOffset(); + + Profile randomProfile = + CreateRandomProfile(randomDate); + + Profile inputProfile = randomProfile; + + inputProfile.UpdatedDate = + randomDate.AddMinutes(1); + + Profile storageProfile = inputProfile; + Profile updatedProfile = inputProfile; + + Profile expectedProfile = + updatedProfile.DeepClone(); + + Guid inputProfileId = inputProfile.Id; + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Returns(randomDate); + + this.storageBrokerMock.Setup(broker => + broker.SelectProfileByIdAsync( + inputProfileId)) + .ReturnsAsync(storageProfile); + + this.storageBrokerMock.Setup(broker => + broker.UpdateProfileAsync( + inputProfile)) + .ReturnsAsync(updatedProfile); + + // when + Profile actualProfile = + await this.profileService. + ModifyProfileAsync(inputProfile); + + // then + actualProfile.Should().BeEquivalentTo( + expectedProfile); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(inputProfileId), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.UpdateProfileAsync(inputProfile), + 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/Profiles/ProfileServiceTests.Logic.RemoveById.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.RemoveById.cs index 77f3a2db..38359521 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.RemoveById.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.RemoveById.cs @@ -12,46 +12,46 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public async void ShouldRemoveProfileByIdAsync() - { - // given - Guid randomId = Guid.NewGuid(); - Guid inputProfileId = randomId; - Profile randomProfile = CreateRandomProfile(); - Profile storageProfile = randomProfile; - Profile expectedInputProfile = storageProfile; - Profile deletedProfile = expectedInputProfile; - Profile expectedProfile = deletedProfile.DeepClone(); - - this.storageBrokerMock.Setup(broker => - broker.SelectProfileByIdAsync(inputProfileId)) - .ReturnsAsync(storageProfile); - - this.storageBrokerMock.Setup(broker => - broker.DeleteProfileAsync(expectedInputProfile)) - .ReturnsAsync(deletedProfile); - - // when - Profile actualProfile = await this.profileService - .RemoveProfileByIdAsync(inputProfileId); - - // then - actualProfile.Should().BeEquivalentTo(expectedProfile); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(inputProfileId), - Times.Once()); - - this.storageBrokerMock.Verify(broker => - broker.DeleteProfileAsync(expectedInputProfile), - Times.Once); - - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class ProfileServiceTests + { + [Fact] + private async void ShouldRemoveProfileByIdAsync() + { + // given + Guid randomId = Guid.NewGuid(); + Guid inputProfileId = randomId; + Profile randomProfile = CreateRandomProfile(); + Profile storageProfile = randomProfile; + Profile expectedInputProfile = storageProfile; + Profile deletedProfile = expectedInputProfile; + Profile expectedProfile = deletedProfile.DeepClone(); + + this.storageBrokerMock.Setup(broker => + broker.SelectProfileByIdAsync(inputProfileId)) + .ReturnsAsync(storageProfile); + + this.storageBrokerMock.Setup(broker => + broker.DeleteProfileAsync(expectedInputProfile)) + .ReturnsAsync(deletedProfile); + + // when + Profile actualProfile = await this.profileService + .RemoveProfileByIdAsync(inputProfileId); + + // then + actualProfile.Should().BeEquivalentTo(expectedProfile); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(inputProfileId), + Times.Once()); + + this.storageBrokerMock.Verify(broker => + broker.DeleteProfileAsync(expectedInputProfile), + 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/Profiles/ProfileServiceTests.Logic.RetrieveAll.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.RetrieveAll.cs index f32d7b21..4e3ce52d 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.RetrieveAll.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.RetrieveAll.cs @@ -11,33 +11,33 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public void ShouldRetrieveProfiles() - { - // given - IQueryable randomProfiles = CreatedRandomProfiles(); - IQueryable storageProfiles = randomProfiles; - IQueryable expectedProfiles = storageProfiles; + public partial class ProfileServiceTests + { + [Fact] + private void ShouldRetrieveProfiles() + { + // given + IQueryable randomProfiles = CreatedRandomProfiles(); + IQueryable storageProfiles = randomProfiles; + IQueryable expectedProfiles = storageProfiles; - this.storageBrokerMock.Setup(broker => - broker.SelectAllProfiles()) - .Returns(storageProfiles); + this.storageBrokerMock.Setup(broker => + broker.SelectAllProfiles()) + .Returns(storageProfiles); - // when - IQueryable actualProfiles = - this.profileService.RetrieveAllProfiles(); + // when + IQueryable actualProfiles = + this.profileService.RetrieveAllProfiles(); - // then - actualProfiles.Should().BeEquivalentTo(expectedProfiles); + // then + actualProfiles.Should().BeEquivalentTo(expectedProfiles); - this.storageBrokerMock.Verify(broker => - broker.SelectAllProfiles(), - Times.Once); + this.storageBrokerMock.Verify(broker => + broker.SelectAllProfiles(), + Times.Once); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - } -} + this.storageBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + } + } +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.RetrieveById.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.RetrieveById.cs index 37365f6f..616355bf 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.RetrieveById.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Logic.RetrieveById.cs @@ -11,40 +11,39 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public async void ShouldRetrieveProfileByIdAsync() - { - // given - Profile someProfile = - CreateRandomProfile(); - - Profile storageProfile = - someProfile; - - Profile expectedProfile = - storageProfile.DeepClone(); - - this.storageBrokerMock.Setup(broker => - broker.SelectProfileByIdAsync(someProfile.Id)) - .ReturnsAsync(storageProfile); - - // when - Profile actualProfile = - await this.profileService. - RetrieveProfileByIdAsync(someProfile.Id); - - // then - actualProfile.Should().BeEquivalentTo(expectedProfile); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(someProfile.Id), - Times.Once); - - this.storageBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class ProfileServiceTests + { + [Fact] + private async void ShouldRetrieveProfileByIdAsync() + { + // given + Profile someProfile = + CreateRandomProfile(); + + Profile storageProfile = someProfile; + + Profile expectedProfile = + storageProfile.DeepClone(); + + this.storageBrokerMock.Setup(broker => + broker.SelectProfileByIdAsync(someProfile.Id)) + .ReturnsAsync(storageProfile); + + // when + Profile actualProfile = + await this.profileService. + RetrieveProfileByIdAsync(someProfile.Id); + + // then + actualProfile.Should().BeEquivalentTo(expectedProfile); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(someProfile.Id), + Times.Once); + + this.storageBrokerMock.VerifyNoOtherCalls(); + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + } + } +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.Add.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.Add.cs index 6a2d6fb5..eddf0782 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.Add.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.Add.cs @@ -13,221 +13,229 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public async Task ShouldThrowValidationExceptionOnAddIfProfileIsNullAndLogItAsync() - { - // given - Profile invalidProfile = null; - - var nullProfileException = - new NullProfileException(); - - var expectedProfileValidationException = - new ProfileValidationException(nullProfileException); - - // when - ValueTask addProfileTask = - this.profileService.AddProfileAsync(invalidProfile); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync( - addProfileTask.AsTask); - - // then - actualProfileValidationException.Should().BeEquivalentTo(expectedProfileValidationException); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.InsertProfileAsync(invalidProfile), - Times.Never); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - } - - [Theory] - [InlineData(null)] - [InlineData("")] - [InlineData(" ")] - public async Task ShouldThrowValidationExceptionOnAddIfProfileIsInvalidAndLogItAsync( - string invalidText) - { - // given - var invalidProfile = new Profile - { - Username = invalidText, - Email = invalidText - }; - - var invalidProfileException = - new InvalidProfileException(); - - invalidProfileException.AddData( - key: nameof(Profile.Id), - values: "Id is required"); - - invalidProfileException.AddData( - key: nameof(Profile.Name), - values: "Text is required"); - - invalidProfileException.AddData( - key: nameof(Profile.Username), - values: "Text is required"); - - invalidProfileException.AddData( - key: nameof(Profile.Email), - values: "Text is required"); - - invalidProfileException.AddData( - key: nameof(Profile.CreatedDate), - values: "Date is required"); - - invalidProfileException.AddData( - key: nameof(Profile.UpdatedDate), - values: "Date is required"); - - var expectedProfileValidationException = - new ProfileValidationException(invalidProfileException); - - // when - ValueTask addProfileTask = - this.profileService.AddProfileAsync(invalidProfile); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync( - addProfileTask.AsTask); - - // then - actualProfileValidationException.Should() - .BeEquivalentTo(expectedProfileValidationException); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.InsertProfileAsync(invalidProfile), - Times.Never); - - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowValidationExceptionOnAddIfCreateAndUpdateDatesIsNotSameAndLogItAsync() - { - // given - DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); - int randomNumber = GetRandomNumber(); - Profile randomProfile = CreateRandomProfile(randomDateTime); - Profile invalidProfile = randomProfile; - - invalidProfile.UpdatedDate = - invalidProfile.CreatedDate.AddDays(randomNumber); - - var invalidProfileException = - new InvalidProfileException(); - - invalidProfileException.AddData( - key: nameof(Profile.UpdatedDate), - values: $"Date is not the same as {nameof(Profile.CreatedDate)}"); - - var expectedProfileValidationException = - new ProfileValidationException(invalidProfileException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Returns(randomDateTime); - - // when - ValueTask addProfileTask = - this.profileService.AddProfileAsync(invalidProfile); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync(() => - addProfileTask.AsTask()); - - // then - actualProfileValidationException.Should().BeEquivalentTo(expectedProfileValidationException); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.InsertProfileAsync(It.IsAny()), - Times.Never); - - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - } - - [Theory] - [MemberData(nameof(MinutesBeforeOrAfter))] - public async Task ShouldThrowValidationExceptionOnAddIfCreatedDateIsNotRecentAndLogItAsync( - int minutesBeforeOrAfter) - { - // given - DateTimeOffset randomDateTime = - GetRandomDateTimeOffset(); - - DateTimeOffset invalidDateTime = - randomDateTime.AddMinutes(minutesBeforeOrAfter); - - Profile randomProfile = CreateRandomProfile(invalidDateTime); - Profile invalidProfile = randomProfile; - - var invalidProfileException = - new InvalidProfileException(); - - invalidProfileException.AddData( - key: nameof(Profile.CreatedDate), - values: "Date is not recent"); - - var expectedProfileValidationException = - new ProfileValidationException(invalidProfileException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Returns(randomDateTime); - - // when - ValueTask addProfileTask = - this.profileService.AddProfileAsync(invalidProfile); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync( - addProfileTask.AsTask); - - // then - actualProfileValidationException.Should() - .BeEquivalentTo(expectedProfileValidationException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once()); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.InsertProfileAsync(It.IsAny()), - Times.Never); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class ProfileServiceTests + { + [Fact] + private async Task ShouldThrowValidationExceptionOnAddIfProfileIsNullAndLogItAsync() + { + // given + Profile invalidProfile = null; + + var nullProfileException = + new NullProfileException(); + + var expectedProfileValidationException = + new ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: nullProfileException); + + // when + ValueTask addProfileTask = + this.profileService.AddProfileAsync(invalidProfile); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync( + addProfileTask.AsTask); + + // then + actualProfileValidationException.Should().BeEquivalentTo(expectedProfileValidationException); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.InsertProfileAsync(invalidProfile), + Times.Never); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" ")] + private async Task ShouldThrowValidationExceptionOnAddIfProfileIsInvalidAndLogItAsync( + string invalidText) + { + // given + var invalidProfile = new Profile + { + Username = invalidText, + Email = invalidText + }; + + var invalidProfileException = + new InvalidProfileException(); + + invalidProfileException.AddData( + key: nameof(Profile.Id), + values: "Id is required"); + + invalidProfileException.AddData( + key: nameof(Profile.Name), + values: "Text is required"); + + invalidProfileException.AddData( + key: nameof(Profile.Username), + values: "Text is required"); + + invalidProfileException.AddData( + key: nameof(Profile.Email), + values: "Text is required"); + + invalidProfileException.AddData( + key: nameof(Profile.CreatedDate), + values: "Date is required"); + + invalidProfileException.AddData( + key: nameof(Profile.UpdatedDate), + values: "Date is required"); + + var expectedProfileValidationException = + new ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: invalidProfileException); + + // when + ValueTask addProfileTask = + this.profileService.AddProfileAsync(invalidProfile); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync( + addProfileTask.AsTask); + + // then + actualProfileValidationException.Should() + .BeEquivalentTo(expectedProfileValidationException); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.InsertProfileAsync(invalidProfile), + Times.Never); + + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowValidationExceptionOnAddIfCreateAndUpdateDatesIsNotSameAndLogItAsync() + { + // given + DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); + int randomNumber = GetRandomNumber(); + Profile randomProfile = CreateRandomProfile(randomDateTime); + Profile invalidProfile = randomProfile; + + invalidProfile.UpdatedDate = + invalidProfile.CreatedDate.AddDays(randomNumber); + + var invalidProfileException = + new InvalidProfileException(); + + invalidProfileException.AddData( + key: nameof(Profile.UpdatedDate), + values: $"Date is not the same as {nameof(Profile.CreatedDate)}"); + + var expectedProfileValidationException = + new ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: invalidProfileException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Returns(randomDateTime); + + // when + ValueTask addProfileTask = + this.profileService.AddProfileAsync(invalidProfile); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync(() => + addProfileTask.AsTask()); + + // then + actualProfileValidationException.Should().BeEquivalentTo(expectedProfileValidationException); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.InsertProfileAsync(It.IsAny()), + Times.Never); + + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + } + + [Theory] + [MemberData(nameof(MinutesBeforeOrAfter))] + private async Task ShouldThrowValidationExceptionOnAddIfCreatedDateIsNotRecentAndLogItAsync( + int minutesBeforeOrAfter) + { + // given + DateTimeOffset randomDateTime = + GetRandomDateTimeOffset(); + + DateTimeOffset invalidDateTime = + randomDateTime.AddMinutes(minutesBeforeOrAfter); + + Profile randomProfile = CreateRandomProfile(invalidDateTime); + Profile invalidProfile = randomProfile; + + var invalidProfileException = + new InvalidProfileException(); + + invalidProfileException.AddData( + key: nameof(Profile.CreatedDate), + values: "Date is not recent"); + + var expectedProfileValidationException = + new ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: invalidProfileException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Returns(randomDateTime); + + // when + ValueTask addProfileTask = + this.profileService.AddProfileAsync(invalidProfile); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync( + addProfileTask.AsTask); + + // then + actualProfileValidationException.Should() + .BeEquivalentTo(expectedProfileValidationException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once()); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.InsertProfileAsync(It.IsAny()), + Times.Never); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + } + } +} \ No newline at end of file diff --git a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.Modify.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.Modify.cs index 6c33f079..612a4757 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.Modify.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.Modify.cs @@ -13,291 +13,301 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public async Task ShouldThrowValidationExceptionOnModifyIfProfileIsNullAndLogItAsync() - { - // given - Profile nullProfile = null; - var nullProfileException = new NullProfileException(); - - var expectedProfileValidationException = - new ProfileValidationException(nullProfileException); - - // when - ValueTask modifyProfileTask = - this.profileService.ModifyProfileAsync(nullProfile); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync( - modifyProfileTask.AsTask); - - // then - actualProfileValidationException.Should() - .BeEquivalentTo(expectedProfileValidationException); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(It.IsAny()), - Times.Never); - - this.storageBrokerMock.Verify(broker => - broker.UpdateProfileAsync(It.IsAny()), - Times.Never); - - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - } - - [Theory] - [InlineData(null)] - [InlineData("")] - [InlineData(" ")] - public async Task ShouldThrowValidationExceptionOnModifyIfProfileIsInvalidAndLogItAsync(string invalidText) - { - // given - var invalidProfile = new Profile - { - Username = invalidText - }; - - var invalidProfileException = - new InvalidProfileException(); - - invalidProfileException.AddData( - key: nameof(Profile.Id), - values: "Id is required"); - - invalidProfileException.AddData( - key: nameof(Profile.Name), - values: "Text is required"); - - invalidProfileException.AddData( - key: nameof(Profile.Username), - values: "Text is required"); - - invalidProfileException.AddData( - key: nameof(Profile.Email), - values: "Text is required"); - - invalidProfileException.AddData( - key: nameof(Profile.CreatedDate), - values: "Date is required"); - - invalidProfileException.AddData( - key: nameof(Profile.UpdatedDate), - values: new[] - { - "Date is required", - $"Date is the same as {nameof(Profile.CreatedDate)}", - "Date is not recent" - } - ); - - var expectedProfileValidationException = - new ProfileValidationException(invalidProfileException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Returns(GetRandomDateTime); - - // when - ValueTask modifyProfileTask = - this.profileService.ModifyProfileAsync(invalidProfile); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync( - modifyProfileTask.AsTask); - - //then - actualProfileValidationException.Should() - .BeEquivalentTo(expectedProfileValidationException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.UpdateProfileAsync(It.IsAny()), - Times.Never); - - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowValidationExceptionOnModifyIfUpdatedDateIsNotSameAsCreatedDateAndLogItAsync() - { - // given - DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); - Profile randomProfile = CreateRandomProfile(randomDateTime); - Profile invalidProfile = randomProfile; - var invalidProfileException = new InvalidProfileException(); - - invalidProfileException.AddData( - key: nameof(Profile.UpdatedDate), - values: $"Date is the same as {nameof(Profile.CreatedDate)}"); - - var expectedProfileValidationException = - new ProfileValidationException(invalidProfileException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Returns(randomDateTime); - - // when - ValueTask modifyProfileTask = - this.profileService.ModifyProfileAsync(invalidProfile); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync( - modifyProfileTask.AsTask); - - // then - actualProfileValidationException.Should() - .BeEquivalentTo(expectedProfileValidationException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(invalidProfile.Id), - Times.Never); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - } - - [Theory] - [MemberData(nameof(MinutesBeforeOrAfter))] - public async Task ShouldThrowValidationExceptionOnModifyIfUpdatedDateIsNotRecentAndLogItAsync(int minutes) - { - // given - DateTimeOffset dateTime = GetRandomDateTimeOffset(); - Profile randomProfile = CreateRandomProfile(dateTime); - Profile inputProfile = randomProfile; - inputProfile.UpdatedDate = dateTime.AddMinutes(minutes); - - var invalidProfileException = - new InvalidProfileException(); - - invalidProfileException.AddData( - key: nameof(Profile.UpdatedDate), - values: "Date is not recent"); - - var expectedProfileValidatonException = - new ProfileValidationException(invalidProfileException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Returns(dateTime); - - // when - ValueTask modifyProfileTask = - this.profileService.ModifyProfileAsync(inputProfile); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync( - modifyProfileTask.AsTask); - - // then - actualProfileValidationException.Should() - .BeEquivalentTo(expectedProfileValidatonException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidatonException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(It.IsAny()), - Times.Never); - - this.storageBrokerMock.Verify(broker => - broker.UpdateProfileAsync(It.IsAny()), - Times.Never); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowValidationExceptionOnModifyIfProfileDoesNotExistAndLogItAsync() - { - // given - int randomNegativeMinutes = GetRandomNegativeNumber(); - DateTimeOffset dateTime = GetRandomDateTimeOffset(); - Profile randomProfile = CreateRandomProfile(dateTime); - Profile nonExistProfile = randomProfile; - nonExistProfile.CreatedDate = dateTime.AddMinutes(randomNegativeMinutes); - Profile nullProfile = null; - - var notFoundProfileException = - new NotFoundProfileException(nonExistProfile.Id); - - var expectedProfileValidationException = - new ProfileValidationException(notFoundProfileException); - - this.dateTimeBrokerMock.Setup(broker => - broker.GetCurrentDateTimeOffset()) - .Returns(dateTime); - - this.storageBrokerMock.Setup(broker => - broker.SelectProfileByIdAsync(nonExistProfile.Id)) - .ReturnsAsync(nullProfile); - - // when - ValueTask modifyProfileTask = - this.profileService.ModifyProfileAsync(nonExistProfile); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync( - modifyProfileTask.AsTask); - - // then - actualProfileValidationException.Should() - .BeEquivalentTo(expectedProfileValidationException); - - this.dateTimeBrokerMock.Verify(broker => - broker.GetCurrentDateTimeOffset(), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(nonExistProfile.Id), - Times.Once); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidationException))), - Times.Once); - - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class ProfileServiceTests + { + [Fact] + private async Task ShouldThrowValidationExceptionOnModifyIfProfileIsNullAndLogItAsync() + { + // given + Profile nullProfile = null; + var nullProfileException = new NullProfileException(); + + var expectedProfileValidationException = + new ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: nullProfileException); + + // when + ValueTask modifyProfileTask = + this.profileService.ModifyProfileAsync(nullProfile); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync( + modifyProfileTask.AsTask); + + // then + actualProfileValidationException.Should() + .BeEquivalentTo(expectedProfileValidationException); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(It.IsAny()), + Times.Never); + + this.storageBrokerMock.Verify(broker => + broker.UpdateProfileAsync(It.IsAny()), + Times.Never); + + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" ")] + private async Task ShouldThrowValidationExceptionOnModifyIfProfileIsInvalidAndLogItAsync(string invalidText) + { + // given + var invalidProfile = new Profile + { + Username = invalidText + }; + + var invalidProfileException = + new InvalidProfileException(); + + invalidProfileException.AddData( + key: nameof(Profile.Id), + values: "Id is required"); + + invalidProfileException.AddData( + key: nameof(Profile.Name), + values: "Text is required"); + + invalidProfileException.AddData( + key: nameof(Profile.Username), + values: "Text is required"); + + invalidProfileException.AddData( + key: nameof(Profile.Email), + values: "Text is required"); + + invalidProfileException.AddData( + key: nameof(Profile.CreatedDate), + values: "Date is required"); + + invalidProfileException.AddData( + key: nameof(Profile.UpdatedDate), + values: new[] + { + "Date is required", + $"Date is the same as {nameof(Profile.CreatedDate)}", + "Date is not recent" + } + ); + + var expectedProfileValidationException = + new ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: invalidProfileException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Returns(GetRandomDateTime); + + // when + ValueTask modifyProfileTask = + this.profileService.ModifyProfileAsync(invalidProfile); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync( + modifyProfileTask.AsTask); + + //then + actualProfileValidationException.Should() + .BeEquivalentTo(expectedProfileValidationException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.UpdateProfileAsync(It.IsAny()), + Times.Never); + + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowValidationExceptionOnModifyIfUpdatedDateIsNotSameAsCreatedDateAndLogItAsync() + { + // given + DateTimeOffset randomDateTime = GetRandomDateTimeOffset(); + Profile randomProfile = CreateRandomProfile(randomDateTime); + Profile invalidProfile = randomProfile; + var invalidProfileException = new InvalidProfileException(); + + invalidProfileException.AddData( + key: nameof(Profile.UpdatedDate), + values: $"Date is the same as {nameof(Profile.CreatedDate)}"); + + var expectedProfileValidationException = + new ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: invalidProfileException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Returns(randomDateTime); + + // when + ValueTask modifyProfileTask = + this.profileService.ModifyProfileAsync(invalidProfile); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync( + modifyProfileTask.AsTask); + + // then + actualProfileValidationException.Should() + .BeEquivalentTo(expectedProfileValidationException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(invalidProfile.Id), + Times.Never); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + } + + [Theory] + [MemberData(nameof(MinutesBeforeOrAfter))] + private async Task ShouldThrowValidationExceptionOnModifyIfUpdatedDateIsNotRecentAndLogItAsync(int minutes) + { + // given + DateTimeOffset dateTime = GetRandomDateTimeOffset(); + Profile randomProfile = CreateRandomProfile(dateTime); + Profile inputProfile = randomProfile; + inputProfile.UpdatedDate = dateTime.AddMinutes(minutes); + + var invalidProfileException = + new InvalidProfileException(); + + invalidProfileException.AddData( + key: nameof(Profile.UpdatedDate), + values: "Date is not recent"); + + var expectedProfileValidatonException = + new ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: invalidProfileException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Returns(dateTime); + + // when + ValueTask modifyProfileTask = + this.profileService.ModifyProfileAsync(inputProfile); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync( + modifyProfileTask.AsTask); + + // then + actualProfileValidationException.Should() + .BeEquivalentTo(expectedProfileValidatonException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidatonException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(It.IsAny()), + Times.Never); + + this.storageBrokerMock.Verify(broker => + broker.UpdateProfileAsync(It.IsAny()), + Times.Never); + + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowValidationExceptionOnModifyIfProfileDoesNotExistAndLogItAsync() + { + // given + int randomNegativeMinutes = GetRandomNegativeNumber(); + DateTimeOffset dateTime = GetRandomDateTimeOffset(); + Profile randomProfile = CreateRandomProfile(dateTime); + Profile nonExistProfile = randomProfile; + nonExistProfile.CreatedDate = dateTime.AddMinutes(randomNegativeMinutes); + Profile nullProfile = null; + + var notFoundProfileException = + new NotFoundProfileException(nonExistProfile.Id); + + var expectedProfileValidationException = + new ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: notFoundProfileException); + + this.dateTimeBrokerMock.Setup(broker => + broker.GetCurrentDateTimeOffset()) + .Returns(dateTime); + + this.storageBrokerMock.Setup(broker => + broker.SelectProfileByIdAsync(nonExistProfile.Id)) + .ReturnsAsync(nullProfile); + + // when + ValueTask modifyProfileTask = + this.profileService.ModifyProfileAsync(nonExistProfile); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync( + modifyProfileTask.AsTask); + + // then + actualProfileValidationException.Should() + .BeEquivalentTo(expectedProfileValidationException); + + this.dateTimeBrokerMock.Verify(broker => + broker.GetCurrentDateTimeOffset(), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(nonExistProfile.Id), + Times.Once); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidationException))), + 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/Profiles/ProfileServiceTests.Validations.RemoveById.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.RemoveById.cs index 089549df..d65d11a2 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.RemoveById.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.RemoveById.cs @@ -13,95 +13,99 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public async Task ShouldThrowValidationExceptionOnRemoveIfIdIsInvalidAndLogItAsync() - { - // given - Guid invalidProfileId = Guid.Empty; - - var invalidProfileException = - new InvalidProfileException(); - - invalidProfileException.AddData( - key: nameof(Profile.Id), - values: "Id is required"); - - var expectedProfileValidationException = - new ProfileValidationException(invalidProfileException); - - // when - ValueTask removeProfileByIdTask = - this.profileService.RemoveProfileByIdAsync(invalidProfileId); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync(() => - removeProfileByIdTask.AsTask()); - - // then - actualProfileValidationException.Should() - .BeEquivalentTo(expectedProfileValidationException); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(It.IsAny()), - Times.Never); - - this.storageBrokerMock.Verify(broker => - broker.DeleteProfileAsync(It.IsAny()), - Times.Never); - } - - [Fact] - public async Task ShouldThrowNotFoundExceptionOnRemoveProfileByIdIsNotFounfAndLogItAsync() - { - // given - Guid inputProfileId = Guid.NewGuid(); - Profile noProfile = null; - - var notFoundProfileException = - new NotFoundProfileException(inputProfileId); - - var expectedProfileValidationException = - new ProfileValidationException(notFoundProfileException); - - this.storageBrokerMock.Setup(broker => - broker.SelectProfileByIdAsync(It.IsAny())) - .ReturnsAsync(noProfile); - - // when - ValueTask removeProfileByIdTask = - this.profileService.RemoveProfileByIdAsync(inputProfileId); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync(() => - removeProfileByIdTask.AsTask()); - - // then - actualProfileValidationException.Should() - .BeEquivalentTo(expectedProfileValidationException); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(It.IsAny()), - Times.Once); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.DeleteProfileAsync(It.IsAny()), - Times.Never); - - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class ProfileServiceTests + { + [Fact] + private async Task ShouldThrowValidationExceptionOnRemoveIfIdIsInvalidAndLogItAsync() + { + // given + Guid invalidProfileId = Guid.Empty; + + var invalidProfileException = + new InvalidProfileException(); + + invalidProfileException.AddData( + key: nameof(Profile.Id), + values: "Id is required"); + + var expectedProfileValidationException = + new ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: invalidProfileException); + + // when + ValueTask removeProfileByIdTask = + this.profileService.RemoveProfileByIdAsync(invalidProfileId); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync(() => + removeProfileByIdTask.AsTask()); + + // then + actualProfileValidationException.Should() + .BeEquivalentTo(expectedProfileValidationException); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(It.IsAny()), + Times.Never); + + this.storageBrokerMock.Verify(broker => + broker.DeleteProfileAsync(It.IsAny()), + Times.Never); + } + + [Fact] + private async Task ShouldThrowNotFoundExceptionOnRemoveProfileByIdIsNotFounfAndLogItAsync() + { + // given + Guid inputProfileId = Guid.NewGuid(); + Profile noProfile = null; + + var notFoundProfileException = + new NotFoundProfileException(inputProfileId); + + var expectedProfileValidationException = + new ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: notFoundProfileException); + + this.storageBrokerMock.Setup(broker => + broker.SelectProfileByIdAsync(It.IsAny())) + .ReturnsAsync(noProfile); + + // when + ValueTask removeProfileByIdTask = + this.profileService.RemoveProfileByIdAsync(inputProfileId); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync(() => + removeProfileByIdTask.AsTask()); + + // then + actualProfileValidationException.Should() + .BeEquivalentTo(expectedProfileValidationException); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(It.IsAny()), + Times.Once); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.DeleteProfileAsync(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/Profiles/ProfileServiceTests.Validations.RetrieveById.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.RetrieveById.cs index 5c624f9a..aa4fb1af 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.RetrieveById.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.Validations.RetrieveById.cs @@ -13,89 +13,93 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Profiles { - public partial class ProfileServiceTests - { - [Fact] - public async Task ShouldThrowValidationExceptionOnRetrieveByIdIfIdIsInvalidAndLogItAsync() - { - // given - var invalidProfileId = Guid.Empty; - - var invalidProfileException = - new InvalidProfileException(); - - invalidProfileException.AddData( - key: nameof(Profile.Id), - values: "Id is required"); - - var expectedProfileValidationException = new - ProfileValidationException(invalidProfileException); - - // when - ValueTask retrieveProfileByIdTask = - this.profileService.RetrieveProfileByIdAsync(invalidProfileId); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync( - retrieveProfileByIdTask.AsTask); - - // then - actualProfileValidationException.Should().BeEquivalentTo(expectedProfileValidationException); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidationException))), - Times.Once); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(It.IsAny()), - Times.Never); - - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.storageBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - } - - [Fact] - public async Task ShouldThrowNotFoundExceptionOnRetrieveByIdIfProfileIsNotFoundAndLogItAsync() - { - //given - Guid someProfileId = Guid.NewGuid(); - Profile noProfile = null; - - var notFoundProfileException = - new NotFoundProfileException(someProfileId); - - var expectedProfileValidationException = - new ProfileValidationException(notFoundProfileException); - - this.storageBrokerMock.Setup(broker => - broker.SelectProfileByIdAsync(It.IsAny())) - .ReturnsAsync(noProfile); - - //when - ValueTask retrieveProfileByIdTask = - this.profileService.RetrieveProfileByIdAsync(someProfileId); - - ProfileValidationException actualProfileValidationException = - await Assert.ThrowsAsync( - retrieveProfileByIdTask.AsTask); - - // then - actualProfileValidationException.Should().BeEquivalentTo(expectedProfileValidationException); - - this.storageBrokerMock.Verify(broker => - broker.SelectProfileByIdAsync(It.IsAny()), - Times.Once()); - - this.loggingBrokerMock.Verify(broker => - broker.LogError(It.Is(SameExceptionAs( - expectedProfileValidationException))), - Times.Once); - - this.storageBrokerMock.VerifyNoOtherCalls(); - this.loggingBrokerMock.VerifyNoOtherCalls(); - this.dateTimeBrokerMock.VerifyNoOtherCalls(); - } - } -} + public partial class ProfileServiceTests + { + [Fact] + private async Task ShouldThrowValidationExceptionOnRetrieveByIdIfIdIsInvalidAndLogItAsync() + { + // given + var invalidProfileId = Guid.Empty; + + var invalidProfileException = + new InvalidProfileException(); + + invalidProfileException.AddData( + key: nameof(Profile.Id), + values: "Id is required"); + + var expectedProfileValidationException = new + ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: invalidProfileException); + + // when + ValueTask retrieveProfileByIdTask = + this.profileService.RetrieveProfileByIdAsync(invalidProfileId); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync( + retrieveProfileByIdTask.AsTask); + + // then + actualProfileValidationException.Should().BeEquivalentTo(expectedProfileValidationException); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidationException))), + Times.Once); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(It.IsAny()), + Times.Never); + + this.loggingBrokerMock.VerifyNoOtherCalls(); + this.storageBrokerMock.VerifyNoOtherCalls(); + this.dateTimeBrokerMock.VerifyNoOtherCalls(); + } + + [Fact] + private async Task ShouldThrowNotFoundExceptionOnRetrieveByIdIfProfileIsNotFoundAndLogItAsync() + { + //given + Guid someProfileId = Guid.NewGuid(); + Profile noProfile = null; + + var notFoundProfileException = + new NotFoundProfileException(someProfileId); + + var expectedProfileValidationException = + new ProfileValidationException( + message: "Profile validation errors occurred, please try again.", + innerException: notFoundProfileException); + + this.storageBrokerMock.Setup(broker => + broker.SelectProfileByIdAsync(It.IsAny())) + .ReturnsAsync(noProfile); + + //when + ValueTask retrieveProfileByIdTask = + this.profileService.RetrieveProfileByIdAsync(someProfileId); + + ProfileValidationException actualProfileValidationException = + await Assert.ThrowsAsync( + retrieveProfileByIdTask.AsTask); + + // then + actualProfileValidationException.Should().BeEquivalentTo(expectedProfileValidationException); + + this.storageBrokerMock.Verify(broker => + broker.SelectProfileByIdAsync(It.IsAny()), + Times.Once()); + + this.loggingBrokerMock.Verify(broker => + broker.LogError(It.Is(SameExceptionAs( + expectedProfileValidationException))), + 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/Profiles/ProfileServiceTests.cs b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.cs index f72689e4..fd87c722 100644 --- a/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.cs +++ b/Taarafo.Core.Tests.Unit/Services/Foundations/Profiles/ProfileServiceTests.cs @@ -94,4 +94,4 @@ private static Filler CreateProfileFiller(DateTimeOffset dates) return filler; } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Models/Profiles/Exceptions/AlreadyExistsProfileException.cs b/Taarafo.Core/Models/Profiles/Exceptions/AlreadyExistsProfileException.cs index b37c8e26..da99ab77 100644 --- a/Taarafo.Core/Models/Profiles/Exceptions/AlreadyExistsProfileException.cs +++ b/Taarafo.Core/Models/Profiles/Exceptions/AlreadyExistsProfileException.cs @@ -11,7 +11,13 @@ namespace Taarafo.Core.Models.Profiles.Exceptions public class AlreadyExistsProfileException : Xeption { public AlreadyExistsProfileException(Exception innerException) - : base(message: "Profile with the same id already exists.", innerException) + : base( + message: "Profile with the same id already exists.", + innerException: innerException) + { } + + public AlreadyExistsProfileException(string message, Exception innerException) + : base(message, innerException) { } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Models/Profiles/Exceptions/FailedProfileServiceException.cs b/Taarafo.Core/Models/Profiles/Exceptions/FailedProfileServiceException.cs index a889ca93..261f0436 100644 --- a/Taarafo.Core/Models/Profiles/Exceptions/FailedProfileServiceException.cs +++ b/Taarafo.Core/Models/Profiles/Exceptions/FailedProfileServiceException.cs @@ -11,7 +11,13 @@ namespace Taarafo.Core.Models.Profiles.Exceptions public class FailedProfileServiceException : Xeption { public FailedProfileServiceException(Exception innerException) - : base(message: "Failed profile service occurred, please contact support", innerException) + : base( + message: "Failed profile service occurred, please contact support", + innerException: innerException) + { } + + public FailedProfileServiceException(string message, Exception innerException) + : base(message, innerException) { } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Models/Profiles/Exceptions/FailedProfileStorageException.cs b/Taarafo.Core/Models/Profiles/Exceptions/FailedProfileStorageException.cs index 9b92f0b6..db75213f 100644 --- a/Taarafo.Core/Models/Profiles/Exceptions/FailedProfileStorageException.cs +++ b/Taarafo.Core/Models/Profiles/Exceptions/FailedProfileStorageException.cs @@ -11,7 +11,13 @@ namespace Taarafo.Core.Models.Profiles.Exceptions public class FailedProfileStorageException : Xeption { public FailedProfileStorageException(Exception innerException) - : base(message: "Failed profile storage error occurred, contact support.", innerException) + : base( + message: "Failed profile storage error occurred, contact support.", + innerException: innerException) + { } + + public FailedProfileStorageException(string message, Exception innerException) + : base(message, innerException) { } } } diff --git a/Taarafo.Core/Models/Profiles/Exceptions/InvalidProfileException.cs b/Taarafo.Core/Models/Profiles/Exceptions/InvalidProfileException.cs index df6addfd..fd588aaa 100644 --- a/Taarafo.Core/Models/Profiles/Exceptions/InvalidProfileException.cs +++ b/Taarafo.Core/Models/Profiles/Exceptions/InvalidProfileException.cs @@ -3,6 +3,7 @@ // FREE TO USE TO CONNECT THE WORLD // --------------------------------------------------------------- +using System; using Xeptions; namespace Taarafo.Core.Models.Profiles.Exceptions @@ -10,7 +11,12 @@ namespace Taarafo.Core.Models.Profiles.Exceptions public class InvalidProfileException : Xeption { public InvalidProfileException() - : base(message: "Invalid profile. Please correct the errors and try again.") + : base( + message: "Invalid profile. Please correct the errors and try again.") + { } + + public InvalidProfileException(string message, Exception innerException) + : base(message, innerException) { } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Models/Profiles/Exceptions/InvalidProfileReferenceException.cs b/Taarafo.Core/Models/Profiles/Exceptions/InvalidProfileReferenceException.cs index 9f170d92..2233d153 100644 --- a/Taarafo.Core/Models/Profiles/Exceptions/InvalidProfileReferenceException.cs +++ b/Taarafo.Core/Models/Profiles/Exceptions/InvalidProfileReferenceException.cs @@ -11,7 +11,13 @@ namespace Taarafo.Core.Models.Profiles.Exceptions public class InvalidProfileReferenceException : Xeption { public InvalidProfileReferenceException(Exception innerException) - : base(message: "Invalid profile reference error occurred.", innerException) + : base( + message: "Invalid profile reference error occurred.", + innerException: innerException) + { } + + public InvalidProfileReferenceException(string message, Exception innerException) + : base(message, innerException) { } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Models/Profiles/Exceptions/LockedProfileException.cs b/Taarafo.Core/Models/Profiles/Exceptions/LockedProfileException.cs index 7ddae117..4ef9eb79 100644 --- a/Taarafo.Core/Models/Profiles/Exceptions/LockedProfileException.cs +++ b/Taarafo.Core/Models/Profiles/Exceptions/LockedProfileException.cs @@ -11,7 +11,13 @@ namespace Taarafo.Core.Models.Profiles.Exceptions public class LockedProfileException : Xeption { public LockedProfileException(Exception innerException) - : base(message: "Locked profile record exception, please try again later", innerException) + : base( + message: "Locked profile record exception, please try again later", + innerException: innerException) + { } + + public LockedProfileException(string message, Exception innerException) + : base(message, innerException) { } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Models/Profiles/Exceptions/NotFoundProfileException.cs b/Taarafo.Core/Models/Profiles/Exceptions/NotFoundProfileException.cs index c7e1a343..30c24035 100644 --- a/Taarafo.Core/Models/Profiles/Exceptions/NotFoundProfileException.cs +++ b/Taarafo.Core/Models/Profiles/Exceptions/NotFoundProfileException.cs @@ -13,5 +13,9 @@ public class NotFoundProfileException : Xeption public NotFoundProfileException(Guid profileId) : base(message: $"Couldn't find profile with id: {profileId}.") { } + + public NotFoundProfileException(string message, Exception innerException) + : base(message, innerException) + { } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Models/Profiles/Exceptions/NullProfileException.cs b/Taarafo.Core/Models/Profiles/Exceptions/NullProfileException.cs index 13b2ca8d..1abe4887 100644 --- a/Taarafo.Core/Models/Profiles/Exceptions/NullProfileException.cs +++ b/Taarafo.Core/Models/Profiles/Exceptions/NullProfileException.cs @@ -3,14 +3,19 @@ // FREE TO USE TO CONNECT THE WORLD // --------------------------------------------------------------- +using System; using Xeptions; namespace Taarafo.Core.Models.Profiles.Exceptions { - public class NullProfileException : Xeption - { - public NullProfileException() - : base(message: "Profile is null.") - { } - } -} + public class NullProfileException : Xeption + { + public NullProfileException() + : base(message: "Profile is null.") + { } + + public NullProfileException(string message, Exception innerException) + : base(message, innerException) + { } + } +} \ No newline at end of file diff --git a/Taarafo.Core/Models/Profiles/Exceptions/ProfileDependencyException.cs b/Taarafo.Core/Models/Profiles/Exceptions/ProfileDependencyException.cs index e84c7170..c9a8ff4c 100644 --- a/Taarafo.Core/Models/Profiles/Exceptions/ProfileDependencyException.cs +++ b/Taarafo.Core/Models/Profiles/Exceptions/ProfileDependencyException.cs @@ -7,10 +7,16 @@ namespace Taarafo.Core.Models.Profiles.Exceptions { - public class ProfileDependencyException : Xeption - { - public ProfileDependencyException(Xeption innerException) - : base(message: "Profile dependency error occurred, contact support.", innerException) - { } - } -} + public class ProfileDependencyException : Xeption + { + public ProfileDependencyException(Xeption innerException) + : base( + message: "Profile dependency error occurred, contact support.", + innerException: innerException) + { } + + public ProfileDependencyException(string message, Xeption innerException) + : base(message, innerException) + { } + } +} \ No newline at end of file diff --git a/Taarafo.Core/Models/Profiles/Exceptions/ProfileDependencyValidationException.cs b/Taarafo.Core/Models/Profiles/Exceptions/ProfileDependencyValidationException.cs index 02053271..627c4b75 100644 --- a/Taarafo.Core/Models/Profiles/Exceptions/ProfileDependencyValidationException.cs +++ b/Taarafo.Core/Models/Profiles/Exceptions/ProfileDependencyValidationException.cs @@ -7,10 +7,16 @@ namespace Taarafo.Core.Models.Profiles.Exceptions { - public class ProfileDependencyValidationException : Xeption - { - public ProfileDependencyValidationException(Xeption innerException) - : base(message: "Profile dependency validation occurred, please try again.", innerException) - { } - } -} + public class ProfileDependencyValidationException : Xeption + { + public ProfileDependencyValidationException(Xeption innerException) + : base( + message: "Profile dependency validation occurred, please try again.", + innerException: innerException) + { } + + public ProfileDependencyValidationException(string message, Xeption innerException) + : base(message, innerException) + { } + } +} \ No newline at end of file diff --git a/Taarafo.Core/Models/Profiles/Exceptions/ProfileServiceException.cs b/Taarafo.Core/Models/Profiles/Exceptions/ProfileServiceException.cs index ac4bab0d..63123620 100644 --- a/Taarafo.Core/Models/Profiles/Exceptions/ProfileServiceException.cs +++ b/Taarafo.Core/Models/Profiles/Exceptions/ProfileServiceException.cs @@ -11,7 +11,13 @@ namespace Taarafo.Core.Models.Profiles.Exceptions public class ProfileServiceException : Xeption { public ProfileServiceException(Exception innerException) - : base(message: "Profile service error occurred, contact support.", innerException) + : base( + message: "Profile service error occurred, contact support.", + innerException: innerException) + { } + + public ProfileServiceException(string message, Exception innerException) + : base(message, innerException) { } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Models/Profiles/Exceptions/ProfileValidationException.cs b/Taarafo.Core/Models/Profiles/Exceptions/ProfileValidationException.cs index b977190d..91767c9c 100644 --- a/Taarafo.Core/Models/Profiles/Exceptions/ProfileValidationException.cs +++ b/Taarafo.Core/Models/Profiles/Exceptions/ProfileValidationException.cs @@ -10,8 +10,13 @@ namespace Taarafo.Core.Models.Profiles.Exceptions public class ProfileValidationException : Xeption { public ProfileValidationException(Xeption innerException) - : base(message: "Profile validation errors occurred, please try again.", - innerException) + : base( + message: "Profile validation errors occurred, please try again.", + innerException: innerException) + { } + + public ProfileValidationException(string message, Xeption innerException) + : base(message, innerException) { } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Services/Foundations/Profiles/ProfileService.Exceptions.cs b/Taarafo.Core/Services/Foundations/Profiles/ProfileService.Exceptions.cs index ab626d5f..792fbe6a 100644 --- a/Taarafo.Core/Services/Foundations/Profiles/ProfileService.Exceptions.cs +++ b/Taarafo.Core/Services/Foundations/Profiles/ProfileService.Exceptions.cs @@ -156,4 +156,4 @@ private ProfileServiceException CreateAndLogServiceException(Xeption exception) return profileServiceException; } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Services/Foundations/Profiles/ProfileService.Validations.cs b/Taarafo.Core/Services/Foundations/Profiles/ProfileService.Validations.cs index 21f81114..afd24410 100644 --- a/Taarafo.Core/Services/Foundations/Profiles/ProfileService.Validations.cs +++ b/Taarafo.Core/Services/Foundations/Profiles/ProfileService.Validations.cs @@ -143,4 +143,4 @@ private static void Validate(params (dynamic Rule, string Parameter)[] validatio invalidProfileException.ThrowIfContainsErrors(); } } -} +} \ No newline at end of file diff --git a/Taarafo.Core/Services/Foundations/Profiles/ProfileService.cs b/Taarafo.Core/Services/Foundations/Profiles/ProfileService.cs index fdcf3c90..ffe8197d 100644 --- a/Taarafo.Core/Services/Foundations/Profiles/ProfileService.cs +++ b/Taarafo.Core/Services/Foundations/Profiles/ProfileService.cs @@ -83,4 +83,4 @@ public ValueTask RemoveProfileByIdAsync(Guid profileId) => return await this.storageBroker.DeleteProfileAsync(someProfile); }); } -} +} \ No newline at end of file