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 void ShouldThrowValidationExceptionOnAddWhenCalendarEntryAttachmentIsNullAndLogItAsync()
        {
            // given
            CalendarEntryAttachment nullCalendarEntryAttachment = default;
            var nullCalendarEntryAttachmentException            = new NullCalendarEntryAttachmentException();

            var expectedCalendarEntryAttachmentValidationException =
                new CalendarEntryAttachmentValidationException(nullCalendarEntryAttachmentException);

            // when
            ValueTask <CalendarEntryAttachment> addCalendarEntryAttachmentTask =
                this.calendarEntryAttachmentService.AddCalendarEntryAttachmentAsync(nullCalendarEntryAttachment);

            // 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();
        }
Esempio n. 4
0
        private CalendarEntryAttachmentValidationException CreateAndLogValidationException(Exception exception)
        {
            var calendarEntryAttachmentValidationException = new CalendarEntryAttachmentValidationException(exception);

            this.loggingBroker.LogError(calendarEntryAttachmentValidationException);

            return(calendarEntryAttachmentValidationException);
        }
        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();
        }
        ShouldThrowValidationExceptionOnRemoveWhenStorageCalendarEntryAttachmentIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset          randomDateTime = GetRandomDateTime();
            CalendarEntryAttachment randomCalendarEntryAttachment = CreateRandomCalendarEntryAttachment(randomDateTime);
            Guid inputAttachmentId    = randomCalendarEntryAttachment.AttachmentId;
            Guid inputCalendarEntryId = randomCalendarEntryAttachment.CalendarEntryId;
            CalendarEntryAttachment nullStorageCalendarEntryAttachment = null;

            var notFoundCalendarEntryAttachmentException =
                new NotFoundCalendarEntryAttachmentException(inputCalendarEntryId, inputAttachmentId);

            var expectedCalendarEntryValidationException =
                new CalendarEntryAttachmentValidationException(notFoundCalendarEntryAttachmentException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectCalendarEntryAttachmentByIdAsync(inputCalendarEntryId, inputAttachmentId))
            .ReturnsAsync(nullStorageCalendarEntryAttachment);

            // when
            ValueTask <CalendarEntryAttachment> removeCalendarEntryAttachmentTask =
                this.calendarEntryAttachmentService.RemoveCalendarEntryAttachmentByIdAsync(inputCalendarEntryId, inputAttachmentId);

            // then
            await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() =>
                                                                                  removeCalendarEntryAttachmentTask.AsTask());

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectCalendarEntryAttachmentByIdAsync(It.IsAny <Guid>(), It.IsAny <Guid>()),
                                          Times.Once);

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedCalendarEntryValidationException))),
                                          Times.Once);

            this.storageBrokerMock.Verify(broker =>
                                          broker.DeleteCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()),
                                          Times.Never);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnAddWhenCalendarEntryAttachmentAlreadyExistsAndLogItAsync()
        {
            // given
            CalendarEntryAttachment randomCalendarEntryAttachment        = CreateRandomCalendarEntryAttachment();
            CalendarEntryAttachment alreadyExistsCalendarEntryAttachment = randomCalendarEntryAttachment;
            string randomMessage         = GetRandomMessage();
            string exceptionMessage      = randomMessage;
            var    duplicateKeyException = new DuplicateKeyException(exceptionMessage);

            var alreadyExistsCalendarEntryAttachmentException =
                new AlreadyExistsCalendarEntryAttachmentException(duplicateKeyException);

            var expectedCalendarEntryAttachmentValidationException =
                new CalendarEntryAttachmentValidationException(alreadyExistsCalendarEntryAttachmentException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertCalendarEntryAttachmentAsync(alreadyExistsCalendarEntryAttachment))
            .ThrowsAsync(duplicateKeyException);

            // when
            ValueTask <CalendarEntryAttachment> addCalendarEntryAttachmentTask =
                this.calendarEntryAttachmentService.AddCalendarEntryAttachmentAsync(alreadyExistsCalendarEntryAttachment);

            // then
            await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() =>
                                                                                  addCalendarEntryAttachmentTask.AsTask());

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()),
                                          Times.Once);

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedCalendarEntryAttachmentValidationException))),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnAddWhenReferneceExceptionAndLogItAsync()
        {
            // given
            CalendarEntryAttachment randomCalendarEntryAttachment = CreateRandomCalendarEntryAttachment();
            CalendarEntryAttachment someCalendarEntryAttachment   = randomCalendarEntryAttachment;
            string randomMessage    = GetRandomMessage();
            string exceptionMessage = randomMessage;
            var    foreignKeyConstraintConflictException = new ForeignKeyConstraintConflictException(exceptionMessage);

            var invalidCalendarEntryAttachmentReferenceException =
                new InvalidCalendarEntryAttachmentReferenceException(foreignKeyConstraintConflictException);

            var expectedCalendarEntryAttachmentValidationException =
                new CalendarEntryAttachmentValidationException(invalidCalendarEntryAttachmentReferenceException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertCalendarEntryAttachmentAsync(someCalendarEntryAttachment))
            .ThrowsAsync(foreignKeyConstraintConflictException);

            // when
            ValueTask <CalendarEntryAttachment> addCalendarEntryAttachmentTask =
                this.calendarEntryAttachmentService.AddCalendarEntryAttachmentAsync(someCalendarEntryAttachment);

            // then
            await Assert.ThrowsAsync <CalendarEntryAttachmentValidationException>(() =>
                                                                                  addCalendarEntryAttachmentTask.AsTask());

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()),
                                          Times.Once);

            this.loggingBrokerMock.Verify(broker =>
                                          broker.LogError(It.Is(SameExceptionAs(
                                                                    expectedCalendarEntryAttachmentValidationException))),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.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();
        }