public async Task AllPages_should_call_repository_and_converter() { // given IEnumerable <Page> pages = _fixture.CreateMany <Page>(); _pageRepositoryMock .AllPagesAsync() .Returns(pages); // when ActionResult <IEnumerable <PageResponse> > actionResult = await _pagesController.AllPages(); // then var model = (actionResult.Result as OkObjectResult).Value as IEnumerable <PageResponse>; model.ShouldNotBeNull("ActionResult's ViewModel was null"); model.Count().ShouldBe(pages.Count()); await _pageRepositoryMock .Received(1) .AllPagesAsync(); _viewObjectsConverterMock .Received(pages.Count()) .ConvertToPageResponse(Arg.Any <Page>()); }
public async Task <ActionResult <string> > ExportPagesToXml() { IEnumerable <Page> allPages = await _pageRepository.AllPagesAsync(); XmlSerializer serializer = new XmlSerializer(typeof(List <Page>)); StringBuilder builder = new StringBuilder(); using (StringWriter writer = new StringWriter(builder)) { serializer.Serialize(writer, allPages); return(Ok(builder.ToString())); } }
public async Task AllPages_should_return_pages() { // given IEnumerable <Page> pages = _fixture.CreateMany <Page>(); _pageRepositoryMock .AllPagesAsync() .Returns(pages); // when ActionResult <IEnumerable <PageResponse> > actionResult = await _pagesController.AllPages(); // then actionResult.ShouldBeOkObjectResult(); IEnumerable <PageResponse> actualPage = actionResult.GetOkObjectResultValue(); actualPage.Count().ShouldBe(pages.Count()); }
public async Task ExportToXml() { // given List <Page> actualPages = _fixture.CreateMany <Page>().ToList(); _pageRepositoryMock.AllPagesAsync() .Returns(actualPages); XmlSerializer serializer = new XmlSerializer(typeof(List <Page>)); // when string actualXml = await _exportController.ExportPagesToXml(); // then var deserializedPages = serializer.Deserialize(new StringReader(actualXml)) as List <Page>; deserializedPages.Count.ShouldBe(actualPages.Count()); }
public async Task <ActionResult <IEnumerable <PageResponse> > > AllPages() { IEnumerable <Page> allpages = await _pageRepository.AllPagesAsync(); return(Ok(allpages.Select(_pageObjectsConverter.ConvertToPageResponse))); }