public async void ShouldThrowValidationExceptionOnCreateWhenCourseIsNullAndLogItAsync() { // given Course randomCourse = null; Course nullCourse = randomCourse; var nullCourseException = new NullCourseException(); var expectedCourseValidationException = new CourseValidationException(nullCourseException); // when ValueTask <Course> createCourseTask = this.courseService.CreateCourseAsync(nullCourse); // then await Assert.ThrowsAsync <CourseValidationException>(() => createCourseTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedCourseValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectCourseByIdAsync(It.IsAny <Guid>()), Times.Never); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowValidationExceptionOnModifyWhenCourseIsNullAndLogItAsync() { //given Course invalidCourse = null; var nullCourseException = new NullCourseException(); var expectedCourseValidationException = new CourseValidationException(nullCourseException); //when ValueTask <Course> modifyCourseTask = this.courseService.ModifyCourseAsync(invalidCourse); //then await Assert.ThrowsAsync <CourseValidationException>(() => modifyCourseTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedCourseValidationException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }