void SynonymsMappedCorrectly(SynonymTestData data)
        {
            // Load test BestBet object
            string           filePath = data.TestFilePath;
            CancerGovBestBet testData = TestingTools.DeserializeXML <CancerGovBestBet>(filePath);

            // Put the expected matches into a dictionary for fast lookup.
            Dictionary <string, BestBetsMatch> dictExpectedMatches = new Dictionary <string, BestBetsMatch>();

            foreach (BestBetsMatch item in data.ExpectedMatches)
            {
                dictExpectedMatches.Add(item.Synonym, item);
            }

            // Create a BestBetMapper from a test BestBet.
            BestBetSynonymMapper mapper = new BestBetSynonymMapper(
                GetTokenizerServiceForData(data),
                testData
                );

            Assert.All(mapper, match => {
                string synonym = match.Synonym;
                Assert.True(dictExpectedMatches.ContainsKey(synonym));
                Assert.Equal(dictExpectedMatches[synonym], match, new BestBetsMatchComparer());
            });
        }
        public void WriteXML_ThrowsNotSupportedException()
        {
            CancerGovBestBet bestBet = new CancerGovBestBet();

            XmlWriter xmlWriter = XmlWriter.Create(new StringWriter());

            Assert.Throws <NotSupportedException>(() => bestBet.WriteXml(xmlWriter));
        }
        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());
        }
Пример #4
0
        /// <summary>
        /// Gets the best bet matches from a IPublishedContentListing.
        /// </summary>
        /// <param name="bestBetsList">The best bets list.</param>
        /// <returns>IEnumerator&lt;BestBetsMatch&gt;.</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);
                }
            }
        }
        void CorrectNumberOfSynonymsFound(SynonymTestData data)
        {
            // Load test BestBet object
            string           filePath = data.TestFilePath;
            CancerGovBestBet testData = TestingTools.DeserializeXML <CancerGovBestBet>(filePath);

            int expectedCount = data.ExpectedMatches.Count();

            // Create a BestBetMapper from a test BestBet.
            BestBetSynonymMapper mapper = new BestBetSynonymMapper(
                GetTokenizerServiceForData(data),
                testData
                );

            int actualCount = mapper.Count();

            // Verify that returned list of BestBetMatch objects matches what's expected.
            Assert.Equal(expectedCount, actualCount);
        }
        public void BestBetsEntry()
        {
            CancerResearchIdeas testData = new CancerResearchIdeas();


            // TODO: Create a TestData object.
            string TestFilePath = testData.TestFilePath;

            //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/xml");

            mockHttp
            .When(string.Format("https://www.cancer.gov/PublishedContent/BestBets/{0}", filePath))
            .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"
            }
                     );


            IPublishedContentListingService publishedContentClient = new CDEPubContentListingService(new HttpClient(mockHttp),
                                                                                                     clientOptions.Object,
                                                                                                     NullLogger <CDEPubContentListingService> .Instance);

            CancerGovBestBet actualReturn = publishedContentClient.GetPublishedFile <CancerGovBestBet>(String.Format("/PublishedContent/BestBets/{0}", filePath));

            Assert.Equal(testData.ExpectedData, actualReturn, new IBestBetDisplayComparer());
        }
Пример #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="source">The CancerGovBestBet which is being mapped to other objects.</param>
 public BestBetSynonymMapper(ITokenAnalyzerService tokenAnalyzer, CancerGovBestBet source)
 {
     _bestBet       = source;
     _tokenAnalyzer = tokenAnalyzer;
 }
        public void GetSchema_ReturnsNull()
        {
            CancerGovBestBet bestBet = new CancerGovBestBet();

            Assert.Null(bestBet.GetSchema());
        }