Skip to content

Commit bd58442

Browse files
ShouldThrowServiceExceptionOnRemoveIfExceptionOccursAndLogItAsync -> FAIL
1 parent a509558 commit bd58442

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

LibraryManagement.Api.Tests.Unit/Services/Foundations/Readers/ReaderServiceTests.Exceptions.RemoveById.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,47 @@ await Assert.ThrowsAsync<ReaderDependencyException>(() =>
101101
this.storageBrokerMock.VerifyNoOtherCalls();
102102
this.loggingBrokerMock.VerifyNoOtherCalls();
103103
}
104+
105+
[Fact]
106+
public async Task ShouldThrowServiceExceptionOnRemoveIfExceptionOccursAndLogItAsync()
107+
{
108+
// given
109+
Guid someReaderId = Guid.NewGuid();
110+
var serviceException = new Exception();
111+
112+
var failedReaderServiceException =
113+
new FailedReaderServiceException(serviceException);
114+
115+
var expectedReaderServiceException =
116+
new ReaderServiceException(failedReaderServiceException);
117+
118+
this.storageBrokerMock.Setup(broker =>
119+
broker.SelectReaderByIdAsync(It.IsAny<Guid>()))
120+
.ThrowsAsync(serviceException);
121+
122+
// when
123+
ValueTask<Reader> removeReaderByIdTask =
124+
this.readerService.RemoveReaderByIdAsync(someReaderId);
125+
126+
ReaderServiceException actualReaderServiceException =
127+
await Assert.ThrowsAsync<ReaderServiceException>(() =>
128+
removeReaderByIdTask.AsTask());
129+
130+
// then
131+
actualReaderServiceException.Should()
132+
.BeEquivalentTo(expectedReaderServiceException);
133+
134+
this.storageBrokerMock.Verify(broker =>
135+
broker.SelectReaderByIdAsync(It.IsAny<Guid>()),
136+
Times.Once);
137+
138+
this.loggingBrokerMock.Verify(broker =>
139+
broker.LogError(It.Is(SameExceptionAs(
140+
expectedReaderServiceException))),
141+
Times.Once);
142+
143+
this.storageBrokerMock.VerifyNoOtherCalls();
144+
this.loggingBrokerMock.VerifyNoOtherCalls();
145+
}
104146
}
105147
}

0 commit comments

Comments
 (0)