public async void ShouldThrowValidationExceptionOnAddWhenAttachmentIdIsInvalidAndLogItAsync() { // given CourseAttachment randomCourseAttachment = CreateRandomCourseAttachment(); CourseAttachment inputCourseAttachment = randomCourseAttachment; inputCourseAttachment.AttachmentId = default; var invalidCourseAttachmentInputException = new InvalidCourseAttachmentException( parameterName: nameof(CourseAttachment.AttachmentId), parameterValue: inputCourseAttachment.AttachmentId); var expectedCourseAttachmentValidationException = new CourseAttachmentValidationException(invalidCourseAttachmentInputException); // when ValueTask <CourseAttachment> addCourseAttachmentTask = this.courseAttachmentService.AddCourseAttachmentAsync(inputCourseAttachment); // then await Assert.ThrowsAsync <CourseAttachmentValidationException>(() => addCourseAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedCourseAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertCourseAttachmentAsync(It.IsAny <CourseAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowValidatonExceptionOnRemoveWhenIdsAreInvalidAndLogItAsync() { // given Guid invalidCourseId = Guid.Empty; Guid invalidAttachmentId = Guid.Empty; var invalidCourseAttachmentInputException = new InvalidCourseAttachmentException(); invalidCourseAttachmentInputException.AddData( key: nameof(CourseAttachment.CourseId), values: "Id is required"); invalidCourseAttachmentInputException.AddData( key: nameof(CourseAttachment.AttachmentId), values: "Id is required"); var expectedCourseAttachmentValidationException = new CourseAttachmentValidationException(invalidCourseAttachmentInputException); // when ValueTask <CourseAttachment> removeCourseAttachmentTask = this.courseAttachmentService.RemoveCourseAttachmentByIdAsync( invalidCourseId, invalidAttachmentId); // then await Assert.ThrowsAsync <CourseAttachmentValidationException>(() => removeCourseAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameValidationExceptionAs( expectedCourseAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectCourseAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Never); this.storageBrokerMock.Verify(broker => broker.DeleteCourseAttachmentAsync(It.IsAny <CourseAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowValidatonExceptionOnRemoveWhenAttachmentIdIsInvalidAndLogItAsync() { // given Guid randomAttachmentId = default; Guid randomCourseId = Guid.NewGuid(); Guid invalidAttachmentId = randomAttachmentId; Guid inputCourseId = randomCourseId; var invalidCourseAttachmentInputException = new InvalidCourseAttachmentException( parameterName: nameof(CourseAttachment.AttachmentId), parameterValue: invalidAttachmentId); var expectedCourseAttachmentValidationException = new CourseAttachmentValidationException(invalidCourseAttachmentInputException); // when ValueTask <CourseAttachment> removeCourseAttachmentTask = this.courseAttachmentService.RemoveCourseAttachmentByIdAsync(inputCourseId, invalidAttachmentId); // then await Assert.ThrowsAsync <CourseAttachmentValidationException>(() => removeCourseAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedCourseAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectCourseAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Never); this.storageBrokerMock.Verify(broker => broker.DeleteCourseAttachmentAsync(It.IsAny <CourseAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }