public async void GetBestBetForDisplay_InvalidIDError(BaseDisplayTestData data) { IElasticClient client = GetElasticClientWithData(data); // Setup the mocked Options IOptions <CGBBIndexOptions> bbClientOptions = GetMockOptions(); ESBestBetsDisplayService bbClient = new ESBestBetsDisplayService(client, bbClientOptions, new NullLogger <ESBestBetsDisplayService>()); APIErrorException ex = await Assert.ThrowsAsync <APIErrorException>(() => bbClient.GetBestBetForDisplay("live", "chicken")); Assert.Equal(400, ex.HttpStatusCode); }
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 async void Get_EnglishTerm(string searchTerm, BaseDisplayTestData displayData) { Mock <IBestBetsDisplayService> displayService = new Mock <IBestBetsDisplayService>(); displayService .Setup( dispSvc => dispSvc.GetBestBetForDisplay( It.Is <string>(coll => coll == "live"), It.Is <string>(catID => catID == displayData.ExpectedData.ID) ) ) .Returns(Task.FromResult <IBestBetDisplay>(displayData.ExpectedData)); Mock <IBestBetsMatchService> matchService = new Mock <IBestBetsMatchService>(); matchService .Setup( matchSvc => matchSvc.GetMatches( It.Is <string>(coll => coll == "live"), It.Is <string>(lang => lang == "en"), It.Is <string>(term => term == searchTerm) ) ) .Returns(Task.FromResult(new string[] { displayData.ExpectedData.ID })); Mock <IHealthCheckService> healthService = new Mock <IHealthCheckService>(); healthService .Setup( healthSvc => healthSvc.IsHealthy( ) ) .Returns(Task.FromResult(true)); // Create instance of controller BestBetsController controller = new BestBetsController( matchService.Object, displayService.Object, healthService.Object, NullLogger <BestBetsController> .Instance ); IBestBetDisplay[] actualItems = await controller.Get("live", "en", searchTerm); Assert.Equal(actualItems, new IBestBetDisplay[] { displayData.ExpectedData }, new IBestBetDisplayComparer()); }
private IElasticClient GetElasticClientWithData(BaseDisplayTestData data) { 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; }); //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); return(client); }
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()); }