public void TestOtherPeople() { // Note: Publication 14560782 was added to OtherPeople.dat to verify // that the software handles the situation where a publication has // no authors listed. Database DB = new Database("Publication Harvester Unit Test"); Harvester harvester = new Harvester(DB); MockNCBI mockNCBI = new MockNCBI("medline"); PublicationTypes ptc = new PublicationTypes( AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes", "PublicationTypes.csv" ); // Reinitialize the database harvester.CreateTables(); // Make an anonymous callback function that keeps track of the callback data int Callbacks = 0; // this will count all of the publications Harvester.GetPublicationsStatus StatusCallback = delegate(int number, int total, int averageTime) { Callbacks++; }; // Make an anonymous callback function to do nothing for GetPublicationsMessage Harvester.GetPublicationsMessage MessageCallback = delegate(string Message, bool StatusBarOnly) { // }; // Make an anonymous callback function to return false for CheckForInterrupt Harvester.CheckForInterrupt InterruptCallback = delegate() { return(false); }; // Create a new person to test string[] names = new string[2]; names[0] = "Klein RG"; names[1] = "Guillemin R"; Person person = new Person("A1234567", "FIRST", "MIDDLE", "LAST", false, names, "Special query for OtherPeople.dat"); person.WriteToDB(DB); double AverageMilliseconds; harvester.GetPublications(mockNCBI, ptc, person, StatusCallback, MessageCallback, InterruptCallback, out AverageMilliseconds); // Verify that the data was written properly int FoundPublications = 0; Publications pubs = new Publications(DB, person, false); if (pubs.PublicationList != null) { foreach (Publication pub in pubs.PublicationList) { FoundPublications++; switch (pub.PMID) { case 12679283: // The weird part of this publication is the second MeSH heading, which is very long Assert.IsTrue(pub.MeSHHeadings.Count == 23); Assert.IsTrue(pub.MeSHHeadings.Contains( "Attention Deficit and Disruptive Behavior Disorders/etiology/*prevention & control/psychology")); break; case 2417121: // The weird part of this publication is the date, which has a weird format that causes // the day to be long Assert.IsTrue(pub.Day == "19-1986 Jan 1"); break; case 6148773: // One of the headers is long Assert.IsTrue(pub.MeSHHeadings.Contains("Peptide Fragments/antagonists & inhibitors/chemical synthesis/diagnostic use/isolation & purification/pharmacology/*physiology")); break; case 16291338: // One of the authors is long Assert.IsTrue(pub.Authors.Length == 8); Assert.IsTrue(pub.Authors[7] == "For The Michigan Alliance For The National Children's Study"); break; case 15451956: // Volume is long Assert.IsTrue(pub.Volume == "Suppl Web Exclusives"); break; case 14653276: // Issue is long Assert.IsTrue(pub.Issue == "5 Suppl Nitric Oxide"); break; case 9965612: // Journal name is long Assert.IsTrue(pub.Journal == "PHYSICAL REVIEW. E. STATISTICAL PHYSICS, PLASMAS, FLUIDS, AND RELATED INTERDISCIPLINARY TOPICS"); break; case 9469584: // Title is long Assert.IsTrue(pub.Title == Database.Left("Down-regulation of cholesterol biosynthesis in sitosterolemia: diminished activities of acetoacetyl-CoA thiolase, 3-hydroxy-3-methylglutaryl-CoA synthase, reductase, squalene synthase, and 7-dehydrocholesterol delta7-reductase in liver and mononuclear leukocytes." , 244)); break; case 2545230: // Month is long Assert.IsTrue(pub.Month == "Spring-Summer"); break; default: break; } } } Assert.IsTrue(FoundPublications == 13); }
/// <summary> /// Set up the database with data from Input1.XLS using the Mock NCBI object /// (this is also called from TestReports()) /// </summary> /// <param name="NCBISearchThrowsAnError">True if the MockNCBI object is supposed to throw an error</param> public static void GetPublicationsFromInput1XLS_Using_MockNCBI(bool NCBISearchThrowsAnError, string[] Languages, int ExpectedPublications) { bool TablesCreated; int NumPeople; int NumHarvestedPeople; int NumPublications; int NumErrors; Database DB = new Database("Publication Harvester Unit Test"); // Drop all tables and make sure the database reports as empty foreach (string Table in new string[] { "meshheadings", "people", "peoplepublications", "publicationauthors", "publicationmeshheadings", "publications", "pubtypecategories" }) { DB.ExecuteNonQuery("DROP TABLE IF EXISTS " + Table); DB.GetStatus(out TablesCreated, out NumPeople, out NumHarvestedPeople, out NumPublications, out NumErrors); Assert.IsFalse(TablesCreated); Assert.AreEqual(NumPeople, 0); Assert.AreEqual(NumHarvestedPeople, 0); Assert.AreEqual(NumPublications, 0); Assert.AreEqual(NumErrors, 0); } // Create and populate the tables Harvester harvester = new Harvester(DB); harvester.Languages = Languages; MockNCBI mockNCBI = new MockNCBI("medline"); mockNCBI.SearchThrowsAnError = NCBISearchThrowsAnError; PublicationTypes ptc = new PublicationTypes( AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPublicationTypes", "PublicationTypes.csv" ); // Reinitialize the database harvester.CreateTables(); ptc.WriteToDB(DB); // Retrieve the publications for each person in input1.xls using GetPublications() People PeopleFromFile = new People( AppDomain.CurrentDomain.BaseDirectory + "\\Unit Tests\\TestPeople", "input1.xls"); // Make an anonymous callback function that keeps track of the callback data int Callbacks = 0; // this will count all of the publications Harvester.GetPublicationsStatus StatusCallback = delegate(int number, int total, int averageTime) { Callbacks++; }; // Make an anonymous callback function to do nothing for GetPublicationsMessage Harvester.GetPublicationsMessage MessageCallback = delegate(string Message, bool StatusBarOnly) { // }; // Make an anonymous callback function to return false for CheckForInterrupt Harvester.CheckForInterrupt InterruptCallback = delegate() { return(false); }; // Verify that the database was created and populated properly DB.GetStatus(out TablesCreated, out NumPeople, out NumHarvestedPeople, out NumPublications, out NumErrors); Assert.IsTrue(TablesCreated); Assert.AreEqual(NumPeople, 0); Assert.AreEqual(NumHarvestedPeople, 0); Assert.AreEqual(NumPublications, 0); Assert.AreEqual(NumErrors, 0); int PeopleCount = 0; int HarvestedCount = 0; int PubCount = 0; foreach (Person person in PeopleFromFile.PersonList) { double AverageMilliseconds; // First write the person to the database person.WriteToDB(DB); PeopleCount++; // Check that the database status is updated properly DB.GetStatus(out TablesCreated, out NumPeople, out NumHarvestedPeople, out NumPublications, out NumErrors); Assert.IsTrue(TablesCreated); Assert.AreEqual(NumPeople, PeopleCount); if (!NCBISearchThrowsAnError) { Assert.AreEqual(NumHarvestedPeople, HarvestedCount); } else { Assert.AreEqual(NumHarvestedPeople, 0); } Assert.AreEqual(NumPublications, PubCount); if (!NCBISearchThrowsAnError) { Assert.AreEqual(NumErrors, 0); } else { Assert.AreEqual(NumErrors, PeopleCount - 1); } // Harvest the person's publications PubCount += harvester.GetPublications(mockNCBI, ptc, person, StatusCallback, MessageCallback, InterruptCallback, out AverageMilliseconds); HarvestedCount++; // Check the status again after the people were harvested DB.GetStatus(out TablesCreated, out NumPeople, out NumHarvestedPeople, out NumPublications, out NumErrors); Assert.IsTrue(TablesCreated); Assert.AreEqual(NumPeople, PeopleCount); if (!NCBISearchThrowsAnError) { Assert.AreEqual(NumHarvestedPeople, HarvestedCount); } else { Assert.AreEqual(NumHarvestedPeople, 0); } Assert.AreEqual(NumPublications, PubCount); if (!NCBISearchThrowsAnError) { Assert.AreEqual(NumErrors, 0); } else { Assert.AreEqual(NumErrors, PeopleCount); } } // Verify that the database was written properly if (!NCBISearchThrowsAnError) { Assert.IsTrue(Callbacks == 24); } else { Assert.IsTrue(Callbacks == 0); } DB.GetStatus(out TablesCreated, out NumPeople, out NumHarvestedPeople, out NumPublications, out NumErrors); Assert.IsTrue(TablesCreated); Assert.AreEqual(NumPeople, 4); if (!NCBISearchThrowsAnError) { Assert.AreEqual(NumHarvestedPeople, 4); Assert.AreEqual(NumPublications, ExpectedPublications); Assert.AreEqual(NumErrors, 0); } else { Assert.AreEqual(NumHarvestedPeople, 0); Assert.AreEqual(NumPublications, 0); Assert.AreEqual(NumErrors, 4); } }