Example #1
0
        public void TestGoogleSearchEmptyQuery()
        {
            List <Category> cat = new List <Category>()
            {
                // first one searches www.nhs.uk and rcgp.org.uk
                new Category("Test", new List <string>()
                {
                    "healthline.com",
                    "NIH.gov",
                    "CDC.gov",
                    "drugs.com",
                    "WHO.int",
                    "medlineplus.gov",
                    "hopkinsmedicine.org",
                    "www.bad.org.uk",
                    "www.pcds.org.uk",
                    "www.ukdctn.org",
                    "bdng.org.uk",
                    "www.aan.com",
                    "www.thebrainmatters.org",
                    "www.neuroguide.com",
                    "www.wfneurology.org",
                    "www.neurology.co.in",
                    "aaa.org",
                    "apexcardiology.com",
                    "bhvci.com",
                    "pacificheart.com",
                    "gpnotebook.com",
                    "bnf.nice.org.uk",
                    "bnfc.nice.org.uk",
                    "products.mhra.gov.uk",
                    "www.hee.nhs.uk",
                    "www.sign.ac.uk"
                }, true)
            };

            Program.categories = cat;
            Program.LoadWhitelist();
            List <Result> ret = GoogleAPIHandler.Search("");

            Assert.IsTrue(ret.Count() == 1);
            Assert.IsTrue(ret[0].Title == "Not enough links?");
            Assert.IsTrue(ret[0].Snippet == "");
        }
Example #2
0
        public void TestGoogleSearch()
        {
            // only 2 categories and both are ticked.
            List <Category> cat = new List <Category>()
            {
                // first one searches www.nhs.uk and rcgp.org.uk
                new Category("Test", new List <string>()
                {
                    "healthline.com",
                    "NIH.gov",
                    "CDC.gov",
                    "drugs.com",
                    "WHO.int",
                    "medlineplus.gov",
                    "hopkinsmedicine.org",
                    "www.bad.org.uk",
                    "www.pcds.org.uk",
                    "www.ukdctn.org",
                    "bdng.org.uk",
                    "www.aan.com",
                    "www.thebrainmatters.org",
                    "www.neuroguide.com",
                    "www.wfneurology.org",
                    "www.neurology.co.in",
                    "aaa.org",
                    "apexcardiology.com",
                    "bhvci.com",
                    "pacificheart.com",
                    "gpnotebook.com",
                    "bnf.nice.org.uk",
                    "bnfc.nice.org.uk",
                    "products.mhra.gov.uk",
                    "www.hee.nhs.uk",
                    "www.sign.ac.uk"
                }, true),
                // searches bnf.nice.org.uk
                new Category("Test2", new List <string>()
                {
                    "healthline.com",
                    "NIH.gov",
                    "CDC.gov",
                    "drugs.com",
                    "WHO.int",
                    "medlineplus.gov",
                    "hopkinsmedicine.org",
                    "www.bad.org.uk",
                    "www.pcds.org.uk",
                    "www.ukdctn.org",
                    "bdng.org.uk",
                    "www.aan.com",
                    "www.thebrainmatters.org",
                    "www.neuroguide.com",
                    "www.wfneurology.org",
                    "www.neurology.co.in",
                    "aaa.org",
                    "apexcardiology.com",
                    "bhvci.com",
                    "pacificheart.com",
                    "gpnotebook.com",
                    "bnfc.nice.org.uk",
                    "products.mhra.gov.uk",
                    "www.hee.nhs.uk",
                    "www.sign.ac.uk",
                    "www.nhs.uk",
                    "rcgp.org.uk"
                }, true)
            };
            string query = "kidney disease";

            Program.categories = cat;
            Program.LoadWhitelist();
            List <Result> ret = GoogleAPIHandler.Search(query);
            // By using Googles "Try it out" CSE API online i was able to obtain a list of results that google returns for the query and categories. There are 20 results but
            // we can be reasonable sure that it is working by checking if the top 6 results match to the ones that GoogleAPIHandler.Search returns.
            List <Result> expected = new List <Result>()
            {
                new Result
                {
                    Title   = "Chronic kidney disease - Treatment - NHS",
                    Link    = "https://www.nhs.uk/conditions/kidney-disease/treatment/",
                    Snippet = "Find out about the main treatments for chronic kidney disease (CKD), including \nlifestyle changes, medication, dialysis and kidney transplants.",
                    RecommendationsNumber = 0
                },
                new Result
                {
                    Title   = "Chronic kidney disease - Symptoms - NHS",
                    Link    = "https://www.nhs.uk/conditions/kidney-disease/symptoms/",
                    Snippet = "Find out about the main symptoms of chronic kidney disease (CKD) and when to \nget medical advice.",
                    RecommendationsNumber = 0
                },
                new Result
                {
                    Title   = "Chronic kidney disease - NHS",
                    Link    = "https://www.nhs.uk/conditions/kidney-disease/",
                    Snippet = "Find out what chronic kidney disease (CKD) is, including what the symptoms are, \nhow it's diagnosed and how it can be treated.",
                    RecommendationsNumber = 0
                },
                new Result
                {
                    Title   = "Autosomal recessive polycystic kidney disease - NHS",
                    Link    = "https://www.nhs.uk/conditions/autosomal-recessive-polycystic-kidney-disease-arpkd/",
                    Snippet = "Autosomal recessive polycystic kidney disease (ARPKD) is a rare inherited \nchildhood condition where the development of the kidneys and liver is abnormal.",
                    RecommendationsNumber = 0
                },
                new Result
                {
                    Title   = "Chronic kidney disease - Diagnosis - NHS",
                    Link    = "https://www.nhs.uk/conditions/kidney-disease/diagnosis/",
                    Snippet = "Find out how chronic kidney disease (CKD) is diagnosed, who should get tested \nand what the stages of CKD mean.",
                    RecommendationsNumber = 0
                },
                new Result
                {
                    Title   = "Autosomal dominant polycystic kidney disease - Symptoms - NHS",
                    Link    = "https://www.nhs.uk/conditions/autosomal-dominant-polycystic-kidney-disease-adpkd/symptoms/",
                    Snippet = "Read about the symptoms of autosomal dominant polycystic kidney disease (\nADPKD), including pain in your abdomen, side or lower back, blood in your urine\n�...",
                    RecommendationsNumber = 0
                }
            };

            foreach (int i in Enumerable.Range(0, 6))
            {
                Assert.AreEqual(ret[i].Title, expected[i].Title);
                Assert.AreEqual(ret[i].Link, expected[i].Link);
                Assert.AreEqual(ret[i].Snippet, expected[i].Snippet);
            }
        }