public async Task ShouldThrowValidatonExceptionOnRetrieveWhenAttachmentIdIsInvalidAndLogItAsync() { // given Guid randomAttachmentId = default; Guid randomTeacherId = Guid.NewGuid(); Guid inputAttachmentId = randomAttachmentId; Guid inputTeacherId = randomTeacherId; var invalidTeacherAttachmentInputException = new InvalidTeacherAttachmentException( parameterName: nameof(TeacherAttachment.AttachmentId), parameterValue: inputAttachmentId); var expectedTeacherAttachmentValidationException = new TeacherAttachmentValidationException(invalidTeacherAttachmentInputException); // when ValueTask <TeacherAttachment> actualTeacherAttachmentTask = this.teacherAttachmentService.RetrieveTeacherAttachmentByIdAsync(inputTeacherId, inputAttachmentId); // then await Assert.ThrowsAsync <TeacherAttachmentValidationException>(() => actualTeacherAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedTeacherAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectTeacherAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnAddWhenTeacherAttachmentIsNullAndLogItAsync() { // given TeacherAttachment invalidTeacherAttachment = null; var nullTeacherAttachmentException = new NullTeacherAttachmentException(); var expectedTeacherAttachmentValidationException = new TeacherAttachmentValidationException(nullTeacherAttachmentException); // when ValueTask <TeacherAttachment> addTeacherAttachmentTask = this.teacherAttachmentService.AddTeacherAttachmentAsync(invalidTeacherAttachment); // then await Assert.ThrowsAsync <TeacherAttachmentValidationException>(() => addTeacherAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedTeacherAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertTeacherAttachmentAsync(It.IsAny <TeacherAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnAddWhenAttachmentIdIsInvalidAndLogItAsync() { // given TeacherAttachment randomTeacherAttachment = CreateRandomTeacherAttachment(); TeacherAttachment inputTeacherAttachment = randomTeacherAttachment; inputTeacherAttachment.AttachmentId = default; var invalidTeacherAttachmentInputException = new InvalidTeacherAttachmentException( parameterName: nameof(TeacherAttachment.AttachmentId), parameterValue: inputTeacherAttachment.AttachmentId); var expectedTeacherAttachmentValidationException = new TeacherAttachmentValidationException(invalidTeacherAttachmentInputException); // when ValueTask <TeacherAttachment> addTeacherAttachmentTask = this.teacherAttachmentService.AddTeacherAttachmentAsync(inputTeacherAttachment); // then await Assert.ThrowsAsync <TeacherAttachmentValidationException>(() => addTeacherAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedTeacherAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertTeacherAttachmentAsync(It.IsAny <TeacherAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
private TeacherAttachmentValidationException CreateAndLogValidationException(Exception exception) { var teacherAttachmentValidationException = new TeacherAttachmentValidationException(exception); this.loggingBroker.LogError(teacherAttachmentValidationException); return(teacherAttachmentValidationException); }
public async Task ShouldThrowValidationExceptionOnRemoveWhenStorageTeacherAttachmentIsInvalidAndLogItAsync() { // given DateTimeOffset randomDateTime = GetRandomDateTime(); TeacherAttachment randomTeacherAttachment = CreateRandomTeacherAttachment(randomDateTime); Guid inputAttachmentId = randomTeacherAttachment.AttachmentId; Guid inputTeacherId = randomTeacherAttachment.TeacherId; TeacherAttachment nullStorageTeacherAttachment = null; var notFoundTeacherAttachmentException = new NotFoundTeacherAttachmentException(inputTeacherId, inputAttachmentId); var expectedTeacherValidationException = new TeacherAttachmentValidationException(notFoundTeacherAttachmentException); this.storageBrokerMock.Setup(broker => broker.SelectTeacherAttachmentByIdAsync(inputTeacherId, inputAttachmentId)) .ReturnsAsync(nullStorageTeacherAttachment); // when ValueTask <TeacherAttachment> removeTeacherAttachmentTask = this.teacherAttachmentService.RemoveTeacherAttachmentByIdAsync(inputTeacherId, inputAttachmentId); // then await Assert.ThrowsAsync <TeacherAttachmentValidationException>(() => removeTeacherAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedTeacherValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectTeacherAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Once); this.storageBrokerMock.Verify(broker => broker.DeleteTeacherAttachmentAsync(It.IsAny <TeacherAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnAddWhenReferneceExceptionAndLogItAsync() { // given TeacherAttachment randomTeacherAttachment = CreateRandomTeacherAttachment(); TeacherAttachment invalidTeacherAttachment = randomTeacherAttachment; string randomMessage = GetRandomMessage(); string exceptionMessage = randomMessage; var foreignKeyConstraintConflictException = new ForeignKeyConstraintConflictException(exceptionMessage); var invalidTeacherAttachmentReferenceException = new InvalidTeacherAttachmentReferenceException(foreignKeyConstraintConflictException); var expectedTeacherAttachmentValidationException = new TeacherAttachmentValidationException(invalidTeacherAttachmentReferenceException); this.storageBrokerMock.Setup(broker => broker.InsertTeacherAttachmentAsync(invalidTeacherAttachment)) .ThrowsAsync(foreignKeyConstraintConflictException); // when ValueTask <TeacherAttachment> addTeacherAttachmentTask = this.teacherAttachmentService.AddTeacherAttachmentAsync(invalidTeacherAttachment); // then await Assert.ThrowsAsync <TeacherAttachmentValidationException>(() => addTeacherAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedTeacherAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertTeacherAttachmentAsync(invalidTeacherAttachment), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnAddWhenTeacherAttachmentAlreadyExistsAndLogItAsync() { // given TeacherAttachment randomTeacherAttachment = CreateRandomTeacherAttachment(); TeacherAttachment alreadyExistsTeacherAttachment = randomTeacherAttachment; string randomMessage = GetRandomMessage(); string exceptionMessage = randomMessage; var duplicateKeyException = new DuplicateKeyException(exceptionMessage); var alreadyExistsTeacherAttachmentException = new AlreadyExistsTeacherAttachmentException(duplicateKeyException); var expectedTeacherAttachmentValidationException = new TeacherAttachmentValidationException(alreadyExistsTeacherAttachmentException); this.storageBrokerMock.Setup(broker => broker.InsertTeacherAttachmentAsync(alreadyExistsTeacherAttachment)) .ThrowsAsync(duplicateKeyException); // when ValueTask <TeacherAttachment> addTeacherAttachmentTask = this.teacherAttachmentService.AddTeacherAttachmentAsync(alreadyExistsTeacherAttachment); // then await Assert.ThrowsAsync <TeacherAttachmentValidationException>(() => addTeacherAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs( expectedTeacherAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertTeacherAttachmentAsync(alreadyExistsTeacherAttachment), Times.Once); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }