コード例 #1
0
        public void Serialize_ItemTitleSerializedCorrect_True()
        {
            var sb = new StringBuilder()
                     .AppendLine("[playlist]")
                     .AppendLine()
                     .AppendLine("File1=test path")
                     .AppendLine("Title1=test title")
                     .AppendLine()
                     .AppendLine("NumberOfEntries=1")
                     .AppendLine("Version=2");

            var serializer = new PlsSerializer();
            var pls        = new PlsPlaylist
            {
                Version = "2"
            };

            pls.Add(new PlsItem("test path")
            {
                Title = "test title"
            });

            var result = serializer.Serialize(pls);

            sb.ToString().Should().Be(result);
        }
コード例 #2
0
        public void Serialize_LengthNotNumberBecomesZero_True()
        {
            var sb = new StringBuilder()
                     .AppendLine("[playlist]")
                     .AppendLine()
                     .AppendLine("File1=test path")
                     .AppendLine("Length1=0")
                     .AppendLine()
                     .AppendLine("NumberOfEntries=1")
                     .AppendLine("Version=2");

            var serializer = new PlsSerializer();
            var pls        = new PlsPlaylist
            {
                Version = "2"
            };

            pls.Add(new PlsItem("test path")
            {
                Length = "sgsgsgsg"
            });

            var result = serializer.Serialize(pls);

            sb.ToString().Should().Be(result);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        public void Serialize_EmptyPlaylistCorrectSerialized_True()
        {
            var sb = new StringBuilder()
                     .AppendLine("[playlist]")
                     .AppendLine()
                     .AppendLine("NumberOfEntries=0")
                     .AppendLine("Version=2");
            var serializer = new PlsSerializer();

            var result = serializer.Serialize(new PlsPlaylist());

            sb.ToString().Should().Be(result);
        }
コード例 #5
0
        public void Serialize_EmptyPlaylistCorrectSerialized_True()
        {
            var sb = new StringBuilder();

            sb.AppendLine("[playlist]");
            sb.AppendLine();
            sb.AppendLine($"NumberOfEntries={0}");
            sb.AppendLine($"Version=2");

            var serializer = new PlsSerializer();
            var result     = serializer.Serialize(new PlsPlaylist());

            Assert.Equal(sb.ToString(), result);
        }
コード例 #6
0
        public void Serialize_VersionNotNumberBecomesTwo_True()
        {
            var sb = new StringBuilder()
                     .AppendLine("[playlist]")
                     .AppendLine()
                     .AppendLine("NumberOfEntries=0")
                     .AppendLine("Version=2");

            var serializer = new PlsSerializer();
            var result     = serializer.Serialize(new PlsPlaylist()
            {
                Version = "ete"
            });

            sb.ToString().Should().Be(result);
        }
コード例 #7
0
        public void Serialize_VersionNotNumberBecomesTwo_True()
        {
            var sb = new StringBuilder();

            sb.AppendLine("[playlist]");
            sb.AppendLine();
            sb.AppendLine($"NumberOfEntries={0}");
            sb.AppendLine($"Version=2");

            var serializer = new PlsSerializer();
            var result     = serializer.Serialize(new PlsPlaylist()
            {
                Version = "ete"
            });

            Assert.Equal(sb.ToString(), result);
        }
コード例 #8
0
        public void Serialize_CorrectNumberOfEntries_True()
        {
            var pls = new PlsPlaylist
            {
                Version = "2"
            };

            pls.Add(new PlsItem("test path")
            {
                Title  = "test title",
                Length = "sgsgsgsg"
            });
            pls.Add(new PlsItem("test path")
            {
                Title  = "test title2",
                Length = "10"
            });
            var serializer = new PlsSerializer();

            var result = serializer.Serialize(pls);

            result.Should().Contain("NumberOfEntries=2");
        }
コード例 #9
0
        public void Serialize_NullInput_ArgumentNullExceptionThrown()
        {
            var serializer = new PlsSerializer();

            Assert.Throws <ArgumentNullException>(() => serializer.Serialize(null));
        }