Skip to content

Commit

Permalink
ShouldThrowServiceExceptionOnRetrieveByIdIfServiceErrorOccursAndLogIt…
Browse files Browse the repository at this point in the history
…Async -> PASS
  • Loading branch information
GulchexrasGithub committed Mar 8, 2023
1 parent 98f595a commit ec3bdd9
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,48 @@ await Assert.ThrowsAsync<GroupMembershipDependencyException>(
this.loggingBrokerMock.VerifyNoOtherCalls();
this.dateTimeBrokerMock.VerifyNoOtherCalls();
}

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

var failedGroupMembershipServiceException =
new FailedGroupMembershipServiceException(serviceException);

var expectedGroupMembershipServiceException =
new GroupMembershipServiceException(failedGroupMembershipServiceException);

this.storageBrokerMock.Setup(broker =>
broker.SelectGroupMembershipByIdAsync(It.IsAny<Guid>()))
.ThrowsAsync(serviceException);

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

GroupMembershipServiceException actualGroupMembershipServiceException =
await Assert.ThrowsAsync<GroupMembershipServiceException>(
retrieveGroupMembershipByIdTask.AsTask);

// then
actualGroupMembershipServiceException.Should().BeEquivalentTo(
expectedGroupMembershipServiceException);

this.storageBrokerMock.Verify(broker =>
broker.SelectGroupMembershipByIdAsync(It.IsAny<Guid>()),
Times.Once);

this.loggingBrokerMock.Verify(broker =>
broker.LogError(It.Is(SameExceptionAs(
expectedGroupMembershipServiceException))),
Times.Once);

this.storageBrokerMock.VerifyNoOtherCalls();
this.loggingBrokerMock.VerifyNoOtherCalls();
this.dateTimeBrokerMock.VerifyNoOtherCalls();
}
}
}

0 comments on commit ec3bdd9

Please sign in to comment.