Skip to content

Commit

Permalink
CODE RUB: GroupPosts Exceptions Upgrade v2.10.0
Browse files Browse the repository at this point in the history
Closes: #508
  • Loading branch information
glhays committed Sep 9, 2023
1 parent 7302783 commit 62ca0f1
Show file tree
Hide file tree
Showing 32 changed files with 282 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.GroupPosts
public partial class GroupPostServiceTests
{
[Fact]
public async Task ShouldThrowDependencyValidationOnRemoveIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync()
private async Task ShouldThrowDependencyValidationOnRemoveIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync()
{
// given
Guid groupId = Guid.NewGuid();
Expand All @@ -27,10 +27,14 @@ public async Task ShouldThrowDependencyValidationOnRemoveIfDatabaseUpdateConcurr
var databaseUpdateConcurrencyException = new DbUpdateConcurrencyException();

var lockedGroupPostException =
new LockedGroupPostException(databaseUpdateConcurrencyException);
new LockedGroupPostException(
message: "GroupPost is locked, please try again.",
innerException: databaseUpdateConcurrencyException);

var expectedGroupPostDependencyValidationException =
new GroupPostDependencyValidationException(lockedGroupPostException);
new GroupPostDependencyValidationException(
message: "Group post dependency validation occurred, please try again.",
innerException: lockedGroupPostException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupPostByIdAsync(It.IsAny<Guid>(), It.IsAny<Guid>()))
Expand Down Expand Up @@ -66,18 +70,22 @@ await Assert.ThrowsAsync<GroupPostDependencyValidationException>(
}

[Fact]
public async Task ShouldThrowDependencyExceptionOnDeleteWhenSqlExceptionOccursAndLogItAsync()
private async Task ShouldThrowDependencyExceptionOnDeleteWhenSqlExceptionOccursAndLogItAsync()
{
// given
Guid groupId = Guid.NewGuid();
Guid postId = Guid.NewGuid();
SqlException sqlException = GetSqlException();

var failedGroupPostStorageException =
new FailedGroupPostStorageException(sqlException);
new FailedGroupPostStorageException(
message: "Failed group post storage error occured, contact support.",
innerException: sqlException);

var expectedGroupPostDependencyException =
new GroupPostDependencyException(failedGroupPostStorageException);
new GroupPostDependencyException(
message: "Group post dependency validation occurred, please try again.",
innerException: failedGroupPostStorageException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupPostByIdAsync(It.IsAny<Guid>(), It.IsAny<Guid>()))
Expand Down Expand Up @@ -109,18 +117,22 @@ await Assert.ThrowsAsync<GroupPostDependencyException>(
}

[Fact]
public async Task ShouldThrowServiceExceptionOnRemoveIfExceptionOccursAndLogItAsync()
private async Task ShouldThrowServiceExceptionOnRemoveIfExceptionOccursAndLogItAsync()
{
// given
Guid groupId = Guid.NewGuid();
Guid postId = Guid.NewGuid();
var serviceException = new Exception();

var failedGroupPostServiceException =
new FailedGroupPostServiceException(serviceException);
new FailedGroupPostServiceException(
message: "Failed group post service occurred, please contact support.",
innerException: serviceException);

var expectedGroupPostServiceException =
new GroupPostServiceException(failedGroupPostServiceException);
new GroupPostServiceException(
message: "Group post service error occurred, please contact support.",
innerException: failedGroupPostServiceException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupPostByIdAsync(It.IsAny<Guid>(), It.IsAny<Guid>()))
Expand Down Expand Up @@ -151,4 +163,4 @@ await Assert.ThrowsAsync<GroupPostServiceException>(
this.loggingBrokerMock.VerifyNoOtherCalls();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.GroupPosts
public partial class GroupPostServiceTests
{
[Fact]
public async Task ShouldThrowCriticalDependencyExceptionOnAddIfSqlErrorOccursAndLogItAsync()
private async Task ShouldThrowCriticalDependencyExceptionOnAddIfSqlErrorOccursAndLogItAsync()
{
// given
GroupPost someGroupPost = CreateRandomGroupPost();
SqlException sqlException = GetSqlException();

var failedGroupPostStorageException =
new FailedGroupPostStorageException(sqlException);
new FailedGroupPostStorageException(
message: "Failed group post storage error occured, contact support.",
innerException: sqlException);

var expectedGroupPostDependencyException =
new GroupPostDependencyException(failedGroupPostStorageException);
new GroupPostDependencyException(
message: "Group post dependency validation occurred, please try again.",
innerException: failedGroupPostStorageException);

this.storageBrokerMock.Setup(broker =>
broker.InsertGroupPostAsync(It.IsAny<GroupPost>()))
Expand Down Expand Up @@ -57,7 +61,7 @@ await Assert.ThrowsAsync<GroupPostDependencyException>(() =>
}

[Fact]
public async Task ShouldThrowDependencyValidationExceptionOnAddIfGroupPostAlreadyExistsAndLogItAsync()
private async Task ShouldThrowDependencyValidationExceptionOnAddIfGroupPostAlreadyExistsAndLogItAsync()
{
// given
GroupPost someGroupPost = CreateRandomGroupPost();
Expand All @@ -67,10 +71,14 @@ public async Task ShouldThrowDependencyValidationExceptionOnAddIfGroupPostAlread
new DuplicateKeyException(randomMessage);

var alreadyExistsGroupPostException =
new AlreadyExistsGroupPostException(duplicateKeyException);
new AlreadyExistsGroupPostException(
message: "Group post with the same id already exists.",
innerException: duplicateKeyException);

var expectedGroupPostDependencyValidationException =
new GroupPostDependencyValidationException(alreadyExistsGroupPostException);
new GroupPostDependencyValidationException(
message: "Group post dependency validation occurred, please try again.",
innerException: alreadyExistsGroupPostException);

this.storageBrokerMock.Setup(broker =>
broker.InsertGroupPostAsync(It.IsAny<GroupPost>()))
Expand Down Expand Up @@ -102,7 +110,7 @@ await Assert.ThrowsAsync<GroupPostDependencyValidationException>(
}

[Fact]
public async Task ShouldThrowDependencyExceptionOnAddIfDatabaseUpdateErrorOccursAndLogItAsync()
private async Task ShouldThrowDependencyExceptionOnAddIfDatabaseUpdateErrorOccursAndLogItAsync()
{
//given
GroupPost someGroupPost = CreateRandomGroupPost();
Expand All @@ -111,10 +119,14 @@ public async Task ShouldThrowDependencyExceptionOnAddIfDatabaseUpdateErrorOccurs
new DbUpdateException();

var failedGroupPostStorageException =
new FailedGroupPostStorageException(databaseUpdateException);
new FailedGroupPostStorageException(
message: "Failed group post storage error occured, contact support.",
innerException: databaseUpdateException);

var expectedGroupPostDependencyException =
new GroupPostDependencyException(failedGroupPostStorageException);
new GroupPostDependencyException(
message: "Group post dependency validation occurred, please try again.",
innerException: failedGroupPostStorageException);

this.storageBrokerMock.Setup(broker =>
broker.InsertGroupPostAsync(someGroupPost))
Expand Down Expand Up @@ -146,7 +158,7 @@ await Assert.ThrowsAsync<GroupPostDependencyException>(
}

[Fact]
public async void ShouldThrowDependencyValidationExceptionOnAddIfReferenceErrorOccursAndLogItAsync()
private async void ShouldThrowDependencyValidationExceptionOnAddIfReferenceErrorOccursAndLogItAsync()
{
//given
GroupPost someGroupPost = CreateRandomGroupPost();
Expand All @@ -157,10 +169,14 @@ public async void ShouldThrowDependencyValidationExceptionOnAddIfReferenceErrorO
new ForeignKeyConstraintConflictException(exceptionMessage);

var invalidGroupPostReferenceException =
new InvalidGroupPostReferenceException(foreignKeyConstraintConflictException);
new InvalidGroupPostReferenceException(
message: "Invalid group post reference error occurred.",
innerException: foreignKeyConstraintConflictException);

var expectedGroupPostDependencyValidationException =
new GroupPostDependencyValidationException(invalidGroupPostReferenceException);
new GroupPostDependencyValidationException(
message: "Group post dependency validation occurred, please try again.",
innerException: invalidGroupPostReferenceException);

this.storageBrokerMock.Setup(broker =>
broker.InsertGroupPostAsync(someGroupPost))
Expand Down Expand Up @@ -192,17 +208,21 @@ await Assert.ThrowsAsync<GroupPostDependencyValidationException>(
}

[Fact]
public async Task ShouldThrowServiceExceptionOnAddIfServiceErrorOccursAndLogItAsync()
private async Task ShouldThrowServiceExceptionOnAddIfServiceErrorOccursAndLogItAsync()
{
//given
GroupPost someGroupPost = CreateRandomGroupPost();
var serviceException = new Exception();

var failedGroupPostServiceException =
new FailedGroupPostServiceException(serviceException);
new FailedGroupPostServiceException(
message: "Failed group post service occurred, please contact support.",
innerException: serviceException);

var expectedGroupPostServiceException =
new GroupPostServiceException(failedGroupPostServiceException);
new GroupPostServiceException(
message: "Group post service error occurred, please contact support.",
innerException: failedGroupPostServiceException);

this.storageBrokerMock.Setup(broker =>
broker.InsertGroupPostAsync(someGroupPost))
Expand Down Expand Up @@ -233,4 +253,4 @@ await Assert.ThrowsAsync<GroupPostServiceException>(
this.loggingBrokerMock.VerifyNoOtherCalls();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.GroupPosts
public partial class GroupPostServiceTests
{
[Fact]
public async Task ShouldThrowCriticalDependencyExceptionOnModifyIfSqlErrorOccursAndLogItAsync()
private async Task ShouldThrowCriticalDependencyExceptionOnModifyIfSqlErrorOccursAndLogItAsync()
{
// given
DateTimeOffset someDateTime = GetRandomDateTimeOffset();
Expand All @@ -29,10 +29,14 @@ public async Task ShouldThrowCriticalDependencyExceptionOnModifyIfSqlErrorOccurs
SqlException sqlException = CreateSqlException();

var failedGroupPostStorageException =
new FailedGroupPostStorageException(sqlException);
new FailedGroupPostStorageException(
message: "Failed group post storage error occured, contact support.",
innerException: sqlException);

var expectedGroupPostDependencyException =
new GroupPostDependencyException(failedGroupPostStorageException);
new GroupPostDependencyException(
message: "Group post dependency validation occurred, please try again.",
innerException: failedGroupPostStorageException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupPostByIdAsync(groupId, postId))
Expand Down Expand Up @@ -65,7 +69,7 @@ await Assert.ThrowsAsync<GroupPostDependencyException>(
}

[Fact]
public async Task ShouldThrowDependencyExceptionOnModifyIfDatabaseUpdateExceptionOccursAndLogItAsync()
private async Task ShouldThrowDependencyExceptionOnModifyIfDatabaseUpdateExceptionOccursAndLogItAsync()
{
// given
int minutesInPast = GetRandomNegativeNumber();
Expand All @@ -77,10 +81,14 @@ public async Task ShouldThrowDependencyExceptionOnModifyIfDatabaseUpdateExceptio
var databaseUpdateException = new DbUpdateException();

var failedGroupPostException =
new FailedGroupPostStorageException(databaseUpdateException);
new FailedGroupPostStorageException(
message: "Failed group post storage error occured, contact support.",
innerException: databaseUpdateException);

var expectedGroupPostDependencyException =
new GroupPostDependencyException(failedGroupPostException);
new GroupPostDependencyException(
message: "Group post dependency validation occurred, please try again.",
innerException: failedGroupPostException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupPostByIdAsync(groupId, postId))
Expand Down Expand Up @@ -110,7 +118,7 @@ await Assert.ThrowsAsync<GroupPostDependencyException>(
}

[Fact]
public async Task ShouldThrowDependencyValidationExceptionOnModifyIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync()
private async Task ShouldThrowDependencyValidationExceptionOnModifyIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync()
{
// given
int minutesInPast = GetRandomNegativeNumber();
Expand All @@ -122,10 +130,14 @@ public async Task ShouldThrowDependencyValidationExceptionOnModifyIfDatabaseUpda
var databaseUpdateConcurrencyException = new DbUpdateConcurrencyException();

var lockedGroupPostException =
new LockedGroupPostException(databaseUpdateConcurrencyException);
new LockedGroupPostException(
message: "GroupPost is locked, please try again.",
innerException: databaseUpdateConcurrencyException);

var expectedGroupPostDependencyValidationException =
new GroupPostDependencyValidationException(lockedGroupPostException);
new GroupPostDependencyValidationException(
message: "Group post dependency validation occurred, please try again.",
innerException: lockedGroupPostException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupPostByIdAsync(groupId, postId))
Expand Down Expand Up @@ -154,7 +166,7 @@ await Assert.ThrowsAsync<GroupPostDependencyValidationException>(
}

[Fact]
public async Task ShouldThrowServiceExceptionOnModifyIfDatabaseUpdateErrorOccursAndLogItAsync()
private async Task ShouldThrowServiceExceptionOnModifyIfDatabaseUpdateErrorOccursAndLogItAsync()
{
// given
int minuteInPast = GetRandomNegativeNumber();
Expand All @@ -164,10 +176,14 @@ public async Task ShouldThrowServiceExceptionOnModifyIfDatabaseUpdateErrorOccurs
var serviceException = new Exception();

var failedGroupPostException =
new FailedGroupPostServiceException(serviceException);
new FailedGroupPostServiceException(
message: "Failed group post service occurred, please contact support.",
innerException: serviceException);

var expectedGroupPostServiceException =
new GroupPostServiceException(failedGroupPostException);
new GroupPostServiceException(
message: "Group post service error occurred, please contact support.",
innerException: failedGroupPostException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupPostByIdAsync(someGroupPost.GroupId, someGroupPost.PostId))
Expand Down Expand Up @@ -196,4 +212,4 @@ await Assert.ThrowsAsync<GroupPostServiceException>(
this.loggingBrokerMock.VerifyNoOtherCalls();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,20 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.GroupPosts
public partial class GroupPostServiceTests
{
[Fact]
public void ShouldThrowCriticalDependencyExceptionOnRetrieveAllIfSqlErrorOccursAndLogIt()
private void ShouldThrowCriticalDependencyExceptionOnRetrieveAllIfSqlErrorOccursAndLogIt()
{
//given
SqlException sqlException = GetSqlException();

var failedGroupPostStorageException =
new FailedGroupPostStorageException(sqlException);
new FailedGroupPostStorageException(
message: "Failed group post storage error occured, contact support.",
innerException: sqlException);

var expectedGroupPostDependencyException =
new GroupPostDependencyException(failedGroupPostStorageException);
new GroupPostDependencyException(
message: "Group post dependency validation occurred, please try again.",
innerException: failedGroupPostStorageException);

this.storageBrokerMock.Setup(broker =>
broker.SelectAllGroupPosts()).Throws(sqlException);
Expand Down Expand Up @@ -52,17 +56,21 @@ public void ShouldThrowCriticalDependencyExceptionOnRetrieveAllIfSqlErrorOccursA
}

[Fact]
public void ShouldThrowServiceExceptionOnRetrieveAllWhenAllServiceErrorOccursAndLogIt()
private void ShouldThrowServiceExceptionOnRetrieveAllWhenAllServiceErrorOccursAndLogIt()
{
//given
string exceptionMessage = GetRandomString();
var serviceException = new Exception(exceptionMessage);

var failedGroupPostServiceException =
new FailedGroupPostServiceException(serviceException);
new FailedGroupPostServiceException(
message: "Failed group post service occurred, please contact support.",
innerException: serviceException);

var expectedGroupPostServiceException =
new GroupPostServiceException(failedGroupPostServiceException);
new GroupPostServiceException(
message: "Group post service error occurred, please contact support.",
innerException: failedGroupPostServiceException);

this.storageBrokerMock.Setup(broker =>
broker.SelectAllGroupPosts()).Throws(serviceException);
Expand All @@ -88,4 +96,4 @@ public void ShouldThrowServiceExceptionOnRetrieveAllWhenAllServiceErrorOccursAnd
this.loggingBrokerMock.VerifyNoOtherCalls();
}
}
}
}
Loading

0 comments on commit 62ca0f1

Please sign in to comment.