public async Task ThenItShouldReturnMappedData() { var mapped = new ApiPagedSearchResult <LearningDeliverySynopsis>(); _mapperMock.Setup(mapper => mapper.Map <ApiPagedSearchResult <LearningDeliverySynopsis> >(It.IsAny <PagedSearchResult <LearningDeliverySynopsis> >())) .Returns(mapped); var result = await _controller.ListByUkprnAsync("12345678", "1", CancellationToken.None); var okObjectResult = result as OkObjectResult; var actual = okObjectResult?.Value as ApiPagedSearchResult <LearningDeliverySynopsis>; Assert.IsNotNull(result); Assert.IsNotNull(okObjectResult); Assert.AreSame(mapped, actual); }
public async Task AndRequestedPageIsLastPageOfResultsThenItShouldIncludeLinkToFirstAndPrevAndLastPage() { var mapped = new ApiPagedSearchResult <LearningDeliverySynopsis> { CurrentPage = 3, TotalNumberOfPages = 3, }; _mapperMock.Setup(mapper => mapper.Map <ApiPagedSearchResult <LearningDeliverySynopsis> >(It.IsAny <PagedSearchResult <LearningDeliverySynopsis> >())) .Returns(mapped); var result = await _controller.ListByUkprnAsync("12345678", "1", CancellationToken.None); var okObjectResult = result as OkObjectResult; var actual = okObjectResult?.Value as ApiPagedSearchResult <LearningDeliverySynopsis>; Assert.NotNull(actual?.Links); Assert.AreEqual($"{_urlHelperStub.BaseUrl}/fe-providers/12345678/learning-deliveries?page=1", actual.Links.First); Assert.AreEqual($"{_urlHelperStub.BaseUrl}/fe-providers/12345678/learning-deliveries?page=2", actual.Links.Prev); Assert.IsNull(actual.Links.Next); Assert.AreEqual($"{_urlHelperStub.BaseUrl}/fe-providers/12345678/learning-deliveries?page=3", actual.Links.Last); }
public async Task AndRequestedPageIsLastPageOfResultsThenItShouldIncludeLinkToFirstAndPrevAndLastPage(int?ukprn, string name) { var mapped = new ApiPagedSearchResult <FeProviderSynopsis> { CurrentPage = 3, TotalNumberOfPages = 3, }; _mapperMock.Setup(mapper => mapper.Map <ApiPagedSearchResult <FeProviderSynopsis> >(It.IsAny <PagedSearchResult <FeProviderSynopsis> >())) .Returns(mapped); var result = await _controller.ListAsync(ukprn?.ToString(), name, "1", CancellationToken.None); var expectedCriteriaUrl = EncodeCriteriaForLinkUrl(ukprn, name); var okObjectResult = result as OkObjectResult; var actual = okObjectResult?.Value as ApiPagedSearchResult <FeProviderSynopsis>; Assert.NotNull(actual?.Links); Assert.AreEqual($"{_urlHelperStub.BaseUrl}?page=1{expectedCriteriaUrl}", actual.Links.First); Assert.AreEqual($"{_urlHelperStub.BaseUrl}?page=2{expectedCriteriaUrl}", actual.Links.Prev); Assert.IsNull(actual.Links.Next); Assert.AreEqual($"{_urlHelperStub.BaseUrl}?page=3{expectedCriteriaUrl}", actual.Links.Last); }