Exemple #1
0
        public void GetEnumeratorTest()
        {
            FileMARCXML target = new FileMARCXML();
            IEnumerator actual = target.GetEnumerator();

            Assert.IsInstanceOfType(actual, typeof(IEnumerator));
        }
Exemple #2
0
        public void FileMARCXMLConstructorTest()
        {
            FileMARCXML target   = new FileMARCXML();
            int         expected = 0;
            int         actual   = target.RawSource.Count;

            Assert.AreEqual(expected, actual);
        }
Exemple #3
0
        public void RawSourceTest()
        {
            FileMARCXML target = new FileMARCXML();

            target.ImportMARCXML("sandburg.xml");
            string expected = XDocument.Load("sandburg.xml").Elements().First(e => e.Name.LocalName == "collection").Elements().First(e => e.Name.LocalName == "record").ToString();
            string actual   = target.RawSource[0].ToString();

            Assert.AreEqual(expected, actual);
        }
Exemple #4
0
        public void CountTest()
        {
            FileMARCXML target = new FileMARCXML();

            target.ImportMARCXML("sandburg.xml");
            target.ImportMARCXML("bigarchive.xml");
            int expected = 2;
            int actual   = target.Count;

            Assert.AreEqual(expected, actual);
        }
Exemple #5
0
        public void ItemTest()
        {
            FileMARCXML target = new FileMARCXML();

            target.ImportMARCXML("sandburg.xml");
            int    index         = 0;
            Record recordAtIndex = target[index];
            string expected      = "01142cam  2200301 a 4500001001300000003000400013005001700017008004100034010001700075020002500092040001800117042000900135050002600144082001600170100003200186245008600218250001200304260005200316300004900368500004000417520022800457650003300685650003300718650002400751650002100775650002300796700002100819   92005291 DLC19930521155141.9920219s1993    caua   j      000 0 eng    a   92005291   a0152038655 :c$15.95  aDLCcDLCdDLC  alcac00aPS3537.A618bA88 199300a811/.522201 aSandburg, Carl,d1878-1967.10aArithmetic /cCarl Sandburg ; illustrated as an anamorphic adventure by Ted Rand.  a1st ed.  aSan Diego :bHarcourt Brace Jovanovich,cc1993.  a1 v. (unpaged) :bill. (some col.) ;c26 cm.  aOne Mylar sheet included in pocket.  aA poem about numbers and their characteristics. Features anamorphic, or distorted, drawings which can be restored to normal by viewing from a particular angle or by viewing the image's reflection in the provided Mylar cone. 0aArithmeticxJuvenile poetry. 0aChildren's poetry, American. 1aArithmeticxPoetry. 1aAmerican poetry. 1aVisual perception.1 aRand, Ted,eill.";
            string actual        = recordAtIndex.ToRaw();

            Assert.AreEqual(expected, actual);
        }
Exemple #6
0
        public void ToXMLTest()
        {
            string      source    = File.ReadAllText("sandburg.xml");
            FileMARCXML targetXML = new FileMARCXML(source);
            Record      target    = targetXML[0];

            XDocument xdoc     = XDocument.Parse(source);
            XElement  expected = xdoc.Elements().First(e => e.Name.LocalName == "collection").Elements().First(e => e.Name.LocalName == "record");
            XElement  actual   = target.ToXML();

            Assert.IsTrue(XNode.DeepEquals(expected, actual));
        }
Exemple #7
0
        public void ResetTest()
        {
            FileMARCXML target = new FileMARCXML();

            target.ImportMARCXML("sandburg.xml");
            target.ImportMARCXML("bigarchive.xml");
            target.MoveNext();
            target.MoveNext();
            target.MoveNext();
            target.Reset();
            target.MoveNext();
            bool expected = true;
            bool actual   = target.MoveNext();

            Assert.AreEqual(expected, actual);
        }
Exemple #8
0
        public void ToXMLDocumentTest()
        {
            string      source    = File.ReadAllText("onerecord.xml");
            FileMARCXML targetXML = new FileMARCXML(source);
            Record      target    = targetXML[0];

            string    expected = source;
            XDocument xdoc     = target.ToXMLDocument();

            using (StringWriter writer = new Utf8StringWriter())
            {
                xdoc.Save(writer);
                string actual = writer.ToString();
                Assert.AreEqual(expected, actual);
            }
        }
Exemple #9
0
        public void AddTest1()
        {
            FileMARCXML target = new FileMARCXML();
            string      source = File.ReadAllText("sandburg.xml");

            {
                int expected = 1;
                int actual   = target.Add(source);
                Assert.AreEqual(expected, actual);
            }

            {
                string expected = XDocument.Parse(source).Elements().First(e => e.Name.LocalName == "collection").Elements().First(e => e.Name.LocalName == "record").ToString();
                string actual   = target.RawSource[0].ToString();
                Assert.AreEqual(expected, actual);
            }
        }
Exemple #10
0
        public void FileMARCXMLConstructorTest2()
        {
            XDocument   source = XDocument.Load("sandburg.xml");
            FileMARCXML target = new FileMARCXML(source);

            {
                int expected = 1;
                int actual   = target.RawSource.Count;
                Assert.AreEqual(expected, actual);
            }

            {
                string expected = source.Elements().First(e => e.Name.LocalName == "collection").Elements().First(e => e.Name.LocalName == "record").ToString();
                string actual   = target.RawSource[0].ToString();
                Assert.AreEqual(expected, actual);
            }
        }
Exemple #11
0
        public void ValidateTest()
        {
            {
                XDocument     source   = XDocument.Load("sandburg.xml");
                List <string> errors   = FileMARCXML.Validate(source);
                int           expected = 0;
                int           actual   = errors.Count;
                Assert.AreEqual(expected, actual);
            }

            {
                XDocument     source   = XDocument.Load("bad_example.xml");
                List <string> errors   = FileMARCXML.Validate(source);
                int           expected = 4;
                int           actual   = errors.Count;
                Assert.AreEqual(expected, actual);
            }
        }
        public void WriteTest()
        {
            string      filename     = "onerecord.xml";
            string      testFilename = "onerecord_test.xml";
            string      source       = File.ReadAllText(filename);
            FileMARCXML targetXML    = new FileMARCXML(source);
            Record      record       = targetXML[0];

            using (FileMARCXMLWriter target = new FileMARCXMLWriter(testFilename))
            {
                target.Write(record);
            }

            string expected = source;
            string actual   = File.ReadAllText(testFilename);

            Assert.AreEqual(expected, actual);
        }
        public void WriteTest1()
        {
            string        filename     = "music.xml";
            string        testFilename = "music_test.xml";
            string        source       = File.ReadAllText(filename);
            FileMARCXML   targetXML    = new FileMARCXML(source);
            List <Record> records      = new List <Record>();

            foreach (Record record in targetXML)
            {
                records.Add(record);
            }

            using (FileMARCXMLWriter target = new FileMARCXMLWriter(testFilename))
            {
                target.Write(records);
            }

            string expected = source;
            string actual   = File.ReadAllText(testFilename);

            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Handles the Click event of the searchButton control.
        ///
        /// We're no longer using the acutal Z39.50 interface and instead querying using the new fancy Search/Retrieval via URL interface
        /// The specifications for the new interface can be found at http://www.loc.gov/standards/sru/index.html
        /// Information on the query langauge can be found at http://www.loc.gov/standards/sru/specs/cql.html
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void searchButton_Click(object sender, EventArgs e)
        {
            searchResultsDataGridView.Rows.Clear();

            if (!String.IsNullOrEmpty(isbnTextBox.Text) || !String.IsNullOrEmpty(lccnTextBox.Text) || !String.IsNullOrEmpty(titleTextBox.Text) || !String.IsNullOrEmpty(authorTextBox.Text))
            {
                searchGroupBox.Enabled = false;
                searchButton.Text      = "Searching ...";
                Application.DoEvents();

                searchResultsDataGridView.Rows.Clear();
                DisableImport();

                //The default ZING SRW namespace
                XNamespace zingSRW = namespaceTextBox.Text;

                //Build the SRU query.
                //The address, version, and operation will always be the same
                string sruServer = serverTextBox.Text;

                string sruQuery = string.Empty;

                if (locRadioButton.Checked)
                {
                    //The actual query in CQL syntax
                    if (titleTextBox.Text.Trim() != string.Empty)
                    {
                        sruQuery += " and dc.title%20=%20%22" + titleTextBox.Text.Trim() + "%22";
                    }

                    if (authorTextBox.Text.Trim() != string.Empty)
                    {
                        sruQuery += " and dc.author%20=%20%22" + authorTextBox.Text.Trim() + "%22";
                    }

                    if (lccnTextBox.Text.Trim() != string.Empty)
                    {
                        sruQuery += " and bath.lccn%20=%20" + lccnTextBox.Text.Trim();
                    }

                    if (isbnTextBox.Text.Trim() != string.Empty)
                    {
                        sruQuery += " and bath.isbn%20=%20" + isbnTextBox.Text.Trim();
                    }
                }
                else if (oclcRadioButton.Checked)
                {
                    //The actual query in CQL syntax
                    if (titleTextBox.Text.Trim() != string.Empty)
                    {
                        sruQuery += " and srw.ti%20=%20%22" + titleTextBox.Text.Trim() + "%22";
                    }

                    if (authorTextBox.Text.Trim() != string.Empty)
                    {
                        sruQuery += " and srw.au%20=%20%22" + authorTextBox.Text.Trim() + "%22";
                    }

                    if (lccnTextBox.Text.Trim() != string.Empty)
                    {
                        sruQuery += " and srw.dn%20=%20" + lccnTextBox.Text.Trim();
                    }

                    if (isbnTextBox.Text.Trim() != string.Empty)
                    {
                        sruQuery += " and srw.bn%20=%20" + isbnTextBox.Text.Trim();
                    }

                    sruQuery += "&wskey=" + oclcTextBox.Text;
                }

                //Maximum records and record schema will always be the same. We get records back in actual MARCXML format making it easy to parse into a BookMaster record
                string sruPostfix = "&maximumRecords=200&recordSchema=marcxml";

                if (sruQuery != string.Empty)
                {
                    sruQuery = sruQuery.Substring(5);

                    try
                    {
                        //This actually queries the server. No more ZOOM. No more VB wrapping C++. It's that easy.
                        XDocument results = XDocument.Load(sruServer + sruQuery + sruPostfix);

                        //The actual search results that we want to search for are 3 levels down.
                        //<zs:searchRetrieveResponse><zs:records><zs:record>Actual result information is here</zs:record></zs:records></zs:searchRetrieveResponse>
                        foreach (XElement result in results.Elements(zingSRW + "searchRetrieveResponse").Elements(zingSRW + "records").Elements(zingSRW + "record"))
                        {
                            //Build an XDocument for each result
                            //The actual data is 2 levesl down from the search result item.
                            //<zs:recordData><record>Actual MARCXML</record></zs:recordData>
                            XDocument importMARCXML = new XDocument();
                            importMARCXML.Add(result.Element(zingSRW + "recordData").Element(FileMARCXML.Namespace + "record"));

                            //Convert the new MARCXML document to a CSharp_MARC Record
                            FileMARCXML imported       = new FileMARCXML(importMARCXML);
                            Record      importedRecord = imported[0];

                            AddResult(importedRecord);
                        }
                    }
                    catch (WebException)
                    {
                        MessageBox.Show("Unable to access the Library of Congress. Please try again later or click \"Help\" to search the LOC website manually.", "Error accessing LOC", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, "http://z3950.loc.gov", "keyword");
                    }
                }
            }

            SortResults();

            searchButton.Text      = "Search";
            searchGroupBox.Enabled = true;
        }