Beispiel #1
0
        public void CheckReadFromXml()
        {
            var          expectedBook      = GetBookEntity();
            var          expectedNewspaper = GetNewspaperEntity();
            var          expectedPatent    = GetPatentEntity();
            StringReader stringReader      = new StringReader(GetXmlToRead());

            var actualResult = librarySystem.ReadFrom(stringReader);

            stringReader.Dispose();
            var actualBook      = (Book)actualResult.ToList().Where(x => x.GetType() == typeof(Book)).FirstOrDefault();
            var actualNewspaper = (Newspaper)actualResult.ToList().Where(x => x.GetType() == typeof(Newspaper)).FirstOrDefault();
            var actualPatent    = (Patent)actualResult.ToList().Where(x => x.GetType() == typeof(Patent)).FirstOrDefault();

            Assert.IsTrue(expectedBook.Name == actualBook.Name &&
                          expectedBook.Authors.FirstOrDefault().FirstName == actualBook.Authors.FirstOrDefault().FirstName&&
                          expectedBook.Authors.FirstOrDefault().LastName == actualBook.Authors.FirstOrDefault().LastName&&
                          expectedBook.PlaceOfPublishing == actualBook.PlaceOfPublishing &&
                          expectedBook.PublishingHouse == expectedBook.PublishingHouse &&
                          expectedBook.YearOfPublishing == actualBook.YearOfPublishing &&
                          expectedBook.Notes == actualBook.Notes &&
                          expectedBook.CountOfPages == actualBook.CountOfPages &&
                          expectedBook.ISBN == actualBook.ISBN,
                          "Actual parsed book is different from expected.");

            Assert.IsTrue(expectedNewspaper.Name == actualNewspaper.Name &&
                          expectedNewspaper.PlaceOfPublishing == actualNewspaper.PlaceOfPublishing &&
                          expectedNewspaper.PublishingHouse == expectedNewspaper.PublishingHouse &&
                          expectedNewspaper.YearOfPublishing == actualNewspaper.YearOfPublishing &&
                          expectedNewspaper.CountOfPages == actualNewspaper.CountOfPages &&
                          expectedNewspaper.Number == actualNewspaper.Number &&
                          expectedNewspaper.Date == actualNewspaper.Date &&
                          expectedNewspaper.Notes == actualNewspaper.Notes &&
                          expectedNewspaper.ISBN == actualNewspaper.ISBN,
                          "Actual parsed newspaper is different from expected.");

            Assert.IsTrue(expectedPatent.Name == actualPatent.Name &&
                          expectedPatent.Authors.FirstOrDefault().FirstName == actualPatent.Authors.FirstOrDefault().FirstName&&
                          expectedPatent.Authors.FirstOrDefault().LastName == actualPatent.Authors.FirstOrDefault().LastName&&
                          expectedPatent.Country == actualPatent.Country &&
                          expectedPatent.RegistrationNumber == actualPatent.RegistrationNumber &&
                          expectedPatent.ApplicationDate == actualPatent.ApplicationDate &&
                          expectedPatent.Notes == actualPatent.Notes &&
                          expectedPatent.CountOfPages == actualPatent.CountOfPages &&
                          expectedPatent.DateOfPublication == actualPatent.DateOfPublication,
                          "Actual parsed patent is different from expected.");
        }
Beispiel #2
0
        /// <summary>
        /// TODO:
        /// - Move pathes to config file
        /// - XmlValidationException handling (try/catch)
        /// </summary>
        static void Main(string[] args)
        {
            var            pathToXmlToReadFrom = @"D:\1.xml";
            var            pathToXmlToWriteIn  = @"D:\2.xml";
            List <IEntity> entities            = new List <IEntity>();

            ReadWriteLibrarySystem librarySystem = new ReadWriteLibrarySystem();

            using (StreamReader sr = new StreamReader(pathToXmlToReadFrom))
            {
                entities = librarySystem.ReadFrom(sr).ToList();
            }

            using (StreamWriter sr = new StreamWriter(pathToXmlToWriteIn))
            {
                librarySystem.WriteTo(entities, sr, true);
            }
        }