public async Task ShouldThrowServiceExceptionOnAddWhenExceptionOccursAndLogItAsync()
        {
            // given
            AssignmentAttachment randomAssignmentAttachment = CreateRandomAssignmentAttachment();
            AssignmentAttachment inputAssignmentAttachment  = randomAssignmentAttachment;
            var exception = new Exception();
            var expectedAssignmentAttachmentServiceException = new AssignmentAttachmentServiceException(exception);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertAssignmentAttachmentAsync(inputAssignmentAttachment))
            .ThrowsAsync(exception);

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

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

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
        }
示例#2
0
        public void ShouldThrowServiceExceptionOnRetrieveAllAssignmentAttachmentsWhenExceptionOccursAndLogIt()
        {
            // given
            var exception = new Exception();

            var expectedAssignmentAttachmentServiceException =
                new AssignmentAttachmentServiceException(exception);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectAllAssignmentAttachments())
            .Throws(exception);

            // when . then
            Assert.Throws <AssignmentAttachmentServiceException>(() =>
                                                                 this.assignmentAttachmentService.RetrieveAllAssignmentAttachments());

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
示例#3
0
        private AssignmentAttachmentServiceException CreateAndLogServiceException(Exception exception)
        {
            var AssignmentAttachmentServiceException = new AssignmentAttachmentServiceException(exception);

            this.loggingBroker.LogError(AssignmentAttachmentServiceException);

            return(AssignmentAttachmentServiceException);
        }
示例#4
0
        public async Task ShouldThrowServiceExceptionOnRetrieveWhenExceptionOccursAndLogItAsync()
        {
            // given
            Guid someAttachmentId = Guid.NewGuid();
            Guid someAssignmentId = Guid.NewGuid();
            var  serviceException = new Exception();

            var failedAssignmentAttachmentServiceException =
                new FailedAssignmentAttachmentServiceException(serviceException);

            var expectedAssignmentAttachmentException =
                new AssignmentAttachmentServiceException(failedAssignmentAttachmentServiceException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectAssignmentAttachmentByIdAsync(
                                             It.IsAny <Guid>(),
                                             It.IsAny <Guid>()))
            .ThrowsAsync(serviceException);

            // when
            ValueTask <AssignmentAttachment> retrieveAssignmentAttachmentTask =
                this.assignmentAttachmentService.RetrieveAssignmentAttachmentByIdAsync(
                    someAssignmentId,
                    someAttachmentId);

            // then
            await Assert.ThrowsAsync <AssignmentAttachmentServiceException>(() =>
                                                                            retrieveAssignmentAttachmentTask.AsTask());

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

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

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