public async void GetBestBetForDisplay_DataLoading(BaseDisplayTestData data) { IElasticClient client = GetElasticClientWithData(data); // Setup the mocked Options IOptions <CGBBIndexOptions> bbClientOptions = GetMockOptions(); ESBestBetsDisplayService bbClient = new ESBestBetsDisplayService(client, bbClientOptions, new NullLogger <ESBestBetsDisplayService>()); IBestBetDisplay actDisplay = await bbClient.GetBestBetForDisplay("live", data.ExpectedData.ID); Assert.Equal(data.ExpectedData, actDisplay, new IBestBetDisplayComparer()); }
public IBestBetDisplay[] Get(string language, string term) { if (String.IsNullOrWhiteSpace(language)) { throw new APIErrorException(400, "You must supply a language and search term"); } if (language.ToLower() != "en" && language.ToLower() != "es") { throw new APIErrorException(404, "Unsupported Language. Please try either 'en' or 'es'"); } if (String.IsNullOrWhiteSpace(term)) { throw new APIErrorException(400, "You must supply a search term"); } // Step 1. Remove Punctuation string cleanedTerm = CleanTerm(term); string[] categoryIDs = _matchService.GetMatches(language.ToLower(), cleanedTerm); List <IBestBetDisplay> displayItems = new List <IBestBetDisplay>(); //Now get categories for ID. foreach (string categoryID in categoryIDs) { IBestBetDisplay item = _displayService.GetBestBetForDisplay(categoryID); displayItems.Add(new BestBetAPIGetResult() { ID = item.ID, Name = item.Name, Weight = item.Weight, HTML = item.HTML }); } return(displayItems.ToArray()); }
public async void GetBestBetForDisplay_TestURISetup(BaseDisplayTestData data) { Uri esURI = null; ElasticsearchInterceptingConnection conn = new ElasticsearchInterceptingConnection(); conn.RegisterRequestHandlerForType <Nest.GetResponse <BestBetsCategoryDisplay> >((req, res) => { //Get the file name for this round res.Stream = TestingTools.GetTestFileAsStream("ESDisplayData/" + data.TestFilePath); res.StatusCode = 200; esURI = req.Uri; }); //While this has a URI, it does not matter, an InMemoryConnection never requests //from the server. var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); var connectionSettings = new ConnectionSettings(pool, conn); IElasticClient client = new ElasticClient(connectionSettings); // Setup the mocked Options IOptions <CGBBIndexOptions> bbClientOptions = GetMockOptions(); ESBestBetsDisplayService bbClient = new ESBestBetsDisplayService(client, bbClientOptions, new NullLogger <ESBestBetsDisplayService>()); // We don't actually care that this returns anything - only that the intercepting connection // sets up the request URI correctly. IBestBetDisplay actDisplay = await bbClient.GetBestBetForDisplay("preview", "431121"); Assert.Equal(esURI.Segments, new string[] { "/", "bestbets_preview_v1/", "categorydisplay/", "431121" }, new ArrayComparer()); actDisplay = await bbClient.GetBestBetForDisplay("live", "431121"); Assert.Equal(esURI.Segments, new string[] { "/", "bestbets_live_v1/", "categorydisplay/", "431121" }, new ArrayComparer()); }
public void GetBestBetForDisplay_DataLoading(BaseCategoryTestData data) { //Setup a mock handler, which is what HttpClient uses under the hood to fetch //data. var mockHttp = new MockHttpMessageHandler(); string filePath = data.TestFilePath; ByteArrayContent content = new ByteArrayContent(TestingTools.GetTestFileAsBytes(filePath)); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/xml"); mockHttp .When(string.Format("https://www.cancer.gov/PublishedContent/BestBets/{0}.xml", data.ExpectedData.ID)) .Respond(System.Net.HttpStatusCode.OK, content); // Setup the mocked Options Mock <IOptions <CGBestBetsDisplayServiceOptions> > bbClientOptions = new Mock <IOptions <CGBestBetsDisplayServiceOptions> >(); bbClientOptions .SetupGet(opt => opt.Value) .Returns(new CGBestBetsDisplayServiceOptions() { Host = "https://www.cancer.gov", BBCategoryPathFormatter = "/PublishedContent/BestBets/{0}.xml" } ); CGBestBetsDisplayService bbClient = new CGBestBetsDisplayService(new HttpClient(mockHttp), bbClientOptions.Object, NullLogger <CGBestBetsDisplayService> .Instance); IBestBetDisplay actDisplay = bbClient.GetBestBetForDisplay(data.ExpectedData.ID); Assert.Equal(data.ExpectedData, actDisplay, new IBestBetDisplayComparer()); }