public async Task ShouldThrowValidationExceptionOnModifyWhenClassroomIsNullAndLogItAsync() { //given Classroom invalidClassroom = null; var nullClassroomException = new NullClassroomException(); var expectedClassroomValidationException = new ClassroomValidationException(nullClassroomException); //when ValueTask <Classroom> modifyClassroomTask = this.classroomService.ModifyClassroomAsync(invalidClassroom); //then await Assert.ThrowsAsync <ClassroomValidationException>(() => modifyClassroomTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedClassroomValidationException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnCreateWhenClassroomIsNullAndLogItAsync() { // given Classroom randomClassroom = null; Classroom nullClassroom = randomClassroom; var nullClassroomException = new NullClassroomException(); var expectedClassroomValidationException = new ClassroomValidationException(nullClassroomException); // when ValueTask <Classroom> createClassroomTask = this.classroomService.CreateClassroomAsync(nullClassroom); // then await Assert.ThrowsAsync <ClassroomValidationException>(() => createClassroomTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedClassroomValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectClassroomByIdAsync(It.IsAny <Guid>()), Times.Never); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }