Exemple #1
0
        public void GivenContextWithoutTags_NoTagsAreReturned()
        {
            var givenTags      = new List <Tag>();
            var expectedResult = new List <TagInstanceDto>();
            var mockGraph      = CreateMockTagGraph(givenTags);

            var query = GetTagsQuery.Create();
            IRequestHandler <GetTagsQuery, IEnumerable <TagInstanceDto> > sut = new GetTagsQueryHandler(mockGraph.Object);
            var actualResult = sut.Handle(query, CancellationToken.None).Result;

            actualResult.Should().BeEquivalentTo(expectedResult);
        }
Exemple #2
0
        public async Task GivenValidRequest_WhenMultipleTagsExist_ReturnsPopulatedTagViewModel()
        {
            // Arrange
            var getQueryTags = new GetTagsQuery();

            // Act
            var handler  = new GetTagsQueryHandler(Context, Mapper);
            var response = await handler.Handle(getQueryTags, CancellationToken.None);

            // Assert
            response.ShouldNotBeNull();
            response.ShouldBeOfType <TagViewModelList>();
            response.Tags.ShouldNotBeNull();
            response.Tags.ShouldBeOfType <List <string> >();
            response.Tags.ShouldNotBeEmpty();
        }
Exemple #3
0
        public async Task GivenValidRequest_WhenNoTagsExist_ReturnsEmptyTagList()
        {
            // Arrange
            var getQueryTags = new GetTagsQuery();
            var tagsToRemove = Context.Tags.ToList();

            Context.Tags.RemoveRange(tagsToRemove);
            Context.SaveChanges();

            // Act
            var handler  = new GetTagsQueryHandler(Context, Mapper);
            var response = await handler.Handle(getQueryTags, CancellationToken.None);

            // Assert
            response.ShouldNotBeNull();
            response.ShouldBeOfType <TagViewModelList>();
            response.Tags.ShouldNotBeNull();
            response.Tags.ShouldBeOfType <List <string> >();
            response.Tags.ShouldBeEmpty();
        }
Exemple #4
0
        public void GivenContextWithSampleTags_ThenAllTagsAreReturned()
        {
            var givenTags = new[] { new Tag {
                                        Id = 52, Name = "random", Description = "It is so random"
                                    }, new Tag {
                                        Id = 62, Name = "expected", Description = "Spanish Inquisition"
                                    } };
            var expectedResult = new[]
            {
                new TagInstanceDto("random", "It is so random", Array.Empty <string>(), Array.Empty <string>()),
                new TagInstanceDto("expected", "Spanish Inquisition", Array.Empty <string>(), Array.Empty <string>())
            };
            var mockGraph = CreateMockTagGraph(givenTags);

            var query = GetTagsQuery.Create();
            IRequestHandler <GetTagsQuery, IEnumerable <TagInstanceDto> > sut = new GetTagsQueryHandler(mockGraph.Object);
            var actualResult = sut.Handle(query, CancellationToken.None).Result;

            actualResult.Should().BeEquivalentTo(expectedResult);
        }