public virtual void Write(IList <Song> songs) { Messenger.Post("Writing " + songs.Count + " songs"); var persisted = new List <PersistedSong>(); foreach (var song in songs) { persisted.Add(new PersistedSong(song)); } var stream = new StreamWriter(filename, false); try { serializer.Serialize(stream, persisted); stream.Flush(); } catch (Exception e) { Messenger.Post("Error occured! " + e.Message); } finally { stream.Close(); stream.Dispose(); } }
public static string GenerateSaveFile() { using (var stream = new MemoryStream()) { LibrarySerializer.Serialize(new[] { LocalSong1, LocalSong2 }, new[] { Playlist1, Playlist2 }, SongSourcePath, stream); return(Encoding.UTF8.GetString(stream.ToArray())); } }
public void SmokeTest() { using (Stream targetStream = new MemoryStream()) { var songs = new[] { Helpers.LocalSong1, Helpers.LocalSong2 }; var playlists = new[] { Helpers.Playlist1, Helpers.Playlist2 }; LibrarySerializer.Serialize(songs, playlists, Helpers.SongSourcePath, targetStream); string expected = Helpers.GenerateSaveFile(); string actual = Helpers.StreamToString(targetStream).Replace("\r\n", String.Empty); Assert.Equal(expected, actual); } }