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

            var expectedTagServiceException =
                new TagServiceException(exception);

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

            // when . then
            Assert.Throws <TagServiceException>(() =>
                                                this.tagService.RetrieveAllTags());

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

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

            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
            this.dateTimeBrokerMock.VerifyNoOtherCalls();
        }
示例#2
0
        public async Task ShouldThrowServiceExceptionOnRetrieveByIdWhenExceptionOccursAndLogItAsync()
        {
            // given
            Guid someTagId = Guid.NewGuid();
            var  exception = new Exception();

            var expectedTagServiceException =
                new TagServiceException(exception);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectTagByIdAsync(It.IsAny <Guid>()))
            .ThrowsAsync(exception);

            // when
            ValueTask <Tag> retrieveByIdTagTask =
                this.tagService.RetrieveTagByIdAsync(someTagId);

            // then
            await Assert.ThrowsAsync <TagServiceException>(() =>
                                                           retrieveByIdTagTask.AsTask());

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

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

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

            this.loggingBroker.LogError(tagServiceException);

            return(tagServiceException);
        }
        public async Task ShouldThrowServiceExceptionOnAddWhenExceptionOccursAndLogItAsync()
        {
            // given
            DateTimeOffset dateTime  = GetRandomDateTime();
            Tag            randomTag = CreateRandomTag(dateTime);
            Tag            inputTag  = randomTag;

            inputTag.UpdatedBy = inputTag.CreatedBy;
            var exception = new Exception();

            var expectedTagServiceException =
                new TagServiceException(exception);

            this.dateTimeBrokerMock.Setup(broker =>
                                          broker.GetCurrentDateTime())
            .Returns(dateTime);

            this.storageBrokerMock.Setup(broker =>
                                         broker.InsertTagAsync(inputTag))
            .ThrowsAsync(exception);

            // when
            ValueTask <Tag> createTagTask =
                this.tagService.AddTagAsync(inputTag);

            // then
            await Assert.ThrowsAsync <TagServiceException>(() =>
                                                           createTagTask.AsTask());

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

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

            this.dateTimeBrokerMock.Verify(broker =>
                                           broker.GetCurrentDateTime(),
                                           Times.Once);

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
示例#5
0
        public async Task ShouldThrowServiceExceptionOnModifyIfServiceExceptionOccursAndLogItAsync()
        {
            // given
            int            randomNegativeNumber = GetNegativeRandomNumber();
            DateTimeOffset randomDateTime       = GetRandomDateTime();
            Tag            randomTag            = CreateRandomTag(randomDateTime);
            Tag            someTag = randomTag;

            someTag.CreatedDate = randomDateTime.AddMinutes(randomNegativeNumber);
            var serviceException = new Exception();

            var expectedTagServiceException =
                new TagServiceException(serviceException);

            this.storageBrokerMock.Setup(broker =>
                                         broker.SelectTagByIdAsync(someTag.Id))
            .ThrowsAsync(serviceException);

            // when
            ValueTask <Tag> modifyTagTask =
                this.tagService.ModifyTagAsync(someTag);

            // then
            await Assert.ThrowsAsync <TagServiceException>(() =>
                                                           modifyTagTask.AsTask());

            this.storageBrokerMock.Verify(broker =>
                                          broker.SelectTagByIdAsync(someTag.Id),
                                          Times.Once);

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

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