public async void ShouldThrowValidationExceptionOnCreateWhenAttendanceIsNullAndLogItAsync() { // given Attendance randomAttendance = null; Attendance nullAttendance = randomAttendance; var nullAttendanceException = new NullAttendanceException(); var expectedAttendanceValidationException = new AttendanceValidationException(nullAttendanceException); // when ValueTask <Attendance> createAttendanceTask = this.attendanceService.CreateAttendanceAsync(nullAttendance); // then await Assert.ThrowsAsync <AttendanceValidationException>(() => createAttendanceTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedAttendanceValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertAttendanceAsync(It.IsAny <Attendance>()), Times.Never); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTime(), Times.Never); this.dateTimeBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowValidationExceptionOnModifyWhenAttendanceIsNullAndLogItAsync() { //given Attendance invalidAttendance = null; var nullAttendanceException = new NullAttendanceException(); var expectedAttendanceValidationException = new AttendanceValidationException(nullAttendanceException); //when ValueTask <Attendance> modifyAttendanceTask = this.attendanceService.ModifyAttendanceAsync(invalidAttendance); //then await Assert.ThrowsAsync <AttendanceValidationException>(() => modifyAttendanceTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedAttendanceValidationException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }