public async Task ShouldThrowValidationExceptionOnModifyIfStudentSemesterCourseDoesntExistAndLogItAsync() { // given int randomNegativeMinutes = GetNegativeRandomNumber(); DateTimeOffset dateTime = GetRandomDateTime(); StudentSemesterCourse randomStudentSemesterCourse = CreateRandomStudentSemesterCourse(dateTime); StudentSemesterCourse nonExistentStudentSemesterCourse = randomStudentSemesterCourse; nonExistentStudentSemesterCourse.CreatedDate = dateTime.AddMinutes(randomNegativeMinutes); StudentSemesterCourse noStudentSemesterCourse = null; var notFoundStudentSemesterCourseException = new NotFoundStudentSemesterCourseException (nonExistentStudentSemesterCourse.StudentId, nonExistentStudentSemesterCourse.SemesterCourseId); var expectedStudentSemesterCourseValidationException = new StudentSemesterCourseValidationException(notFoundStudentSemesterCourseException); this.storageBrokerMock.Setup(broker => broker.SelectStudentSemesterCourseByIdAsync( nonExistentStudentSemesterCourse.StudentId, nonExistentStudentSemesterCourse.SemesterCourseId)) .ReturnsAsync(noStudentSemesterCourse); this.dateTimeBrokerMock.Setup(broker => broker.GetCurrentDateTime()) .Returns(dateTime); // when ValueTask <StudentSemesterCourse> modifyStudentSemesterCourseTask = this.studentSemesterCourseService.ModifyStudentSemesterCourseAsync(nonExistentStudentSemesterCourse); // then await Assert.ThrowsAsync <StudentSemesterCourseValidationException>(() => modifyStudentSemesterCourseTask.AsTask()); this.dateTimeBrokerMock.Verify(broker => broker.GetCurrentDateTime(), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentSemesterCourseByIdAsync (nonExistentStudentSemesterCourse.StudentId, nonExistentStudentSemesterCourse.SemesterCourseId), Times.Once); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedStudentSemesterCourseValidationException))), Times.Once); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowValidationExceptionOnDeleteWhenStorageStudentSemesterCourseIsInvalidAndLogItAsync() { // given DateTimeOffset randomDateTime = GetRandomDateTime(); StudentSemesterCourse randomStudentSemesterCourse = CreateRandomStudentSemesterCourse(randomDateTime); Guid inputSemasterCourseId = randomStudentSemesterCourse.SemesterCourseId; Guid inputStudentId = randomStudentSemesterCourse.StudentId; StudentSemesterCourse nullStorageStudentSemesterCourse = null; var notFoundStudentSemesterCourseException = new NotFoundStudentSemesterCourseException(inputSemasterCourseId, inputStudentId); var expectedSemesterCourseValidationException = new StudentSemesterCourseValidationException(notFoundStudentSemesterCourseException); this.storageBrokerMock.Setup(broker => broker.SelectStudentSemesterCourseByIdAsync(inputSemasterCourseId, inputStudentId)) .ReturnsAsync(nullStorageStudentSemesterCourse); // when ValueTask <StudentSemesterCourse> actualStudentSemesterCourseDeleteTask = this.studentSemesterCourseService.RemoveStudentSemesterCourseByIdsAsync(inputSemasterCourseId, inputStudentId); // then await Assert.ThrowsAsync <StudentSemesterCourseValidationException>(() => actualStudentSemesterCourseDeleteTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedSemesterCourseValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentSemesterCourseByIdAsync(inputSemasterCourseId, inputStudentId), Times.Once); this.storageBrokerMock.Verify(broker => broker.DeleteStudentSemesterCourseAsync(It.IsAny <StudentSemesterCourse>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }