/// <summary> /// This actually runs the program. /// </summary> public void Run() { try { //This needs to be pulled into its own testable method. //Create new index string indexName = _indexerSvc.CreateTimeStampedIndex(); _logger.LogInformation("Created Index {0}", indexName); //Fetch bunch of BB IPublishedContentListing bestBetsList = _listSvc.GetItemsForPath("BestBets", "/"); //Index the BB int numBBIndexed = _indexerSvc.IndexBestBetsMatches(indexName, GetBestBetMatchesFromListing(bestBetsList)); //Test the collection? //Optimize bool didOptimize = _indexerSvc.OptimizeIndex(indexName); _logger.LogInformation("Optimized Index {0}", indexName); //Swap Alias bool didSwap = _indexerSvc.MakeIndexCurrentAlias(indexName); _logger.LogInformation("Swapped Alias {0}"); _logger.LogDebug("Indexed {0} Best Bets", numBBIndexed.ToString()); //Clean Up old. } catch (Exception ex) { throw new Exception("We should really have a logger for this error.", ex); } }
/// <summary> /// Gets the best bet matches from a IPublishedContentListing. /// </summary> /// <param name="bestBetsList">The best bets list.</param> /// <returns>IEnumerator<BestBetsMatch>.</returns> private IEnumerable <BestBetsMatch> GetBestBetMatchesFromListing(IPublishedContentListing bestBetsList) { foreach (IPublishedContentInfo item in bestBetsList.Files) { //Fetch Item _logger.LogDebug("Fetching Category: {0}", item.FileName); CancerGovBestBet bbCategory = _listSvc.GetPublishedFile <CancerGovBestBet>(item.FullWebPath); _logger.LogDebug("Mapping Category: {0}", bbCategory.Name); //Do we really need a mapper that does this per category? BestBetSynonymMapper mapper = new BestBetSynonymMapper(_tokenService, bbCategory); foreach (BestBetsMatch match in mapper) { yield return(match); } } }
public void DataLoading(string rootName, string dataPath) { // TODO: Create a TestData object. string TestFilePath = "CDEPubContentListingService.BestBets.json"; //Setup a mock handler, which is what HttpClient uses under the hood to fetch //data. var mockHttp = new MockHttpMessageHandler(); string filePath = TestFilePath; ByteArrayContent content = new ByteArrayContent(TestingTools.GetTestFileAsBytes(filePath)); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); mockHttp .When(string.Format("https://www.cancer.gov/PublishedContent/List?root={0}&path={1}&fmt=json", rootName, dataPath)) .Respond(System.Net.HttpStatusCode.OK, content); // Setup the mocked Options Mock <IOptions <PublishedContentListingServiceOptions> > clientOptions = new Mock <IOptions <PublishedContentListingServiceOptions> >(); clientOptions .SetupGet(opt => opt.Value) .Returns(new PublishedContentListingServiceOptions() { Host = "https://www.cancer.gov", ListRoot = "/PublishedContent/List", SpecificListPathFormatter = "?root={0}&path={1}&fmt=json" } ); IPublishedContentListingService listClient = new CDEPubContentListingService(new HttpClient(mockHttp), clientOptions.Object, NullLogger <CDEPubContentListingService> .Instance); IPublishedContentListing actualList = listClient.GetItemsForPath(rootName, dataPath); /// TODO: Make this a list comparison. Assert.NotNull(actualList); }