private static string SerializePlaylist(IPlaylist playlist, Format fileFormat)
        {
            switch (fileFormat)
            {
            case Format.XSPF:
                var xspfSerializer = new XspfSerializer();
                var xspfPl         = new XspfPlaylist(playlist);
                return(xspfSerializer.Serialize(xspfPl));

            case Format.WPL:
                var wplSerializer = new WplSerializer();
                var wplPlaylist   = new WplPlaylist(playlist);
                return(wplSerializer.Serialize(wplPlaylist));

            case Format.M3U:
                var m3USerializer = new M3uSerializer();
                var m3UPlaylist   = new M3uPlaylist(playlist);
                return(m3USerializer.Serialize(m3UPlaylist));

            case Format.ASX:
                var asxSerializer = new AsxSerializer();
                var asxPlaylist   = new AsxPlaylist(playlist);
                return(asxSerializer.Serialize(asxPlaylist));

            case Format.PLS:
                var plsSerializer = new PlsSerializer();
                var plsPlaylist   = new PlsPlaylist(playlist);
                return(plsSerializer.Serialize(plsPlaylist));
            }

            return(String.Empty);
        }
        public void Conversion_CorrespondWithTheSameAmountOfItems_True()
        {
            var playlist = Substitute.For <IPlaylist>();
            var item     = Substitute.For <IPlaylistItem>();

            playlist.GetGenericItems().Returns(new[] { item });

            var asx = new AsxPlaylist(playlist);

            asx.GetGenericItems().Should().HaveCount(playlist.GetGenericItems().Count());
        }
        public void Serialize_EmptyEntryIsParsed()
        {
            var playlist = new AsxPlaylist();

            playlist.Add(new AsxItem(string.Empty));
            var cleanAsx = @"<asx />";

            var output = serializer.Serialize(playlist);

            Assert.True(output == cleanAsx);
        }
        public void Serialize_VersionIsParsedAsExpected()
        {
            var playlist = new AsxPlaylist {
                Version = "1.0"
            };
            var asxWithVersion = @"<asx version=""1.0"" />";

            var output = serializer.Serialize(playlist);

            Assert.True(output == asxWithVersion);
        }
        public void Serialize_TitleOnlyIsParsedAsExpected_Foo()
        {
            var playlist = new AsxPlaylist {
                Title = "Foo"
            };
            var asxWithTitle = @"<title>Foo</title>";

            var output = serializer.Serialize(playlist);

            Assert.Contains(asxWithTitle, output);
        }
        public void Serialize_EmptyEntryIsParsed()
        {
            var playlist = new AsxPlaylist();

            playlist.Add(new AsxItem(string.Empty));
            var serializer = new AsxSerializer();

            var actual = serializer.Serialize(playlist);

            actual.Should().Be("<asx />");
        }
        public void Serialize_TitleOnlyIsParsedAsExpected_Foo()
        {
            var playlist = new AsxPlaylist {
                Title = "Foo"
            };
            var serializer = new AsxSerializer();

            var output = serializer.Serialize(playlist);

            output.Should().Contain("<title>Foo</title>");
        }
        public void Serialize_VersionIsParsedAsExpected()
        {
            var playlist = new AsxPlaylist {
                Version = "1.0"
            };
            var serializer = new AsxSerializer();

            var output = serializer.Serialize(playlist);

            output.Should().Be(@"<asx version=""1.0"" />");
        }
        public void Conversion_ConvertedPlaylistItemContainsSamePath_Foo()
        {
            var playlist = Substitute.For <IPlaylist>();
            var item     = Substitute.For <IPlaylistItem>();

            item.Path.Returns("Foo");
            playlist.GetGenericItems().Returns(new[] { item });

            var asx = new AsxPlaylist(playlist);

            asx.GetGenericItems().First().Path.Should().Be("Foo");
        }
Example #10
0
        public void Conversion_ConvertedPlaylistContainsInitialTitle_Foo()
        {
            var playlist   = Substitute.For <IPlaylist>();
            var dictionary = new Dictionary <string, string>
            {
                { CommonTags.Author, "Foo" }
            };

            playlist.Tags.Returns(dictionary);

            var asx = new AsxPlaylist(playlist);

            asx.Tags[CommonTags.Author].Should().Be("Foo");
        }
Example #11
0
        public void Conversion_ConvertedPlaylistContainsTitleTag_True()
        {
            var playlist   = Substitute.For <IPlaylist>();
            var dictionary = new Dictionary <string, string>
            {
                { CommonTags.Author, "Foo" }
            };

            playlist.Tags.Returns(dictionary);

            var asx = new AsxPlaylist(playlist);

            asx.Tags.Should().ContainKey(CommonTags.Author);
        }
        public void Conversion_ConvertedPlaylistContainsInitialTitle_Foo()
        {
            var playlist   = Substitute.For <IPlaylist>();
            var dictionary = new Dictionary <string, string>
            {
                { TagNames.Author, "Foo" }
            };

            playlist.Tags.Returns(dictionary);

            var asx = new AsxPlaylist(playlist);

            Assert.True(asx.Tags[TagNames.Author] == "Foo");
        }
Example #13
0
        public void Serialize_OnlyParamIsParsed_FooToBar()
        {
            var playlist = new AsxPlaylist();

            playlist.Add(new AsxItem(string.Empty));
            var asxItem = playlist.Items.First();

            asxItem.Tags["Foo"] = "Bar";
            var serializer = new AsxSerializer();

            var actual = serializer.Serialize(playlist);

            actual.Should().Be("<asx />");
        }
        public void Serialize_OnlyParamIsParsed_FooToBar()
        {
            var playlist = new AsxPlaylist();

            playlist.Add(new AsxItem(string.Empty));
            var asxItem = playlist.Items.First();

            asxItem.Tags["Foo"] = "Bar";

            var asxWithVersion = @"<asx />";

            var output = serializer.Serialize(playlist);

            Assert.True(output == asxWithVersion);
        }
Example #15
0
        public void Conversion_ConvertedPlaylistItemContainsParam_FooToBar()
        {
            var playlist   = Substitute.For <IPlaylist>();
            var item       = Substitute.For <IPlaylistItem>();
            var dictionary = new Dictionary <string, string>
            {
                { "Foo", "Bar" }
            };

            item.Tags.Returns(dictionary);
            playlist.GetGenericItems().Returns(new[] { item });

            var asx = new AsxPlaylist(playlist);

            asx.GetGenericItems().First().Tags["Foo"].Should().Be("Bar");
        }