コード例 #1
0
        public async Task ShouldThrowDependencyExceptionOnRetrieveWhenDbExceptionOccursAndLogItAsync()
        {
            // given
            Guid someAttachmentId        = Guid.NewGuid();
            Guid someCalendarEntryId     = Guid.NewGuid();
            var  databaseUpdateException = new DbUpdateException();

            var expectedCalendarEntryAttachmentDependencyException =
                new CalendarEntryAttachmentDependencyException(databaseUpdateException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectCalendarEntryAttachmentByIdAsync(someCalendarEntryId, someAttachmentId))
            .ThrowsAsync(databaseUpdateException);

            // when
            ValueTask <CalendarEntryAttachment> retrieveAttachmentTask =
                this.calendarEntryAttachmentService.RetrieveCalendarEntryAttachmentByIdAsync
                    (someCalendarEntryId, someAttachmentId);

            // then
            await Assert.ThrowsAsync <CalendarEntryAttachmentDependencyException>(() =>
                                                                                  retrieveAttachmentTask.AsTask());

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectCalendarEntryAttachmentByIdAsync(someCalendarEntryId, someAttachmentId),
                                          Times.Once);

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
        public void ShouldThrowDependencyExceptionOnRetrieveAllCalendarEntryAttachmentsWhenSqlExceptionOccursAndLogIt()
        {
            // given
            var sqlException = GetSqlException();

            var expectedCalendarEntryAttachmentDependencyException =
                new CalendarEntryAttachmentDependencyException(sqlException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectAllCalendarEntryAttachments())
            .Throws(sqlException);

            // when
            Action retrieveAllCalenderEntryAttachmentAction = () =>
                                                              this.calendarEntryAttachmentService.RetrieveAllCalendarEntryAttachments();

            // then
            Assert.Throws <CalendarEntryAttachmentDependencyException>(
                retrieveAllCalenderEntryAttachmentAction);

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public async Task ShouldThrowDependencyExceptionOnAddWhenDbExceptionOccursAndLogItAsync()
        {
            // given
            CalendarEntryAttachment someCalendarEntryAttachment = CreateRandomCalendarEntryAttachment();
            var databaseUpdateException = new DbUpdateException();

            var expectedCalendarEntryAttachmentDependencyException =
                new CalendarEntryAttachmentDependencyException(databaseUpdateException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertCalendarEntryAttachmentAsync(It.IsAny <CalendarEntryAttachment>()))
            .ThrowsAsync(databaseUpdateException);

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

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

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
        public void ShouldThrowDependencyExceptionOnRetrieveAllCalendarEntryAttachmentsWhenDbExceptionOccursAndLogIt()
        {
            // given
            var databaseUpdateException = new DbUpdateException();

            var expectedAttachmentDependencyException =
                new CalendarEntryAttachmentDependencyException(databaseUpdateException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectAllCalendarEntryAttachments())
            .Throws(databaseUpdateException);

            // when . then
            Assert.Throws <CalendarEntryAttachmentDependencyException>(() =>
                                                                       this.calendarEntryAttachmentService.RetrieveAllCalendarEntryAttachments());

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
コード例 #5
0
        private CalendarEntryAttachmentDependencyException CreateAndLogDependencyException(Exception exception)
        {
            var calendarEntryAttachmentDependencyException = new CalendarEntryAttachmentDependencyException(exception);

            this.loggingBroker.LogError(calendarEntryAttachmentDependencyException);

            return(calendarEntryAttachmentDependencyException);
        }
        public async Task ShouldThrowDependencyExceptionOnRemoveWhenSqlExceptionOccursAndLogItAsync()
        {
            // given
            Guid         someAttachmentId    = Guid.NewGuid();
            Guid         someCalendarEntryId = Guid.NewGuid();
            SqlException sqlException        = GetSqlException();

            var expectedCalendarEntryAttachmentDependencyException =
                new CalendarEntryAttachmentDependencyException(sqlException);

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

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

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

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

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

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

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