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(); }