public async Task SearchTags() { var repository = new Mock <ITagsRepository>(MockBehavior.Strict); repository .Setup(mock => mock.SearchTags("art")) .ReturnsAsync(new[] { new Tag { Id = Guid.Parse("c2fa02b7-b107-4261-8306-9465178f2949"), Name = "artsy" } }); var controller = new TagsController(repository.Object); var result = await controller.SearchTags("art"); result.ShouldDeepEqual(new[] { new TagViewModel { Name = "artsy" } }); }
public async Task SearchTags() { var tags = _fixture.CreateMany <Tag>(10); var keywords = "birthday party"; _photosService.Setup(m => m.GetTagsByKeywords(keywords, 1, 200)) .ReturnsAsync(tags); var response = await _tagsController.SearchTags(keywords, 1, 200); _photosService.Verify(m => m.GetTagsByKeywords(keywords, 1, 200), Times.Once); Assert.IsType <OkObjectResult>(response); var value = ((OkObjectResult)response).Value; Assert.IsType <List <Dto.Tag> >(value); var dtos = value as List <Dto.Tag>; Assert.Equal(tags.Count(), dtos.Count); }