Skip to content

Commit

Permalink
CODE RUB: Profiles Exceptions Upgrade v2.10.0
Browse files Browse the repository at this point in the history
Closes: #513
  • Loading branch information
glhays committed Sep 8, 2023
1 parent 7302783 commit 45d1f78
Show file tree
Hide file tree
Showing 30 changed files with 1,708 additions and 1,550 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ 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();
Profile someProfile = CreateRandomProfile(randomDateTime);
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())
Expand Down Expand Up @@ -67,7 +71,7 @@ await Assert.ThrowsAsync<ProfileDependencyException>(
}

[Fact]
public async Task ShouldThrowDependencyValidationExceptionOnAddIfProfileAlreadyExsitsAndLogItAsync()
private async Task ShouldThrowDependencyValidationExceptionOnAddIfProfileAlreadyExsitsAndLogItAsync()
{
// given
Profile randomProfile = CreateRandomProfile();
Expand All @@ -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())
Expand Down Expand Up @@ -118,7 +126,7 @@ await Assert.ThrowsAsync<ProfileDependencyValidationException>(
}

[Fact]
public async void ShouldThrowValidationExceptionOnAddIfReferenceErrorOccursAndLogItAsync()
private async void ShouldThrowValidationExceptionOnAddIfReferenceErrorOccursAndLogItAsync()
{
// given
Profile someProfile = CreateRandomProfile();
Expand All @@ -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())
Expand Down Expand Up @@ -169,7 +181,7 @@ await Assert.ThrowsAsync<ProfileDependencyValidationException>(
}

[Fact]
public async Task ShouldThrowDependencyExceptionOnAddIfDatabaseUpdateErrorOccursAndLogItAsync()
private async Task ShouldThrowDependencyExceptionOnAddIfDatabaseUpdateErrorOccursAndLogItAsync()
{
// given
Profile someProfile = CreateRandomProfile();
Expand All @@ -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())
Expand Down Expand Up @@ -218,17 +234,21 @@ await Assert.ThrowsAsync<ProfileDependencyException>(
}

[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())
Expand Down Expand Up @@ -264,4 +284,4 @@ await Assert.ThrowsAsync<ProfileServiceException>(
this.loggingBrokerMock.VerifyNoOtherCalls();
}
}
}
}
Loading

0 comments on commit 45d1f78

Please sign in to comment.