public void TestPaperCrud() { IDataReader reader; Paper paper = new Paper (); paper.Title = "The refined structure of nascent HDL reveals a key functional domain for particle maturation and dysfunction"; paper.Authors = "Zhiping Wu, Matthew A Wagner, Lemin Zheng, John S Parks, Jacinto M Shy Jr, Jonathan D Smith, Valentin Gogonea & Stanley L Hazen"; paper.Journal = "Nature Structural & Molecular Biology"; paper.Volume = "14"; paper.Pages = "861 - 868"; paper.Year = "2007"; paper.Save (); Assert.That (paper.ID, Is.EqualTo (1)); reader = Database.Query (String.Format ("SELECT title, authors, journal, volume, pages, year, uri, doi FROM papers WHERE id = {0}", paper.ID)); Assert.That (reader, Is.Not.Null); if (reader != null) { reader.Read (); Assert.That (reader.GetString (0), Is.EqualTo (paper.Title)); Assert.That (reader.GetString (1), Is.EqualTo (paper.Authors)); Assert.That (reader.GetString (2), Is.EqualTo (paper.Journal)); Assert.That (reader.GetString (3), Is.EqualTo (paper.Volume)); Assert.That (reader.GetString (4), Is.EqualTo (paper.Pages)); Assert.That (reader.GetString (5), Is.EqualTo (paper.Year)); Assert.That (reader.IsDBNull (6), Is.True); Assert.That (reader.IsDBNull (7), Is.True); reader.Close (); } paper.Uri = "http://www.nature.com/nsmb/journal/v14/n9/abs/nsmb1284.html"; paper.Doi = "10.1038/nsmb1284"; paper.Save (); reader = Database.Query (String.Format ("SELECT uri, doi FROM papers WHERE id = {0}", paper.ID)); Assert.That (reader, Is.Not.Null); if (reader != null) { reader.Read (); Assert.That (reader.GetString (0), Is.EqualTo (paper.Uri)); Assert.That (reader.GetString (1), Is.EqualTo (paper.Doi)); reader.Close (); } paper.Delete (); reader = Database.Query (String.Format ("SELECT title FROM papers WHERE id = {0}", paper.ID)); Assert.That (reader, Is.Null); }
public static void Add(string filename) { Paper paper = new Paper (filename); // FIXME Check for metadata paper.Title = "Unknown"; paper.Authors = "Unknown"; paper.Journal = "Unknown"; paper.Year = "Unknown"; paper.Save (); papers.Add (paper); Log.DebugFormat ("Added new paper (ID = {0}) at '{1}' to database", paper.ID, paper.FilePath); if (PaperAdded != null) PaperAdded (paper); }