public async Task Get_should_return_from_repository_and_call_converter() { // given Page expectedPage = _fixture.Create <Page>(); int id = expectedPage.Id; _pageRepositoryMock .GetPageByIdAsync(id) .Returns(expectedPage); // when ActionResult <PageResponse> actionResult = await _pagesController.Get(id); // then actionResult.Value.ShouldNotBeNull("ActionResult's ViewModel was null"); actionResult.Value.Id.ShouldBe(id); await _pageRepositoryMock .Received(1) .GetPageByIdAsync(id); _viewObjectsConverterMock .Received(1) .ConvertToPageResponse(expectedPage); }
public async Task FindByTag_should_use_repository_to_find_tags() { // given string tag = "gutentag"; List <Page> pagesWithTag = _fixture.CreateMany <Page>().ToList(); pagesWithTag[0].Tags += $", {tag}"; pagesWithTag[1].Tags += $", {tag}"; pagesWithTag[2].Tags += $", {tag}"; _pageRepositoryMock .FindPagesContainingTagAsync(tag) .Returns(pagesWithTag); // when IEnumerable <PageResponse> pageViewModelsWithTag = await _tagsController.FindPageWithTag(tag); // then pageViewModelsWithTag.Count().ShouldBe(pagesWithTag.Count()); _pageViewModelConverterMock .Received(pagesWithTag.Count) .ConvertToPageResponse(Arg.Any <Page>()); }