public void MultipleExtensions_NotDefault() { string playlistDir = Path.Combine(OutputPath, "MultipleExtensions_NotDefault"); IPlaylistHandler expectedHandler = new LegacyPlaylistHandler(); if (Directory.Exists(playlistDir)) { Directory.Delete(playlistDir, true); } Assert.IsFalse(Directory.Exists(playlistDir)); PlaylistManager manager = new PlaylistManager(playlistDir, new MockPlaylistHandler()); Assert.IsNull(manager.GetHandlerForExtension("bplist")); Assert.IsTrue(manager.RegisterHandler(expectedHandler)); Assert.IsTrue(Directory.Exists(playlistDir)); Assert.AreEqual(typeof(MockPlaylistHandler), manager.DefaultHandler?.GetType()); Assert.AreEqual(expectedHandler, manager.GetHandlerForExtension("bplist")); Assert.AreEqual(expectedHandler, manager.GetHandlerForExtension("JsOn")); if (Directory.Exists(playlistDir)) { Directory.Delete(playlistDir, true); } }
public void DeserializeDerivedPlaylist() { string playlistDir = Path.Combine(OutputPath, "DeserializeDerivedPlaylist"); IPlaylistHandler handler = new LegacyPlaylistHandler(); if (Directory.Exists(playlistDir)) { Directory.Delete(playlistDir, true); } Assert.IsFalse(Directory.Exists(playlistDir)); PlaylistManager manager = new PlaylistManager(playlistDir, handler); var songs = CreateSongArray <LegacyPlaylistSong>("Legacy_", "LegacyAuthor_", 1000, Identifier.LevelId | Identifier.Hash | Identifier.Key); IPlaylist? playlist = manager.CreatePlaylist("5LegacySongs", "Five Legacy Songs", "TestAuthor", string.Empty, "Test Description"); foreach (var song in songs) { playlist.Add(song); } playlist.RaisePlaylistChanged(); manager.RegisterPlaylist(playlist); manager.StoreAllPlaylists(); manager = new PlaylistManager(playlistDir, handler); playlist = manager.GetHandler <LegacyPlaylistHandler>()?.Deserialize <DerivedLegacyPlaylist>(File.OpenRead(Path.Combine(playlistDir, "5LegacySongs.bplist"))); if (Directory.Exists(playlistDir)) { Directory.Delete(playlistDir, true); } }
public void DeserializationError() { string playlistDir = Path.Combine(OutputPath, "NoExtension"); IPlaylistHandler handler = new LegacyPlaylistHandler(); PlaylistManager manager = TestTools.GetPlaylistManager(playlistDir, handler); File.Copy(Path.Combine(ReadOnlyData, "InvalidJson.bPlist"), Path.Combine(playlistDir, "InvalidJson.bPlist")); string playlistFileName = "InvalidJson"; Assert.ThrowsException <PlaylistSerializationException>(() => manager.GetPlaylist(playlistFileName)); TestTools.Cleanup(playlistDir); }
public void FileNoExtension() { string playlistDir = Path.Combine(OutputPath, "NoExtension"); IPlaylistHandler handler = new LegacyPlaylistHandler(); PlaylistManager manager = TestTools.GetPlaylistManager(playlistDir, handler); File.Copy(Path.Combine(ReadOnlyData, "NoExtension"), Path.Combine(playlistDir, "NoExtension")); string playlistFileName = "NoExtension"; Assert.IsNull(manager.GetPlaylist(playlistFileName)); TestTools.Cleanup(playlistDir); }
public void EmptyFilename() { string playlistDir = Path.Combine(OutputPath, ""); IPlaylistHandler handler = new LegacyPlaylistHandler(); PlaylistManager manager = TestTools.GetPlaylistManager(playlistDir, handler); string playlistFileName = ""; IPlaylist?playlist = manager.GetPlaylist(playlistFileName); Assert.IsNull(playlist); TestTools.Cleanup(playlistDir); }
public void PassedUnsupportedHandler() { string playlistDir = Path.Combine(OutputPath, "PassedUnsupportedHandler"); IPlaylistHandler defaultHandler = new LegacyPlaylistHandler(); IPlaylistHandler providedHandler = new MockPlaylistHandler(); PlaylistManager manager = TestTools.GetPlaylistManager(playlistDir, defaultHandler); string playlistFileName = "5LegacySongs"; File.Copy(Path.Combine(ReadOnlyData, "5LegacySongs.bPlist"), Path.Combine(playlistDir, "5LegacySongs.bPlist")); Assert.ThrowsException <ArgumentException>(() => manager.GetPlaylist(playlistFileName, false, providedHandler)); TestTools.Cleanup(playlistDir); }
public void NewHandler() { string playlistDir = Path.Combine(OutputPath, "NewHandler"); IPlaylistHandler expectedHandler = new LegacyPlaylistHandler(); PlaylistManager manager = TestTools.GetPlaylistManager(playlistDir, new MockPlaylistHandler()); Assert.IsNull(manager.GetHandlerForExtension("bplist")); Assert.IsNull(manager.GetHandlerForExtension("json")); manager.RegisterHandlerForExtension("json", expectedHandler); Assert.AreEqual(typeof(MockPlaylistHandler), manager.DefaultHandler?.GetType()); Assert.AreEqual(expectedHandler, manager.GetHandlerForExtension("json")); Assert.IsNull(manager.GetHandlerForExtension("bplist")); TestTools.Cleanup(playlistDir); }
public void ExtensionHasCapital() { string playlistDir = Path.Combine(OutputPath, "ExtensionHasCapital"); IPlaylistHandler handler = new LegacyPlaylistHandler(); PlaylistManager manager = TestTools.GetPlaylistManager(playlistDir, handler); string playlistFileName = "5LegacySongs"; File.Copy(Path.Combine(ReadOnlyData, "5LegacySongs.bPlist"), Path.Combine(playlistDir, "5LegacySongs.bPlist")); IPlaylist?playlist = null; playlist = manager.GetPlaylist(playlistFileName); Assert.IsNotNull(playlist); if (playlist == null) { return; } Assert.AreEqual(5, playlist.Count); TestTools.Cleanup(playlistDir); }
public void UnsupportedExtension() { string playlistDir = Path.Combine(OutputPath, "UnsupportedExtension"); IPlaylistHandler handler = new LegacyPlaylistHandler(); if (Directory.Exists(playlistDir)) { Directory.Delete(playlistDir, true); } Assert.IsFalse(Directory.Exists(playlistDir)); PlaylistManager manager = new PlaylistManager(playlistDir, handler); Assert.ThrowsException <ArgumentException>(() => manager.RegisterHandlerForExtension("mock", handler)); if (Directory.Exists(playlistDir)) { Directory.Delete(playlistDir, true); } }
public void ExistingHandlerType() { string playlistDir = Path.Combine(OutputPath, "ExistingHandlerType"); IPlaylistHandler existingHandler = new LegacyPlaylistHandler(); IPlaylistHandler expectedHandler = new LegacyPlaylistHandler(); string extension = "json"; PlaylistManager manager = TestTools.GetPlaylistManager(playlistDir, existingHandler); manager.RegisterHandlerForExtension(extension, expectedHandler); IPlaylistHandler?actualHandler = manager.GetHandlerForExtension(extension); IPlaylistHandler?bplistHandler = manager.GetHandlerForExtension("bplist"); Assert.IsTrue(Directory.Exists(playlistDir)); Assert.AreEqual(expectedHandler, actualHandler); Assert.IsNotNull(bplistHandler); Assert.AreNotEqual(actualHandler, bplistHandler); TestTools.Cleanup(playlistDir); }
public void NullHandler() { string playlistDir = Path.Combine(OutputPath, "NullHandler"); IPlaylistHandler handler = new LegacyPlaylistHandler(); if (Directory.Exists(playlistDir)) { Directory.Delete(playlistDir, true); } Assert.IsFalse(Directory.Exists(playlistDir)); PlaylistManager manager = new PlaylistManager(playlistDir, handler); #pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type. Assert.ThrowsException <ArgumentNullException>(() => manager.RegisterHandlerForExtension("mock", null)); #pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type. if (Directory.Exists(playlistDir)) { Directory.Delete(playlistDir, true); } }