private static FundingFeedItemByIdService CreateService( IPublishedFundingRetrievalService publishedFundingRetrievalService = null, ISearchRepository <PublishedFundingIndex> searchRepository = null, ILogger logger = null) { return(new FundingFeedItemByIdService( publishedFundingRetrievalService ?? CreatePublishedFundingRetrievalService(), searchRepository ?? CreateSearchRepository(), GenerateTestPolicies(), logger ?? CreateLogger())); }
private static FundingFeedService CreateService( IFundingFeedSearchService searchService = null, IPublishedFundingRetrievalService publishedFundingRetrievalService = null, IExternalEngineOptions externalEngineOptions = null) { return(new FundingFeedService( searchService ?? CreateSearchService(), publishedFundingRetrievalService ?? CreatePublishedFundingRetrievalService(), externalEngineOptions ?? CreateExternalEngineOptions() )); }
public FundingFeedService( IFundingFeedSearchService feedService, IPublishedFundingRetrievalService publishedFundingRetrievalService, IExternalEngineOptions externalEngineOptions) { Guard.ArgumentNotNull(feedService, nameof(feedService)); Guard.ArgumentNotNull(publishedFundingRetrievalService, nameof(publishedFundingRetrievalService)); Guard.ArgumentNotNull(externalEngineOptions, nameof(externalEngineOptions)); _feedService = feedService; _publishedFundingRetrievalService = publishedFundingRetrievalService; _externalEngineOptions = externalEngineOptions; }
public async Task GetFundingByFundingResultId_GivenResultFound_ReturnsContentResult() { //Arrange string resultId = "12345"; string documentPath = "Round the ragged rocks the ragged rascal ran"; string fundingDocument = "Now is the time for all good men to come to the aid of the party."; PublishedFundingIndex publishedFundingIndex = CreatePublishedFundingResult(); publishedFundingIndex.DocumentPath = documentPath; ISearchRepository <PublishedFundingIndex> searchRepository = CreateSearchRepository(); searchRepository .SearchById(Arg.Is(resultId)) .Returns(publishedFundingIndex); IPublishedFundingRetrievalService publishedFundingRetrievalService = Substitute.For <IPublishedFundingRetrievalService>(); publishedFundingRetrievalService .GetFundingFeedDocument(documentPath) .Returns(fundingDocument); FundingFeedItemByIdService service = CreateService(searchRepository: searchRepository, publishedFundingRetrievalService: publishedFundingRetrievalService); //Act IActionResult result = await service.GetFundingByFundingResultId(resultId); //Assert result .Should().BeOfType <ContentResult>() .Which .StatusCode .Should().Be((int)HttpStatusCode.OK); await searchRepository .Received(1) .SearchById(resultId); await publishedFundingRetrievalService .Received(1) .GetFundingFeedDocument(documentPath); ContentResult contentResult = result as ContentResult; contentResult.Content .Should().Be(fundingDocument); contentResult.ContentType .Should().Be("application/json"); }
public FundingFeedItemByIdService(IPublishedFundingRetrievalService publishedFundingRetrievalService, ISearchRepository <PublishedFundingIndex> fundingSearchRepository, IPublishingResiliencePolicies resiliencePolicies, ILogger logger) { Guard.ArgumentNotNull(publishedFundingRetrievalService, nameof(publishedFundingRetrievalService)); Guard.ArgumentNotNull(fundingSearchRepository, nameof(fundingSearchRepository)); Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(resiliencePolicies?.FundingFeedSearchRepository, nameof(resiliencePolicies.FundingFeedSearchRepository)); _publishedFundingRetrievalService = publishedFundingRetrievalService; _fundingSearchRepository = fundingSearchRepository; _fundingSearchRepositoryPolicy = resiliencePolicies.FundingFeedSearchRepository; _logger = logger; }
public FeedItemPreLoader(IFeedItemPreloaderSettings settings, IPublishedFundingRetrievalService retrievalService, IFundingFeedSearchService searchService, IFileSystemCache cache, IExternalApiFileSystemCacheSettings apiFileSystemCacheSettings) { Guard.ArgumentNotNull(settings, nameof(settings)); Guard.ArgumentNotNull(retrievalService, nameof(retrievalService)); Guard.ArgumentNotNull(searchService, nameof(searchService)); Guard.ArgumentNotNull(cache, nameof(cache)); _settings = settings; _retrievalService = retrievalService; _searchService = searchService; _cache = cache; _apiFileSystemCacheSettings = apiFileSystemCacheSettings; }
public void SetUp() { _settings = new FeedItemPreLoaderSettings(); _retrievalService = Substitute.For <IPublishedFundingRetrievalService>(); _searchService = Substitute.For <IFundingFeedSearchService>(); _cache = Substitute.For <IFileSystemCache>(); _apiFileSystemCacheSettings = Substitute.For <IExternalApiFileSystemCacheSettings>(); _preLoader = new FeedItemPreLoader(_settings, _retrievalService, _searchService, _cache, _apiFileSystemCacheSettings); _retrievalService .GetFundingFeedDocument(Arg.Any <string>(), Arg.Any <bool>()) .Returns((string)null); }
public async Task GetFundingByFundingResultId_GivenEmptyResultFound_ReturnsNotFoundResult(string document) { //Arrange string resultId = "12345"; string documentPath = "Round the ragged rocks the ragged rascal ran"; PublishedFundingIndex publishedFundingIndex = CreatePublishedFundingResult(); publishedFundingIndex.DocumentPath = documentPath; ISearchRepository <PublishedFundingIndex> searchRepository = CreateSearchRepository(); searchRepository .SearchById(Arg.Is(resultId)) .Returns(publishedFundingIndex); IPublishedFundingRetrievalService publishedFundingRetrievalService = Substitute.For <IPublishedFundingRetrievalService>(); publishedFundingRetrievalService .GetFundingFeedDocument(documentPath) .Returns(document); FundingFeedItemByIdService service = CreateService(searchRepository: searchRepository, publishedFundingRetrievalService: publishedFundingRetrievalService); //Act IActionResult result = await service.GetFundingByFundingResultId(resultId); //Assert result .Should().BeOfType <NotFoundResult>(); await searchRepository .Received(1) .SearchById(resultId); }
public async Task GetNotifications_GivenAQueryStringForWhichThereAreResults_ReturnsAtomFeedWithCorrectLinks() { //Arrange string fundingFeedDocument = JsonConvert.SerializeObject(new { FundingStreamId = "PES" }); int pageRef = 2; int pageSize = 3; List <PublishedFundingIndex> searchFeedEntries = CreateFeedIndexes().ToList(); SearchFeedV3 <PublishedFundingIndex> feeds = new SearchFeedV3 <PublishedFundingIndex> { PageRef = pageRef, Top = 2, TotalCount = 8, Entries = searchFeedEntries }; PublishedFundingIndex firstFeedItem = feeds.Entries.ElementAt(0); IFundingFeedSearchService feedsSearchService = CreateSearchService(); feedsSearchService .GetFeedsV3(Arg.Is(pageRef), Arg.Is(pageSize)) .ReturnsForAnyArgs(feeds); IPublishedFundingRetrievalService publishedFundingRetrievalService = Substitute.For <IPublishedFundingRetrievalService>(); publishedFundingRetrievalService .GetFundingFeedDocument(Arg.Any <string>()) .Returns(fundingFeedDocument); Mock <IExternalEngineOptions> externalEngineOptions = new Mock <IExternalEngineOptions>(); externalEngineOptions .Setup(_ => _.BlobLookupConcurrencyCount) .Returns(10); FundingFeedService service = CreateService( searchService: feedsSearchService, publishedFundingRetrievalService: publishedFundingRetrievalService, externalEngineOptions.Object); IHeaderDictionary headerDictionary = new HeaderDictionary { { "Accept", new StringValues("application/json") } }; IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues> { { "pageRef", new StringValues(pageRef.ToString()) }, { "allocationStatuses", new StringValues("Published,Approved") }, { "pageSize", new StringValues(pageSize.ToString()) } }); string scheme = "https"; string path = "/api/v3/fundings/notifications"; string host = "wherever.naf:12345"; string queryString = "?pageSize=2"; HttpRequest request = Substitute.For <HttpRequest>(); request.Scheme.Returns(scheme); request.Path.Returns(new PathString(path)); request.Host.Returns(new HostString(host)); request.QueryString.Returns(new QueryString(queryString)); request.Headers.Returns(headerDictionary); request.Query.Returns(queryStringValues); //Act IActionResult result = await service.GetFunding(request, pageRef : pageRef, pageSize : pageSize); //Assert result .Should() .BeOfType <OkObjectResult>(); OkObjectResult contentResult = result as OkObjectResult; Models.External.V3.AtomItems.AtomFeed <AtomEntry> atomFeed = contentResult.Value as Models.External.V3.AtomItems.AtomFeed <AtomEntry>; atomFeed .Should() .NotBeNull(); atomFeed.Id.Should().NotBeEmpty(); atomFeed.Title.Should().Be("Calculate Funding Service Funding Feed"); atomFeed.Author.Name.Should().Be("Calculate Funding Service"); atomFeed.Link.First(m => m.Rel == "next-archive").Href.Should().Be($"{scheme}://{host}{path}/3{queryString}"); atomFeed.Link.First(m => m.Rel == "prev-archive").Href.Should().Be($"{scheme}://{host}{path}/1{queryString}"); atomFeed.Link.First(m => m.Rel == "self").Href.Should().Be($"{scheme}://{host}{path}{queryString}"); atomFeed.Link.First(m => m.Rel == "current").Href.Should().Be($"{scheme}://{host}{path}/2{queryString}"); atomFeed.AtomEntry.Count.Should().Be(3); for (int i = 0; i < 3; i++) { string text = $"id-{i + 1}"; atomFeed.AtomEntry.ElementAt(i).Id.Should().Be($"{scheme}://{host}/api/v3/fundings/byId/{text}"); atomFeed.AtomEntry.ElementAt(i).Title.Should().Be(text); atomFeed.AtomEntry.ElementAt(i).Summary.Should().Be(text); atomFeed.AtomEntry.ElementAt(i).Content.Should().NotBeNull(); } JObject content = atomFeed.AtomEntry.ElementAt(0).Content as JObject; content.TryGetValue("FundingStreamId", out JToken token); ((JValue)token).Value <string>().Should().Be("PES"); await feedsSearchService .Received(1) .GetFeedsV3(pageRef, pageSize, null, null, null); await publishedFundingRetrievalService .Received(searchFeedEntries.Count) .GetFundingFeedDocument(Arg.Any <string>()); foreach (PublishedFundingIndex index in searchFeedEntries) { await publishedFundingRetrievalService .Received(1) .GetFundingFeedDocument(index.DocumentPath); } }