Ejemplo n.º 1
0
            public void Export_NewFileWithExpectedContenCreated()
            {
                string fileName = $"/{nameof(Song)}.xml";
                var    worker   = new XMLImportExport <Song>();
                var    songs    = new HashSet <Song>()
                {
                    new Song {
                        Path = "Somepathlol"
                    },
                    new Song {
                        Path = "Somepathlol2"
                    }
                };

                worker.Export(songs, fileName);
                var expected = new StringBuilder();

                expected.Append("<?xml version=\"1.0\"?>\r\n<ArrayOfSong xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">");
                foreach (var song in songs)
                {
                    expected.AppendFormat("\r\n  <Song>\r\n    <Path>{0}</Path>\r\n    <Lenght>0</Lenght>\r\n    <Year>0</Year>\r\n  </Song>", song.Path);
                }
                expected.Append("\r\n</ArrayOfSong>");

                string actual;

                using (var reader = new StreamReader(fileName))
                {
                    actual = reader.ReadToEnd();
                }

                Assert.AreEqual(expected.ToString(), actual);
            }
Ejemplo n.º 2
0
            public void Import_ValidFile_ReturnsCorrectlyDeserealizedSongs()
            {
                string fileName = $"/{nameof(Song)}.xml";
                var    worker   = new XMLImportExport <Song>();
                var    songs    = new HashSet <Song>
                {
                    new Song {
                        Path = "Somepathlol"
                    },
                    new Song {
                        Path = "Somepathlol2"
                    }
                };

                worker.Export(songs, fileName);
                string absolutePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);

                var actual = worker.Import(absolutePath);

                CollectionAssert.AreEqual(songs, actual);
            }