public void Get_EnglishTerm(string searchTerm, BaseCategoryTestData data)
        {
            Mock <IBestBetsDisplayService> displayService = new Mock <IBestBetsDisplayService>();

            displayService
            .Setup(
                dispSvc => dispSvc.GetBestBetForDisplay(
                    It.Is <string>(catID => catID == data.ExpectedData.ID)
                    )
                )
            .Returns(TestingTools.DeserializeXML <CancerGovBestBet>(data.TestFilePath));

            Mock <IBestBetsMatchService> matchService = new Mock <IBestBetsMatchService>();

            matchService
            .Setup(
                matchSvc => matchSvc.GetMatches(
                    It.Is <string>(lang => lang == "en"),
                    It.Is <string>(term => term == searchTerm)
                    )
                )
            .Returns(new string[] { data.ExpectedData.ID });

            // Create instance of controller
            BestBetsController controller = new BestBetsController(
                matchService.Object,
                displayService.Object,
                NullLogger <BestBetsController> .Instance
                );

            IBestBetDisplay[] actualItems = controller.Get("en", searchTerm);

            Assert.Equal(actualItems, new IBestBetDisplay[] { data.ExpectedData }, new IBestBetDisplayComparer());
        }
        public void Can_Deserialize_XML(BaseCategoryTestData data)
        {
            //Setup the expected object.
            CancerGovBestBet actCat = TestingTools.DeserializeXML <CancerGovBestBet>(data.TestFilePath);

            //Compare Object
            Assert.Equal(data.ExpectedData, actCat, new IBestBetCategoryComparer());
        }
Ejemplo n.º 3
0
        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());
        }