Skip to content

Commit

Permalink
CODE RUB: Groups Exceptions Upgrade v2.10.0
Browse files Browse the repository at this point in the history
Closes: #509
  • Loading branch information
glhays committed Sep 8, 2023
1 parent 7302783 commit 9ecaaab
Show file tree
Hide file tree
Showing 29 changed files with 982 additions and 834 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.Groups
public partial class GroupServiceTests
{
[Fact]
public async Task ShouldThrowCriticalDependencyExceptionOnCreateIfSqlErrorOccursAndLogItAsync()
private async Task ShouldThrowCriticalDependencyExceptionOnCreateIfSqlErrorOccursAndLogItAsync()
{
// given
DateTimeOffset randomDateTime = GetRandomDateTime();
Group someGroup = CreateRandomGroup(randomDateTime);
SqlException sqlException = GetSqlException();

var failedGroupStorageException =
new FailedGroupStorageException(sqlException);
new FailedGroupStorageException(
message: "Failed group storage error occurred, contact support.",
innerException: sqlException);

var expectedGroupDependencyException =
new GroupDependencyException(failedGroupStorageException);
new GroupDependencyException(
message: "Group dependency error occurred, contact support.",
innerException: failedGroupStorageException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand Down Expand Up @@ -67,7 +71,7 @@ await Assert.ThrowsAsync<GroupDependencyException>(
}

[Fact]
public async Task ShouldThrowDependencyValidationExceptionOnCreateIfGroupAlreadyExsitsAndLogItAsync()
private async Task ShouldThrowDependencyValidationExceptionOnCreateIfGroupAlreadyExsitsAndLogItAsync()
{
// given
Group randomGroup = CreateRandomGroup();
Expand All @@ -78,10 +82,14 @@ public async Task ShouldThrowDependencyValidationExceptionOnCreateIfGroupAlready
new DuplicateKeyException(randomMessage);

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

var expectedGroupDependencyValidationException =
new GroupDependencyValidationException(alreadyExistsGroupException);
new GroupDependencyValidationException(
message: "Group dependency validation occurred, please try again.",
innerException: alreadyExistsGroupException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand Down Expand Up @@ -118,7 +126,7 @@ await Assert.ThrowsAsync<GroupDependencyValidationException>(
}

[Fact]
public async void ShouldThrowValidationExceptionOnCreateIfReferenceErrorOccursAndLogItAsync()
private async void ShouldThrowValidationExceptionOnCreateIfReferenceErrorOccursAndLogItAsync()
{
// given
Group someGroup = CreateRandomGroup();
Expand All @@ -129,10 +137,14 @@ public async void ShouldThrowValidationExceptionOnCreateIfReferenceErrorOccursAn
new ForeignKeyConstraintConflictException(exceptionMessage);

var invalidGroupReferenceException =
new InvalidGroupReferenceException(foreignKeyConstraintConflictException);
new InvalidGroupReferenceException(
message: "Invalid group reference error occurred.",
innerException: foreignKeyConstraintConflictException);

var expectedGroupDependencyValidationException =
new GroupDependencyValidationException(invalidGroupReferenceException);
new GroupDependencyValidationException(
message: "Group dependency validation occurred, please try again.",
innerException: invalidGroupReferenceException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand Down Expand Up @@ -169,7 +181,7 @@ await Assert.ThrowsAsync<GroupDependencyValidationException>(
}

[Fact]
public async Task ShouldThrowDependencyExceptionOnCreateIfDatabaseUpdateErrorOccursAndLogItAsync()
private async Task ShouldThrowDependencyExceptionOnCreateIfDatabaseUpdateErrorOccursAndLogItAsync()
{
// given
Group someGroup = CreateRandomGroup();
Expand All @@ -178,10 +190,14 @@ public async Task ShouldThrowDependencyExceptionOnCreateIfDatabaseUpdateErrorOcc
new DbUpdateException();

var failedGroupStorageException =
new FailedGroupStorageException(databaseUpdateException);
new FailedGroupStorageException(
message: "Failed group storage error occurred, contact support.",
innerException: databaseUpdateException);

var expectedGroupDependencyException =
new GroupDependencyException(failedGroupStorageException);
new GroupDependencyException(
message: "Group dependency error occurred, contact support.",
innerException: failedGroupStorageException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand Down Expand Up @@ -218,17 +234,21 @@ await Assert.ThrowsAsync<GroupDependencyException>(
}

[Fact]
public async Task ShouldThrowServiceExceptionOnCreateIfServiceErrorOccursAndLogItAsync()
private async Task ShouldThrowServiceExceptionOnCreateIfServiceErrorOccursAndLogItAsync()
{
// given
Group someGroup = CreateRandomGroup();
var serviceException = new Exception();

var failedGroupServiceException =
new FailedGroupServiceException(serviceException);
new FailedGroupServiceException(
message: "Failed group service error occurred, please contact support.",
innerException: serviceException);

var expectedGroupServiceException =
new GroupServiceException(failedGroupServiceException);
new GroupServiceException(
message: "Group service error occurred, contact support.",
innerException: failedGroupServiceException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand Down Expand Up @@ -264,4 +284,4 @@ await Assert.ThrowsAsync<GroupServiceException>(
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.Groups
public partial class GroupServiceTests
{
[Fact]
public async Task ShouldThrowCriticalDependencyExceptionOnUpdateIfSqlErrorOccursAndLogItAsync()
private async Task ShouldThrowCriticalDependencyExceptionOnUpdateIfSqlErrorOccursAndLogItAsync()
{
// given
Group randomGroup = CreateRandomGroup();
SqlException sqlException = GetSqlException();

var failedGroupStorageException =
new FailedGroupStorageException(sqlException);
new FailedGroupStorageException(
message: "Failed group storage error occurred, contact support.",
innerException: sqlException);

var expectedGroupDependencyException =
new GroupDependencyException(failedGroupStorageException);
new GroupDependencyException(
message: "Group dependency error occurred, contact support.",
innerException: failedGroupStorageException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand Down Expand Up @@ -70,7 +74,7 @@ await Assert.ThrowsAsync<GroupDependencyException>(
}

[Fact]
public async void ShouldThrowValidationExceptionOnUpdateIfReferenceErrorOccursAndLogItAsync()
private async void ShouldThrowValidationExceptionOnUpdateIfReferenceErrorOccursAndLogItAsync()
{
// given
Group someGroup =
Expand All @@ -89,10 +93,14 @@ public async void ShouldThrowValidationExceptionOnUpdateIfReferenceErrorOccursAn
new ForeignKeyConstraintConflictException(exceptionMessage);

var invalidGroupReferenceException =
new InvalidGroupReferenceException(foreignKeyConstraintConflictException);
new InvalidGroupReferenceException(
message: "Invalid group reference error occurred.",
innerException: foreignKeyConstraintConflictException);

var expectedGroupDependencyValidationException =
new GroupDependencyValidationException(invalidGroupReferenceException);
new GroupDependencyValidationException(
message: "Group dependency validation occurred, please try again.",
innerException: invalidGroupReferenceException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand Down Expand Up @@ -132,17 +140,21 @@ await Assert.ThrowsAsync<GroupDependencyValidationException>(
}

[Fact]
public async Task ShouldThrowDependencyExceptionOnModifyIfDatabaseUpdateExceptionOccursAndLogItAsync()
private async Task ShouldThrowDependencyExceptionOnModifyIfDatabaseUpdateExceptionOccursAndLogItAsync()
{
// given
Group randomGroup = CreateRandomGroup();
var databaseUpdateException = new DbUpdateException();

var failedGroupStorageException =
new FailedGroupStorageException(databaseUpdateException);
new FailedGroupStorageException(
message: "Failed group storage error occurred, contact support.",
innerException: databaseUpdateException);

var expectedGroupDependencyException =
new GroupDependencyException(failedGroupStorageException);
new GroupDependencyException(
message: "Group dependency error occurred, contact support.",
innerException: failedGroupStorageException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand Down Expand Up @@ -183,17 +195,21 @@ await Assert.ThrowsAsync<GroupDependencyException>(
}

[Fact]
public async Task ShouldThrowDependencyValidationExceptionOnUpdateIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync()
private async Task ShouldThrowDependencyValidationOnUpdateIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync()
{
// given
Group randomGroup = CreateRandomGroup();
var databaseUpdateConcurrencyException = new DbUpdateConcurrencyException();

var lockedGroupException =
new LockedGroupException(databaseUpdateConcurrencyException);
new LockedGroupException(
message: "Locked group record exception, please try again later",
innerException: databaseUpdateConcurrencyException);

var expectedGroupDependencyValidationException =
new GroupDependencyValidationException(lockedGroupException);
new GroupDependencyValidationException(
message: "Group dependency validation occurred, please try again.",
innerException: lockedGroupException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand Down Expand Up @@ -234,17 +250,21 @@ await Assert.ThrowsAsync<GroupDependencyValidationException>(
}

[Fact]
public async Task ShouldThrowServiceExceptionOnUpdateIfServiceErrorOccursAndLogItAsync()
private async Task ShouldThrowServiceExceptionOnUpdateIfServiceErrorOccursAndLogItAsync()
{
// given
Group randomGroup = CreateRandomGroup();
var serviceException = new Exception();

var failedGroupException =
new FailedGroupServiceException(serviceException);
new FailedGroupServiceException(
message: "Failed group service error occurred, please contact support.",
innerException: serviceException);

var expectedGroupServiceException =
new GroupServiceException(failedGroupException);
new GroupServiceException(
message: "Group service error occurred, contact support.",
innerException: failedGroupException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand Down Expand Up @@ -284,4 +304,4 @@ await Assert.ThrowsAsync<GroupServiceException>(
this.loggingBrokerMock.VerifyNoOtherCalls();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Moq;
using Taarafo.Core.Models.GroupPosts.Exceptions;
using Taarafo.Core.Models.Groups;
using Taarafo.Core.Models.Groups.Exceptions;
using Taarafo.Core.Models.PostImpressions.Exceptions;
using Xunit;

namespace Taarafo.Core.Tests.Unit.Services.Foundations.Groups
{
public partial class GroupServiceTests
{
[Fact]
public async Task ShouldThrowCriticalDependencyExceptionOnRemoveWhenSqlExceptionOccursAndLogItAsync()
private async Task ShouldThrowCriticalDependencyExceptionOnRemoveWhenSqlExceptionOccursAndLogItAsync()
{
// given
Guid someGroupId = Guid.NewGuid();
SqlException sqlException = GetSqlException();

var failedGroupStorageException =
new FailedGroupStorageException(sqlException);
new FailedGroupStorageException(
message: "Failed group storage error occurred, contact support.",
innerException: sqlException);

var expectedGroupDependencyException =
new GroupDependencyException(failedGroupStorageException);
new GroupDependencyException(
message: "Group dependency error occurred, contact support.",
innerException: failedGroupStorageException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupByIdAsync(It.IsAny<Guid>()))
Expand Down Expand Up @@ -67,7 +69,7 @@ await Assert.ThrowsAsync<GroupDependencyException>(
}

[Fact]
public async Task ShouldThrowDependencyValidationOnRemoveIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync()
private async Task ShouldThrowDependencyValidationOnRemoveIfDatabaseUpdateConcurrencyErrorOccursAndLogItAsync()
{
// given
Guid someGroupId = Guid.NewGuid();
Expand All @@ -76,10 +78,14 @@ public async Task ShouldThrowDependencyValidationOnRemoveIfDatabaseUpdateConcurr
new DbUpdateConcurrencyException();

var lockedGroupException =
new LockedGroupException(databaseUpdateConcurrencyException);
new LockedGroupException(
message: "Locked group record exception, please try again later",
innerException: databaseUpdateConcurrencyException);

var expectedGroupDependencyValidationException =
new GroupDependencyValidationException(lockedGroupException);
new GroupDependencyValidationException(
message: "Group dependency validation occurred, please try again.",
innerException: lockedGroupException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupByIdAsync(It.IsAny<Guid>()))
Expand Down Expand Up @@ -116,17 +122,21 @@ await Assert.ThrowsAsync<GroupDependencyValidationException>(
}

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

var failedGroupServiceException =
new FailedGroupServiceException(serviceException);
new FailedGroupServiceException(
message: "Failed group service error occurred, please contact support.",
innerException: serviceException);

var expectedGroupServiceException =
new GroupServiceException(failedGroupServiceException);
new GroupServiceException(
message: "Group service error occurred, contact support.",
innerException: failedGroupServiceException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupByIdAsync(It.IsAny<Guid>()))
Expand Down Expand Up @@ -162,4 +172,4 @@ await Assert.ThrowsAsync<GroupServiceException>(
this.dateTimeBrokerMock.VerifyNoOtherCalls();
}
}
}
}
Loading

0 comments on commit 9ecaaab

Please sign in to comment.