public async void ShouldThrowValidationExceptionOnAddWhenAttachmentIdIsInvalidAndLogItAsync() { // given StudentAttachment randomStudentAttachment = CreateRandomStudentAttachment(); StudentAttachment inputStudentAttachment = randomStudentAttachment; inputStudentAttachment.AttachmentId = default; var invalidStudentAttachmentInputException = new InvalidStudentAttachmentException( parameterName: nameof(StudentAttachment.AttachmentId), parameterValue: inputStudentAttachment.AttachmentId); var expectedStudentAttachmentValidationException = new StudentAttachmentValidationException(invalidStudentAttachmentInputException); // when ValueTask <StudentAttachment> addStudentAttachmentTask = this.studentAttachmentService.AddStudentAttachmentAsync(inputStudentAttachment); // then await Assert.ThrowsAsync <StudentAttachmentValidationException>(() => addStudentAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedStudentAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertStudentAttachmentAsync(It.IsAny <StudentAttachment>()), Times.Never); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnAddWhenStudentAttachmentIsNullAndLogItAsync() { // given StudentAttachment randomStudentAttachment = default; StudentAttachment nullStudentAttachment = randomStudentAttachment; var nullStudentAttachmentException = new NullStudentAttachmentException(); var expectedStudentAttachmentValidationException = new StudentAttachmentValidationException(nullStudentAttachmentException); // when ValueTask <StudentAttachment> addStudentAttachmentTask = this.studentAttachmentService.AddStudentAttachmentAsync(nullStudentAttachment); // then await Assert.ThrowsAsync <StudentAttachmentValidationException>(() => addStudentAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedStudentAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertStudentAttachmentAsync(It.IsAny <StudentAttachment>()), Times.Never); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowValidatonExceptionOnRetrieveWhenAttachmentIdIsInvalidAndLogItAsync() { // given Guid randomAttachmentId = default; Guid randomStudentId = Guid.NewGuid(); Guid inputAttachmentId = randomAttachmentId; Guid inputStudentId = randomStudentId; var invalidStudentAttachmentInputException = new InvalidStudentAttachmentException( parameterName: nameof(StudentAttachment.AttachmentId), parameterValue: inputAttachmentId); var expectedStudentAttachmentValidationException = new StudentAttachmentValidationException(invalidStudentAttachmentInputException); // when ValueTask <StudentAttachment> actualStudentAttachmentTask = this.studentAttachmentService.RetrieveStudentAttachmentByIdAsync(inputStudentId, inputAttachmentId); // then await Assert.ThrowsAsync <StudentAttachmentValidationException>(() => actualStudentAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedStudentAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
private StudentAttachmentValidationException CreateAndLogValidationException(Exception exception) { var StudentAttachmentValidationException = new StudentAttachmentValidationException(exception); this.loggingBroker.LogError(StudentAttachmentValidationException); return(StudentAttachmentValidationException); }
public async Task ShouldThrowValidationExceptionOnRemoveWhenStorageStudentAttachmentIsInvalidAndLogItAsync() { // given DateTimeOffset randomDateTime = GetRandomDateTime(); StudentAttachment randomStudentAttachment = CreateRandomStudentAttachment(randomDateTime); Guid inputAttachmentId = randomStudentAttachment.AttachmentId; Guid inputStudentId = randomStudentAttachment.StudentId; StudentAttachment nullStorageStudentAttachment = null; var notFoundStudentAttachmentException = new NotFoundStudentAttachmentException(inputStudentId, inputAttachmentId); var expectedSemesterCourseValidationException = new StudentAttachmentValidationException(notFoundStudentAttachmentException); this.storageBrokerMock.Setup(broker => broker.SelectStudentAttachmentByIdAsync(inputStudentId, inputAttachmentId)) .ReturnsAsync(nullStorageStudentAttachment); // when ValueTask <StudentAttachment> removeStudentAttachmentTask = this.studentAttachmentService.RemoveStudentAttachmentByIdAsync(inputStudentId, inputAttachmentId); // then await Assert.ThrowsAsync <StudentAttachmentValidationException>(() => removeStudentAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedSemesterCourseValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectStudentAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); this.storageBrokerMock.Verify(broker => broker.DeleteStudentAttachmentAsync(It.IsAny <StudentAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnAddWhenReferneceExceptionAndLogItAsync() { // given StudentAttachment randomStudentAttachment = CreateRandomStudentAttachment(); StudentAttachment invalidStudentAttachment = randomStudentAttachment; string randomMessage = GetRandomMessage(); string exceptionMessage = randomMessage; var foreignKeyConstraintConflictException = new ForeignKeyConstraintConflictException(exceptionMessage); var invalidStudentAttachmentReferenceException = new InvalidStudentAttachmentReferenceException(foreignKeyConstraintConflictException); var expectedStudentAttachmentValidationException = new StudentAttachmentValidationException(invalidStudentAttachmentReferenceException); this.storageBrokerMock.Setup(broker => broker.InsertStudentAttachmentAsync(invalidStudentAttachment)) .ThrowsAsync(foreignKeyConstraintConflictException); // when ValueTask <StudentAttachment> addStudentAttachmentTask = this.studentAttachmentService.AddStudentAttachmentAsync(invalidStudentAttachment); // then await Assert.ThrowsAsync <StudentAttachmentValidationException>(() => addStudentAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedStudentAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertStudentAttachmentAsync(invalidStudentAttachment), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnAddWhenStudentAttachmentAlreadyExistsAndLogItAsync() { // given StudentAttachment randomStudentAttachment = CreateRandomStudentAttachment(); StudentAttachment alreadyExistsStudentAttachment = randomStudentAttachment; string randomMessage = GetRandomMessage(); string exceptionMessage = randomMessage; var duplicateKeyException = new DuplicateKeyException(exceptionMessage); var alreadyExistsStudentAttachmentException = new AlreadyExistsStudentAttachmentException(duplicateKeyException); var expectedStudentAttachmentValidationException = new StudentAttachmentValidationException(alreadyExistsStudentAttachmentException); this.storageBrokerMock.Setup(broker => broker.InsertStudentAttachmentAsync(alreadyExistsStudentAttachment)) .ThrowsAsync(duplicateKeyException); // when ValueTask <StudentAttachment> addStudentAttachmentTask = this.studentAttachmentService.AddStudentAttachmentAsync(alreadyExistsStudentAttachment); // then await Assert.ThrowsAsync <StudentAttachmentValidationException>(() => addStudentAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedStudentAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertStudentAttachmentAsync(alreadyExistsStudentAttachment), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); }