private StudentViewDependencyValidationException CreateAndLogDependencyValidationException(Exception exception) { var studentViewDependencyValidationException = new StudentViewDependencyValidationException(exception); this.loggingBroker.LogError(studentViewDependencyValidationException); return(studentViewDependencyValidationException); }
public async Task ShouldThrowDependencyValidationExceptionOnAddIfStudentValidationErrorOccuredAndLogItAsync( Exception studentServiceValidationException) { // given StudentView someStudentView = CreateRandomStudentView(); var expectedDependencyValidationException = new StudentViewDependencyValidationException(studentServiceValidationException); this.studentServiceMock.Setup(service => service.RegisterStudentAsync(It.IsAny <Student>())) .ThrowsAsync(studentServiceValidationException); // when ValueTask <StudentView> addStudentViewTask = this.studentViewService.AddStudentViewAsync(someStudentView); // then await Assert.ThrowsAsync <StudentViewDependencyValidationException>(() => addStudentViewTask.AsTask()); this.userServiceMock.Verify(service => service.GetCurrentlyLoggedInUser(), Times.Once); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTime(), Times.Once); this.studentServiceMock.Verify(service => service.RegisterStudentAsync(It.IsAny <Student>()), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedDependencyValidationException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.userServiceMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.studentServiceMock.VerifyNoOtherCalls(); this.navigationBrokerMock.VerifyNoOtherCalls(); }