public async Task ShouldThrowTeacherViewServiceExceptionWhenServiceErrorOccursAndLogItAsync() { var serviceException = new Exception(); var failedTeacherViewServiceException = new FailedTeacherViewServiceException(serviceException); var expectedTeacherViewServiceException = new TeacherViewServiceException(failedTeacherViewServiceException); this.teacherServiceMock.Setup(service => service.RetrieveAllTeachersAsync()) .ThrowsAsync(serviceException); ValueTask <List <TeacherView> > retrieveAllTeacherViewsTask = this.teacherViewService.RetrieveAllTeacherViewsAsync(); await Assert.ThrowsAsync <TeacherViewServiceException>(() => retrieveAllTeacherViewsTask.AsTask()); this.teacherServiceMock.Verify(service => service.RetrieveAllTeachersAsync(), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedTeacherViewServiceException))), Times.Once); this.teacherServiceMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
private TeacherViewServiceException CreateAndLogServiceException(Exception innerException) { var teacherViewServiceException = new TeacherViewServiceException(innerException); this.loggingBroker.LogError(teacherViewServiceException); return(teacherViewServiceException); }