public void ShouldThrowServiceExceptionOnRetrieveAllCalendarEntryAttachmentsWhenExceptionOccursAndLogIt()
        {
            // given
            var exception = new Exception();

            var expectedCalendarEntryAttachmentServiceException =
                new CalendarEntryAttachmentServiceException(exception);

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

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

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Esempio n. 2
0
        public async Task ShouldThrowServiceExceptionOnRetrieveWhenExceptionOccursAndLogItAsync()
        {
            // given
            Guid someAttachmentId    = Guid.NewGuid();
            Guid someCalendarEntryId = Guid.NewGuid();
            var  exception           = new Exception();

            var expectedCalendarEntryAttachmentException =
                new CalendarEntryAttachmentServiceException(exception);

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

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

            // then
            await Assert.ThrowsAsync <CalendarEntryAttachmentServiceException>(() =>
                                                                               retrieveCalendarEntryAttachmentTask.AsTask());

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

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
Esempio n. 3
0
        public async Task ShouldThrowServiceExceptionOnAddWhenExceptionOccursAndLogItAsync()
        {
            // given
            CalendarEntryAttachment someCalendarEntryAttachment = CreateRandomCalendarEntryAttachment();
            var exception = new Exception();

            var expectedCalendarEntryAttachmentServiceException =
                new CalendarEntryAttachmentServiceException(exception);

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

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

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

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

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

            this.storageBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
Esempio n. 4
0
        private CalendarEntryAttachmentServiceException CreateAndLogServiceException(Exception exception)
        {
            var CalendarEntryAttachmentServiceException = new CalendarEntryAttachmentServiceException(exception);

            this.loggingBroker.LogError(CalendarEntryAttachmentServiceException);

            return(CalendarEntryAttachmentServiceException);
        }