public async Task ShouldThrowValidatonExceptionOnRetrieveWhenCalendarEntryIdIsInvalidAndLogItAsync() { // given Guid randomAttachmentId = Guid.NewGuid(); Guid randomCalendarEntryId = default; Guid inputAttachmentId = randomAttachmentId; Guid inputCalendarEntryId = randomCalendarEntryId; var invalidCalendarEntryAttachmentInputException = new InvalidCalendarEntryAttachmentException( parameterName: nameof(CalendarEntryAttachment.CalendarEntryId), parameterValue: inputCalendarEntryId); var expectedCalendarEntryAttachmentValidationException = new CalendarEntryAttachmentValidationException(invalidCalendarEntryAttachmentInputException); // when ValueTask <CalendarEntryAttachment> retrieveCalendarEntryAttachmentTask = this.calendarEntryAttachmentService.RetrieveCalendarEntryAttachmentByIdAsync(inputCalendarEntryId, inputAttachmentId); // then await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() => retrieveCalendarEntryAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedCalendarEntryAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectCalendarEntryAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnAddWhenAttachmentIdIsInvalidAndLogItAsync() { // given CalendarEntryAttachment randomCalendarEntryAttachment = CreateRandomCalendarEntryAttachment(); CalendarEntryAttachment inputCalendarEntryAttachment = randomCalendarEntryAttachment; inputCalendarEntryAttachment.AttachmentId = default; var invalidCalendarEntryAttachmentInputException = new InvalidCalendarEntryAttachmentException( parameterName: nameof(CalendarEntryAttachment.AttachmentId), parameterValue: inputCalendarEntryAttachment.AttachmentId); var expectedCalendarEntryAttachmentValidationException = new CalendarEntryAttachmentValidationException(invalidCalendarEntryAttachmentInputException); // when ValueTask <CalendarEntryAttachment> addCalendarEntryAttachmentTask = this.calendarEntryAttachmentService.AddCalendarEntryAttachmentAsync(inputCalendarEntryAttachment); // then await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() => addCalendarEntryAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameExceptionAs(expectedCalendarEntryAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async Task ShouldThrowValidatonExceptionOnRemoveWhenIdsAreInvalidAndLogItAsync() { // given Guid invalidCalendarEntryId = Guid.Empty; Guid invalidAttachmentId = Guid.Empty; var invalidCalendarEntryAttachmentInputException = new InvalidCalendarEntryAttachmentException(); invalidCalendarEntryAttachmentInputException.AddData( key: nameof(CalendarEntryAttachment.AttachmentId), values: "Id is required"); invalidCalendarEntryAttachmentInputException.AddData( key: nameof(CalendarEntryAttachment.CalendarEntryId), values: "Id is required"); var expectedCalendarEntryAttachmentValidationException = new CalendarEntryAttachmentValidationException( invalidCalendarEntryAttachmentInputException); // when ValueTask <CalendarEntryAttachment> removeCalendarEntryAttachmentTask = this.calendarEntryAttachmentService.RemoveCalendarEntryAttachmentByIdAsync( invalidCalendarEntryId, invalidAttachmentId); // then await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() => removeCalendarEntryAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameValidationExceptionAs( expectedCalendarEntryAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.SelectCalendarEntryAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Never); this.storageBrokerMock.Verify(broker => broker.DeleteCalendarEntryAttachmentAsync( It.IsAny <CalendarEntryAttachment>()), Times.Never); this.loggingBrokerMock.VerifyNoOtherCalls(); this.storageBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }
public async void ShouldThrowValidationExceptionOnAddWhenCalendarEntryAttachmentIsInvalidAndLogItAsync() { // given var invalidCalendarEntryAttachment = new CalendarEntryAttachment(); var invalidCalendarEntryAttachmentInputException = new InvalidCalendarEntryAttachmentException(); invalidCalendarEntryAttachmentInputException.AddData( key: nameof(CalendarEntryAttachment.AttachmentId), values: "Id is required"); invalidCalendarEntryAttachmentInputException.AddData( key: nameof(CalendarEntryAttachment.CalendarEntryId), values: "Id is required"); var expectedCalendarEntryAttachmentValidationException = new CalendarEntryAttachmentValidationException(invalidCalendarEntryAttachmentInputException); // when ValueTask <CalendarEntryAttachment> addCalendarEntryAttachmentTask = this.calendarEntryAttachmentService.AddCalendarEntryAttachmentAsync(invalidCalendarEntryAttachment); // then await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() => addCalendarEntryAttachmentTask.AsTask()); this.loggingBrokerMock.Verify(broker => broker.LogError(It.Is(SameValidationExceptionAs( expectedCalendarEntryAttachmentValidationException))), Times.Once); this.storageBrokerMock.Verify(broker => broker.InsertCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()), Times.Never); this.storageBrokerMock.VerifyNoOtherCalls(); this.loggingBrokerMock.VerifyNoOtherCalls(); this.dateTimeBrokerMock.VerifyNoOtherCalls(); }