Beispiel #1
0
        public async void ShouldThrowValidationExceptionOnAddWhenAttachmentIdIsInvalidAndLogItAsync()
        {
            // given
            AssignmentAttachment randomAssignmentAttachment = CreateRandomAssignmentAttachment();
            AssignmentAttachment inputAssignmentAttachment  = randomAssignmentAttachment;

            inputAssignmentAttachment.AttachmentId = default;

            var invalidAssignmentAttachmentInputException = new InvalidAssignmentAttachmentException(
                parameterName: nameof(AssignmentAttachment.AttachmentId),
                parameterValue: inputAssignmentAttachment.AttachmentId);

            var expectedAssignmentAttachmentValidationException =
                new AssignmentAttachmentValidationException(invalidAssignmentAttachmentInputException);

            // when
            ValueTask <AssignmentAttachment> addAssignmentAttachmentTask =
                this.assignmentAttachmentService.AddAssignmentAttachmentAsync(inputAssignmentAttachment);

            // then
            await Assert.ThrowsAsync <AssignmentAttachmentValidationException>(() =>
                                                                               addAssignmentAttachmentTask.AsTask());

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
Beispiel #2
0
        public async void ShouldThrowValidationExceptionOnAddWhenAssignmentAttachmentIsNullAndLogItAsync()
        {
            // given
            AssignmentAttachment invalidAssignmentAttachment = null;

            var nullAssignmentAttachmentException = new NullAssignmentAttachmentException();

            var expectedAssignmentAttachmentValidationException =
                new AssignmentAttachmentValidationException(nullAssignmentAttachmentException);

            // when
            ValueTask <AssignmentAttachment> addAssignmentAttachmentTask =
                this.assignmentAttachmentService.AddAssignmentAttachmentAsync(invalidAssignmentAttachment);

            // then
            await Assert.ThrowsAsync <AssignmentAttachmentValidationException>(() =>
                                                                               addAssignmentAttachmentTask.AsTask());

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
Beispiel #3
0
        private AssignmentAttachmentValidationException CreateAndLogValidationException(Exception exception)
        {
            var AssignmentAttachmentValidationException = new AssignmentAttachmentValidationException(exception);

            this.loggingBroker.LogError(AssignmentAttachmentValidationException);

            return(AssignmentAttachmentValidationException);
        }
Beispiel #4
0
        public async Task ShouldThrowValidationExceptionOnRemoveWhenStorageAssignmentAttachmentIsInvalidAndLogItAsync()
        {
            // given
            DateTimeOffset       randomDateTime             = GetRandomDateTime();
            AssignmentAttachment randomAssignmentAttachment = CreateRandomAssignmentAttachment(randomDateTime);
            Guid inputAttachmentId = randomAssignmentAttachment.AttachmentId;
            Guid inputAssignmentId = randomAssignmentAttachment.AssignmentId;
            AssignmentAttachment nullStorageAssignmentAttachment = null;

            var notFoundAssignmentAttachmentException =
                new NotFoundAssignmentAttachmentException(inputAssignmentId, inputAttachmentId);

            var expectedAssignmentValidationException =
                new AssignmentAttachmentValidationException(notFoundAssignmentAttachmentException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectAssignmentAttachmentByIdAsync(inputAssignmentId, inputAttachmentId))
            .ReturnsAsync(nullStorageAssignmentAttachment);

            // when
            ValueTask <AssignmentAttachment> removeAssignmentAttachmentTask =
                this.assignmentAttachmentService.RemoveAssignmentAttachmentByIdAsync(
                    inputAssignmentId,
                    inputAttachmentId);

            // then
            await Assert.ThrowsAsync <AssignmentAttachmentValidationException>(() =>
                                                                               removeAssignmentAttachmentTask.AsTask());

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

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
Beispiel #5
0
        public async Task ShouldThrowValidatonExceptionOnRemoveWhenAttachmentIdIsInvalidAndLogItAsync()
        {
            // given
            Guid randomAttachmentId = default;
            Guid randomAssignmentId = Guid.NewGuid();
            Guid inputAttachmentId  = randomAttachmentId;
            Guid inputAssignmentId  = randomAssignmentId;

            var invalidAssignmentAttachmentInputException = new InvalidAssignmentAttachmentException(
                parameterName: nameof(AssignmentAttachment.AttachmentId),
                parameterValue: inputAttachmentId);

            var expectedAssignmentAttachmentValidationException =
                new AssignmentAttachmentValidationException(invalidAssignmentAttachmentInputException);

            // when
            ValueTask <AssignmentAttachment> removeAssignmentAttachmentTask =
                this.assignmentAttachmentService.RemoveAssignmentAttachmentByIdAsync(
                    inputAssignmentId,
                    inputAttachmentId);

            // then
            await Assert.ThrowsAsync <AssignmentAttachmentValidationException>(() =>
                                                                               removeAssignmentAttachmentTask.AsTask());

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

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
Beispiel #6
0
        public async void ShouldThrowValidationExceptionOnAddWhenAssignmentAttachmentAlreadyExistsAndLogItAsync()
        {
            // given
            AssignmentAttachment randomAssignmentAttachment        = CreateRandomAssignmentAttachment();
            AssignmentAttachment alreadyExistsAssignmentAttachment = randomAssignmentAttachment;
            string randomMessage         = GetRandomMessage();
            string exceptionMessage      = randomMessage;
            var    duplicateKeyException = new DuplicateKeyException(exceptionMessage);

            var alreadyExistsAssignmentAttachmentException =
                new AlreadyExistsAssignmentAttachmentException(duplicateKeyException);

            var expectedAssignmentAttachmentValidationException =
                new AssignmentAttachmentValidationException(alreadyExistsAssignmentAttachmentException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertAssignmentAttachmentAsync(alreadyExistsAssignmentAttachment))
            .ThrowsAsync(duplicateKeyException);

            // when
            ValueTask <AssignmentAttachment> addAssignmentAttachmentTask =
                this.assignmentAttachmentService.AddAssignmentAttachmentAsync(alreadyExistsAssignmentAttachment);

            // then
            await Assert.ThrowsAsync <AssignmentAttachmentValidationException>(() =>
                                                                               addAssignmentAttachmentTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertAssignmentAttachmentAsync(alreadyExistsAssignmentAttachment),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
        public async void ShouldThrowValidationExceptionOnAddWhenReferneceExceptionAndLogItAsync()
        {
            // given
            AssignmentAttachment randomAssignmentAttachment  = CreateRandomAssignmentAttachment();
            AssignmentAttachment invalidAssignmentAttachment = randomAssignmentAttachment;
            string randomMessage    = GetRandomMessage();
            string exceptionMessage = randomMessage;
            var    foreignKeyConstraintConflictException = new ForeignKeyConstraintConflictException(exceptionMessage);

            var invalidAssignmentAttachmentReferenceException =
                new InvalidAssignmentAttachmentReferenceException(foreignKeyConstraintConflictException);

            var expectedAssignmentAttachmentValidationException =
                new AssignmentAttachmentValidationException(invalidAssignmentAttachmentReferenceException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertAssignmentAttachmentAsync(invalidAssignmentAttachment))
            .ThrowsAsync(foreignKeyConstraintConflictException);

            // when
            ValueTask <AssignmentAttachment> addAssignmentAttachmentTask =
                this.assignmentAttachmentService.AddAssignmentAttachmentAsync(invalidAssignmentAttachment);

            // then
            await Assert.ThrowsAsync <AssignmentAttachmentValidationException>(() =>
                                                                               addAssignmentAttachmentTask.AsTask());

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

            this.storageBrokerMock.Verify(broker =>
                                          broker.InsertAssignmentAttachmentAsync(invalidAssignmentAttachment),
                                          Times.Once);

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }