Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CODE RUB: Profiles Exceptions Upgrade v2.10.0 #518

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading