Exemplo n.º 1
0
        public async void ShouldThrowValidationExceptionOnAddWhenCreatedDateIsNotRecentAndLogItAsync(int minutes)
        {
            // given
            DateTimeOffset dateTime  = GetRandomDateTime();
            Tag            randomTag = CreateRandomTag(dateTime);
            Tag            inputTag  = randomTag;

            inputTag.UpdatedBy   = randomTag.CreatedBy;
            inputTag.CreatedDate = dateTime.AddMinutes(minutes);
            inputTag.UpdatedDate = inputTag.CreatedDate;

            var invalidTagValidationException = new InvalidTagException(
                parameterName: nameof(Tag.CreatedDate),
                parameterValue: inputTag.CreatedDate);

            var expectedTagValidationException =
                new TagValidationException(invalidTagValidationException);

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

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

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

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

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


            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
Exemplo n.º 2
0
        public async void ShouldThrowValidationExceptionOnCreateWhenTagIdIsInvalidAndLogItAsync()
        {
            //given
            DateTimeOffset dateTime  = GetRandomDateTime();
            Tag            randomTag = CreateRandomTag(dateTime);
            Tag            inputTag  = randomTag;

            inputTag.Id = default;

            var invalidTagInputException = new InvalidTagException(
                parameterName: nameof(Tag.Id),
                parameterValue: inputTag.Id);

            var expectedTagValidationException =
                new TagValidationException(invalidTagInputException);

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

            // then
            await Assert.ThrowsAsync <TagValidationException>(() =>
                                                              registerTagTask.AsTask());

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

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

            this.dateTimeBrokerMock.VerifyNoOtherCalls();
            this.loggingBrokerMock.VerifyNoOtherCalls();
            this.storageBrokerMock.VerifyNoOtherCalls();
        }
Exemplo n.º 3
0
        public async Task ShouldThrowValidatonExceptionOnDeleteWhenIdIsInvalidAndLogItAsync()
        {
            // given
            Guid randomTagId = default;
            Guid inputTagId  = randomTagId;

            var invalidTagInputException = new InvalidTagException(
                parameterName: nameof(Tag.Id),
                parameterValue: inputTagId);

            var expectedTagValidationException =
                new TagValidationException(invalidTagInputException);

            // when
            ValueTask <Tag> deleteTagTask =
                this.tagService.RemoveTagByIdAsync(inputTagId);

            // then
            await Assert.ThrowsAsync <TagValidationException>(() => deleteTagTask.AsTask());

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

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

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

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