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: GroupMemberships Exceptions Upgrade v2.10.0 #521

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.GroupMemberships
public partial class GroupMembershipServiceTests
{
[Fact]
public async Task ShouldThrowCriticalDependencyExceptionOnAddIfSqlErrorOccursAndLogItAsync()
private async Task ShouldThrowCriticalDependencyExceptionOnAddIfSqlErrorOccursAndLogItAsync()
{
//given
DateTimeOffset randomDateTime = GetRandomDateTimeOffset();
GroupMembership someGroupMembership = CreateRandomGroupMembership(randomDateTime);
SqlException sqlException = GetSqlException();

var failedGroupMembershipStorageException =
new FailedGroupMembershipStorageException(sqlException);
new FailedGroupMembershipStorageException(
message: "Failed GroupMembership storage error occured, contact support.",
innerException: sqlException);

var expectedGroupMembershipDependencyException =
new GroupMembershipDependencyException(failedGroupMembershipStorageException);
new GroupMembershipDependencyException(
message: "GroupMembership dependency validation occurred, please try again.",
innerException: failedGroupMembershipStorageException);

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

[Fact]
public async Task ShouldThrowDependencyValidationExceptionOnAddIfGroupMembershipAlreadyExistsAndLogItAsync()
private async Task ShouldThrowDependencyValidationExceptionOnAddIfGroupMembershipAlreadyExistsAndLogItAsync()
{
//given
GroupMembership randomGroupMembership = CreateRandomGroupMembership();
Expand All @@ -78,10 +82,14 @@ public async Task ShouldThrowDependencyValidationExceptionOnAddIfGroupMembership
new DuplicateKeyException(randomMessage);

var alreadyExistsGroupMembershipException =
new AlreadyExistsGroupMembershipException(duplicateKeyException);
new AlreadyExistsGroupMembershipException(
message: "GroupMembership with the same id already exists.",
innerException: duplicateKeyException);

var expectedGroupMembershipDependencyValidationException =
new GroupMembershipDependencyValidationException(alreadyExistsGroupMembershipException);
new GroupMembershipDependencyValidationException(
message: "GroupMembership dependency validation occurred, please try again.",
innerException: alreadyExistsGroupMembershipException);

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

[Fact]
public async Task ShouldThrowDependencyExceptionOnAddIfDatabaseUpdateErrorOccursAndLogItAsync()
private async Task ShouldThrowDependencyExceptionOnAddIfDatabaseUpdateErrorOccursAndLogItAsync()
{
//given
GroupMembership someGroupMembership = CreateRandomGroupMembership();

var databaseUpdateException = new DbUpdateException();

var failedGroupMembershipStorageException =
new FailedGroupMembershipStorageException(databaseUpdateException);
new FailedGroupMembershipStorageException(
message: "Failed GroupMembership storage error occured, contact support.",
innerException: databaseUpdateException);

var expectedGroupMembershipDependencyException =
new GroupMembershipDependencyException(failedGroupMembershipStorageException);
new GroupMembershipDependencyException(
message: "GroupMembership dependency validation occurred, please try again.",
innerException: failedGroupMembershipStorageException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand Down Expand Up @@ -166,25 +178,30 @@ await Assert.ThrowsAsync<GroupMembershipDependencyException>(
}

[Fact]
public async Task ShouldThrowServiceExceptionOnAddIfDatabaseUpdateErrorOccursAndLogItAsync()
private async Task ShouldThrowServiceExceptionOnAddIfDatabaseUpdateErrorOccursAndLogItAsync()
{
// given
GroupMembership someGroupMembership = CreateRandomGroupMembership();
var serviceException = new Exception();

var failedGroupMembershipServiceException =
new FailedGroupMembershipServiceException(serviceException);
new FailedGroupMembershipServiceException(
message: "Failed GroupMembership service occurred, please contact support.",
innerException: serviceException);

var expectedGroupMembershipServiceException =
new GroupMembershipServiceException(failedGroupMembershipServiceException);
new GroupMembershipServiceException(
message: "GroupMembership service error occurred, please contact support.",
innerException: failedGroupMembershipServiceException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
.Throws(serviceException);

// when
ValueTask<GroupMembership> addGroupMembershipTask =
this.groupMembershipService.AddGroupMembershipAsync(someGroupMembership);
this.groupMembershipService.AddGroupMembershipAsync(
someGroupMembership);

GroupMembershipServiceException actualGroupMembershipServiceException =
await Assert.ThrowsAsync<GroupMembershipServiceException>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.GroupMemberships
public partial class GroupMembershipServiceTests
{
[Fact]
public async Task ShouldThrowCriticalDependencyExceptionOnRetrieveByIdIfSqlErrorOccursAndLogItAsync()
private async Task ShouldThrowCriticalDependencyExceptionOnRetrieveByIdIfSqlErrorOccursAndLogItAsync()
{
// given
Guid someId = Guid.NewGuid();
SqlException sqlException = GetSqlException();

var failedGroupMembershipStorageException =
new FailedGroupMembershipStorageException(sqlException);
new FailedGroupMembershipStorageException(
message: "Failed GroupMembership storage error occured, contact support.",
innerException: sqlException);

var expectedGroupMembershipDependencyException =
new GroupMembershipDependencyException(failedGroupMembershipStorageException);
new GroupMembershipDependencyException(
message: "GroupMembership dependency validation occurred, please try again.",
innerException: failedGroupMembershipStorageException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupMembershipByIdAsync(It.IsAny<Guid>()))
Expand Down Expand Up @@ -60,17 +64,21 @@ await Assert.ThrowsAsync<GroupMembershipDependencyException>(
}

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

var failedGroupMembershipServiceException =
new FailedGroupMembershipServiceException(serviceException);
new FailedGroupMembershipServiceException(
message: "Failed GroupMembership service occurred, please contact support.",
innerException: serviceException);

var expectedGroupMembershipServiceException =
new GroupMembershipServiceException(failedGroupMembershipServiceException);
new GroupMembershipServiceException(
message: "GroupMembership service error occurred, please contact support.",
innerException: failedGroupMembershipServiceException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupMembershipByIdAsync(It.IsAny<Guid>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.GroupMemberships
public partial class GroupMembershipServiceTests
{
[Fact]
public async Task ShouldAddGroupMembershipAsync()
private async Task ShouldAddGroupMembershipAsync()
{
// given
DateTimeOffset randomDateTime = GetRandomDateTimeOffset();
GroupMembership randomGroupMembership = CreateRandomGroupMembership(randomDateTime);

GroupMembership randomGroupMembership =
CreateRandomGroupMembership(randomDateTime);

GroupMembership inputGroupMembership = randomGroupMembership;
GroupMembership storageGroupMembership = inputGroupMembership;
GroupMembership expectedGroupMembership = storageGroupMembership.DeepClone();

GroupMembership expectedGroupMembership =
storageGroupMembership.DeepClone();

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand All @@ -35,10 +40,12 @@ public async Task ShouldAddGroupMembershipAsync()

// when
GroupMembership actualGroupMembership =
await this.groupMembershipService.AddGroupMembershipAsync(inputGroupMembership);
await this.groupMembershipService.AddGroupMembershipAsync(
inputGroupMembership);

// then
actualGroupMembership.Should().BeEquivalentTo(expectedGroupMembership);
actualGroupMembership.Should().BeEquivalentTo(
expectedGroupMembership);

this.dateTimeBrokerMock.Verify(broker =>
broker.GetCurrentDateTimeOffset(),
Expand All @@ -53,4 +60,4 @@ public async Task ShouldAddGroupMembershipAsync()
this.loggingBrokerMock.VerifyNoOtherCalls();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.GroupMemberships
public partial class GroupMembershipServiceTests
{
[Fact]
public async Task ShouldRetrieveGroupMembershipByIdAsync()
private async Task ShouldRetrieveGroupMembershipByIdAsync()
{
// given
GroupMembership randomGroupMembership = CreateRandomGroupMembership();
Expand All @@ -28,7 +28,8 @@ public async Task ShouldRetrieveGroupMembershipByIdAsync()

// when
GroupMembership actualGroupMembership =
await this.groupMembershipService.RetrieveGroupMembershipByIdAsync(randomGroupMembership.Id);
await this.groupMembershipService.RetrieveGroupMembershipByIdAsync(
randomGroupMembership.Id);

// then
actualGroupMembership.Should().BeEquivalentTo(expectedGroupMembership);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.GroupMemberships
public partial class GroupMembershipServiceTests
{
[Fact]
public async Task ShouldThrowValidationExceptionOnAddIfGroupMembershipIsNullAndLogItAsync()
private async Task ShouldThrowValidationExceptionOnAddIfGroupMembershipIsNullAndLogItAsync()
{
// given
GroupMembership nullGroupMembership = null;
Expand All @@ -25,7 +25,9 @@ public async Task ShouldThrowValidationExceptionOnAddIfGroupMembershipIsNullAndL
new NullGroupMembershipException();

var expectedGroupMembershipValidationException =
new GroupMembershipValidationException(nullGroupMembershipException);
new GroupMembershipValidationException(
message: "GroupMembership validation error occurred, please try again.",
innerException: nullGroupMembershipException);

// when
ValueTask<GroupMembership> addGroupMembershipTask =
Expand All @@ -50,7 +52,7 @@ await Assert.ThrowsAsync<GroupMembershipValidationException>(
}

[Fact]
public async Task ShouldThrowValidationExceptionOnAddIfGroupMembershipIsInvalidAndLogItAsync()
private async Task ShouldThrowValidationExceptionOnAddIfGroupMembershipIsInvalidAndLogItAsync()
{
// given
Guid invalidGuid = Guid.Empty;
Expand Down Expand Up @@ -81,17 +83,19 @@ public async Task ShouldThrowValidationExceptionOnAddIfGroupMembershipIsInvalidA
values: "Date is required");

var expectedGroupMembershipValidationException =
new GroupMembershipValidationException(invalidGroupMembershipException);
new GroupMembershipValidationException(
message: "GroupMembership validation error occurred, please try again.",
innerException: invalidGroupMembershipException);

//when
// when
ValueTask<GroupMembership> addGroupMembershipTask =
this.groupMembershipService.AddGroupMembershipAsync(invalidGroupMembership);

GroupMembershipValidationException actualGroupMembershipValidationException =
await Assert.ThrowsAsync<GroupMembershipValidationException>(
addGroupMembershipTask.AsTask);

//then
// then
actualGroupMembershipValidationException.Should().BeEquivalentTo(
expectedGroupMembershipValidationException);

Expand All @@ -115,7 +119,7 @@ await Assert.ThrowsAsync<GroupMembershipValidationException>(

[Theory]
[MemberData(nameof(MinutesBeforeOrAfter))]
public async Task ShouldThrowValidationExceptionOnAddIfGroupMembershipDateIsNotRecentAndLogItAsync(
private async Task ShouldThrowValidationExceptionOnAddIfGroupMembershipDateIsNotRecentAndLogItAsync(
int minutesBeforeOrAfter)
{
// given
Expand All @@ -125,8 +129,11 @@ public async Task ShouldThrowValidationExceptionOnAddIfGroupMembershipDateIsNotR
DateTimeOffset invalidDateTime =
randomDateTime.AddMinutes(minutesBeforeOrAfter);

GroupMembership randomGroupMembership = CreateRandomGroupMembership(invalidDateTime);
GroupMembership randomGroupMembership =
CreateRandomGroupMembership(invalidDateTime);

GroupMembership invalidGroupMembership = randomGroupMembership;

var invalidGroupMembershipException =
new InvalidGroupMembershipException();

Expand All @@ -135,7 +142,9 @@ public async Task ShouldThrowValidationExceptionOnAddIfGroupMembershipDateIsNotR
values: "Date is not recent");

var expectedGroupMembershipValidationException =
new GroupMembershipValidationException(invalidGroupMembershipException);
new GroupMembershipValidationException(
message: "GroupMembership validation error occurred, please try again.",
innerException: invalidGroupMembershipException);

this.dateTimeBrokerMock.Setup(broker =>
broker.GetCurrentDateTimeOffset())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Taarafo.Core.Tests.Unit.Services.Foundations.GroupMemberships
public partial class GroupMembershipServiceTests
{
[Fact]
public async Task ShouldThrowValidationExceptionOnRetrieveByIdIfIdIsInvalidAndLogItAsync()
private async Task ShouldThrowValidationExceptionOnRetrieveByIdIfIdIsInvalidAndLogItAsync()
{
// given
var invalidGroupMembershipId = Guid.Empty;
Expand All @@ -28,11 +28,14 @@ public async Task ShouldThrowValidationExceptionOnRetrieveByIdIfIdIsInvalidAndLo
values: "Id is required");

var expectedGroupMembershipValidationException =
new GroupMembershipValidationException(invalidGroupMembershipException);
new GroupMembershipValidationException(
message: "GroupMembership validation error occurred, please try again.",
innerException: invalidGroupMembershipException);

// when
ValueTask<GroupMembership> retrieveGroupMembershipByIdTask =
this.groupMembershipService.RetrieveGroupMembershipByIdAsync(invalidGroupMembershipId);
this.groupMembershipService.RetrieveGroupMembershipByIdAsync(
invalidGroupMembershipId);

GroupMembershipValidationException actualGroupMembershipValidationException =
await Assert.ThrowsAsync<GroupMembershipValidationException>(
Expand All @@ -57,25 +60,28 @@ await Assert.ThrowsAsync<GroupMembershipValidationException>(
}

[Fact]
public async Task ShouldThrowNotFoundExceptionOnRetrieveByIdIfGroupMembershipIsNotFoundAndLogItAsync()
private async Task ShouldThrowNotFoundExceptionOnRetrieveByIdIfGroupMembershipIsNotFoundAndLogItAsync()
{
//given
// given
Guid someGroupMembershipId = Guid.NewGuid();
GroupMembership noGroupMembership = null;

var notFoundGroupMembershipException =
new NotFoundGroupMembershipException(someGroupMembershipId);

var expectedGroupMembershipValidationException =
new GroupMembershipValidationException(notFoundGroupMembershipException);
new GroupMembershipValidationException(
message: "GroupMembership validation error occurred, please try again.",
innerException: notFoundGroupMembershipException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupMembershipByIdAsync(It.IsAny<Guid>()))
.ReturnsAsync(noGroupMembership);

//when
// when
ValueTask<GroupMembership> retrieveGroupMembershipByIdTask =
this.groupMembershipService.RetrieveGroupMembershipByIdAsync(someGroupMembershipId);
this.groupMembershipService.RetrieveGroupMembershipByIdAsync(
someGroupMembershipId);

GroupMembershipValidationException actualGroupMembershipValidationException =
await Assert.ThrowsAsync<GroupMembershipValidationException>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ namespace Taarafo.Core.Models.GroupMemberships.Exceptions
public class AlreadyExistsGroupMembershipException : Xeption
{
public AlreadyExistsGroupMembershipException(Exception innerException)
: base(message: "GroupMembership with the same id already exists.", innerException)
: base(
message: "GroupMembership with the same id already exists.",
innerException: innerException)
{ }

public AlreadyExistsGroupMembershipException(string message, Exception innerException)
: base(message, innerException)
{ }
}
}
Loading