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); }
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(); }
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(); }
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); }