public void Write_should_right_write_all_elements_from_stream()
        {
            //Arange
            //Act
            _libraryWriter.Write(GetMockedCorectLibraryElements(), "MyLibrary");
            _libraryWriter.Close();

            var resultString = Regex.Replace(File.ReadAllText(_path), @"\t|\n|\r", "");
            var mockedString = Regex.Replace(GetMockedXmlString(), @"\t|\n|\r", "");

            //Assert
            Assert.AreEqual(resultString, mockedString);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            #region Library reader
            //LibraryReader lreader = new LibraryReader(File.OpenRead($@"{Directory.GetCurrentDirectory()}\library.xml"), $@"{Directory.GetCurrentDirectory()}\library.xsd");
            //foreach (LibraryElement el in lreader)
            //{
            //    Console.WriteLine(el.Name);
            //    Console.WriteLine(el.PagesCount);
            //    Console.WriteLine(el.Note);
            //}

            //var books = lreader.Where(element => element.GetType() == typeof(Book)).Select(element => (Book)element);
            //foreach (var book in books)
            //{
            //    Console.WriteLine(book.Name);
            //    Console.WriteLine(book.PagesCount);
            //    Console.WriteLine(book.Note);
            //    Console.WriteLine(book.InternationNumber);
            //    Console.WriteLine(book.Autor);
            //    Console.WriteLine(book.PublishingYear);
            //}

            //lreader.Close();

            #endregion

            #region Library writer

            FileStream            fs = new FileStream($"{Directory.GetCurrentDirectory()}\\MyLibrary.xml", FileMode.Create, FileAccess.Write);
            LibraryWriter         lw = new LibraryWriter(fs);
            List <LibraryElement> libraryElements = new List <LibraryElement>()
            {
                new Book
                {
                    Name              = "test",
                    Note              = "test",
                    PagesCount        = 500,
                    Autor             = "test",
                    InternationNumber = "test",
                    PublishingHouse   = "test",
                    PublishingName    = "test",
                    //PublishingYear = 2018
                }
            };
            lw.Write(libraryElements, "TestWriter");
            //lw.Close();

            #endregion

            Console.ReadLine();
        }
Exemplo n.º 3
0
        public void Write()
        {
            using (Stream targetStream = new MemoryStream())
            {
                var songs = new[] { Helpers.LocalSong1, Helpers.LocalSong2 };

                var playlists = new[] { Helpers.Playlist1, Helpers.Playlist2 };

                LibraryWriter.Write(songs, playlists, targetStream);

                string expected = Helpers.GenerateSaveFile();
                string actual   = Helpers.StreamToString(targetStream).Replace("\r\n", String.Empty);

                Assert.AreEqual(expected, actual);
            }
        }
        public void Write_should_write_empty_file_without_elements()
        {
            //Arange
            var path        = $"{Directory.GetCurrentDirectory()}\\BrokenLibrary.xml";
            var streamWrite = new FileStream(path, FileMode.Create, FileAccess.Write);
            //Act
            var libraryWriter = new LibraryWriter(streamWrite);

            libraryWriter.Write(GetMockedUnCorectLibraryElements(), "BrokenLibrary");
            libraryWriter.Close();
            var streamRead    = new FileStream(path, FileMode.Open, FileAccess.Read);
            var libraryReader = new LibraryReader(streamRead, _schemaPath);

            libraryReader.Close();
            //Assert
            Assert.That(!libraryReader.Any());
        }