public void LoadSimpleTest()
        {
            ISongFileReader <OpenLyricsSong> target = new OpenLyricsSongFileReader();
            const string filename = "Resources/openlyrics/simple.xml";

            OpenLyricsSong expected = new OpenLyricsSong
            {
                Title             = "Amazing Grace",
                ModifiedTimestamp = "2012-04-10T22:00:00+10:00",
                CreatedIn         = "OpenLP 1.9.0",
                ModifiedIn        = "MyApp 0.0.1"
            };

            OpenLyricsSong.Verse verse = new OpenLyricsSong.Verse
            {
                Name = "v1"
            };

            OpenLyricsSong.TextLines lines = new OpenLyricsSong.TextLines();
            lines.Text.Add("Amazing grace how sweet the sound");
            lines.Text.Add("that saved a wretch like me;");
            verse.Lines.Add(lines);
            expected.Verses.Add(verse);

            var actual = target.Load(filename);

            Assert.AreEqual(expected.Title, actual.Title, "Wrong song title");
            Assert.AreEqual(expected.Title, actual.GetTitle(), "Wrong song title");
            Assert.AreEqual(expected.ModifiedTimestamp, actual.ModifiedTimestamp, "Wrong song modified date");
            Assert.AreEqual(expected.CreatedIn, actual.CreatedIn, "Wrong creator app");
            Assert.AreEqual(expected.ModifiedIn, actual.ModifiedIn, "Wrong modifier app");

            Assert.AreEqual(expected.Verses.Count, actual.Verses.Count, "Parts incomplete");
            for (int i = 0; i < expected.Verses.Count; i++)
            {
                Assert.AreEqual(expected.Verses[i].Name, actual.Verses[i].Name, "Wrong verse name");
                Assert.AreEqual(expected.Verses[i].Lines.Count, actual.Verses[i].Lines.Count, "Slides incomplete");
                for (int j = 0; j < expected.Verses[i].Lines.Count; j++)
                {
                    Assert.AreEqual(expected.Verses[i].Lines[j].Text.Count, actual.Verses[i].Lines[j].Text.Count, "Slide lines incomplete");
                    for (int k = 0; k < expected.Verses[i].Lines[j].Text.Count; k++)
                    {
                        Assert.AreEqual(expected.Verses[i].Lines[j].Text[k], actual.Verses[i].Lines[j].Text[k], "Wrong slide lyrics");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void ParseLyrics(XmlNode verseNode, OpenLyricsSong sng)
        {
            if (verseNode.Name == "verse")
            {
                var verse = new OpenLyricsSong.Verse();
                if (verseNode.Attributes != null && verseNode.Attributes["name"] != null)
                {
                    verse.Name = verseNode.Attributes["name"].InnerText;
                }
                if (verseNode.Attributes != null && verseNode.Attributes["lang"] != null)
                {
                    verse.Language = verseNode.Attributes["lang"].InnerText;
                }

                foreach (XmlNode linesNode in verseNode.ChildNodes)
                {
                    if (linesNode.Name == "lines")
                    {
                        var line = new OpenLyricsSong.TextLines();
                        if (linesNode.Attributes != null && linesNode.Attributes["part"] != null)
                        {
                            line.Part = linesNode.Attributes["part"].InnerText;
                        }
                        var lineText = string.Empty;
                        foreach (XmlNode l in linesNode)
                        {
                            if (l.NodeType == XmlNodeType.Text)
                            {
                                lineText += l.InnerText;
                            }
                            else if (l.NodeType == XmlNodeType.Element && l.Name == "br")
                            {
                                line.Text.Add(lineText);
                                lineText = string.Empty;
                            }
                        }
                        line.Text.Add(lineText);
                        verse.Lines.Add(line);
                    }
                }
                if (verse.Lines.Count > 0)
                {
                    sng.Verses.Add(verse);
                }
            }
        }
        public void LoadComplexTest()
        {
            ISongFileReader <OpenLyricsSong> target = new OpenLyricsSongFileReader();
            const string filename = "Resources/openlyrics/complex.xml";

            OpenLyricsSong expected = new OpenLyricsSong
            {
                Title             = "Amazing Grace",
                ModifiedTimestamp = "2012-04-10T22:00:00+10:00",
                CreatedIn         = "OpenLP 1.9.0",
                ModifiedIn        = "ChangingSong 0.0.1",
                CcliIdentifier    = "4639462",
                Copyright         = "public domain",
                ReleaseYear       = "1779"
            };

            expected.Comments.Add("This is one of the most popular songs in our congregation.");

            OpenLyricsSong.Verse verse = new OpenLyricsSong.Verse
            {
                Name     = "v1",
                Language = "en"
            };
            var lines = new OpenLyricsSong.TextLines();

            lines.Text.Add("Amazing grace how sweet the sound that saved a wretch like me;");
            verse.Lines.Add(lines);
            lines = new OpenLyricsSong.TextLines
            {
                Part = "women"
            };
            lines.Text.Add("A b c");
            lines.Text.Add("D e f");
            verse.Lines.Add(lines);
            expected.Verses.Add(verse);

            verse = new OpenLyricsSong.Verse
            {
                Name     = "v1",
                Language = "de"
            };
            lines = new OpenLyricsSong.TextLines();
            lines.Text.Add("Erstaunliche Ahmut, wie");
            verse.Lines.Add(lines);
            expected.Verses.Add(verse);

            verse = new OpenLyricsSong.Verse
            {
                Name = "c"
            };
            lines = new OpenLyricsSong.TextLines();
            lines.Text.Add("");
            lines.Text.Add("Line content.");
            verse.Lines.Add(lines);
            expected.Verses.Add(verse);

            verse = new OpenLyricsSong.Verse
            {
                Name     = "v2",
                Language = "en-US"
            };
            lines = new OpenLyricsSong.TextLines
            {
                Part = "men"
            };
            lines.Text.Add("");
            lines.Text.Add("Amazing grace how sweet the sound that saved a wretch like me;");
            lines.Text.Add("");
            lines.Text.Add("Amazing grace how sweet the sound that saved a wretch like me;");
            lines.Text.Add("Amazing grace how sweet the sound that saved a wretch like me;");
            verse.Lines.Add(lines);
            lines = new OpenLyricsSong.TextLines
            {
                Part = "women"
            };
            lines.Text.Add("A b c");
            lines.Text.Add("");
            lines.Text.Add("D e f");
            verse.Lines.Add(lines);
            expected.Verses.Add(verse);

            verse = new OpenLyricsSong.Verse
            {
                Name     = "emptyline",
                Language = "de"
            };
            lines = new OpenLyricsSong.TextLines();
            lines.Text.Add("");
            lines.Text.Add("");
            verse.Lines.Add(lines);
            lines = new OpenLyricsSong.TextLines();
            lines.Text.Add("");
            lines.Text.Add("");
            lines.Text.Add("");
            lines.Text.Add("");
            lines.Text.Add("");
            verse.Lines.Add(lines);
            expected.Verses.Add(verse);

            verse = new OpenLyricsSong.Verse
            {
                Name     = "e",
                Language = "de"
            };
            lines = new OpenLyricsSong.TextLines();
            lines.Text.Add("This is text of ending.");
            verse.Lines.Add(lines);
            expected.Verses.Add(verse);

            OpenLyricsSong actual = target.Load(filename);

            Assert.AreEqual(expected.Title, actual.Title, "Wrong song title");
            Assert.AreEqual(expected.ModifiedTimestamp, actual.ModifiedTimestamp, "Wrong song modified date");
            Assert.AreEqual(expected.CreatedIn, actual.CreatedIn, "Wrong creator app");
            Assert.AreEqual(expected.ModifiedIn, actual.ModifiedIn, "Wrong modifier app");
            Assert.AreEqual(expected.Copyright, actual.Copyright, "Wrong copyright info");
            Assert.AreEqual(expected.CcliIdentifier, actual.CcliIdentifier, "Wrong CCLI number");
            Assert.AreEqual(expected.ReleaseYear, actual.ReleaseYear, "Wrong release date");
            CollectionAssert.AreEqual(expected.Comments, actual.Comments, "Wrong comments");

            Assert.AreEqual(expected.Verses.Count, actual.Verses.Count, "Verses incomplete");
            for (int i = 0; i < expected.Verses.Count; i++)
            {
                Assert.AreEqual(expected.Verses[i].Name, actual.Verses[i].Name, "Wrong verse name");
                Assert.AreEqual(expected.Verses[i].Language, actual.Verses[i].Language, "Wrong language");
                Assert.AreEqual(expected.Verses[i].Lines.Count, actual.Verses[i].Lines.Count, "Slides incomplete " + i);
                for (int j = 0; j < expected.Verses[i].Lines.Count; j++)
                {
                    Assert.AreEqual(expected.Verses[i].Lines[j].Text.Count, actual.Verses[i].Lines[j].Text.Count, "Slide lines incomplete " + i + " " + j);
                    Assert.AreEqual(expected.Verses[i].Lines[j].Part, actual.Verses[i].Lines[j].Part, "Wrong lines part name");
                    for (int k = 0; k < expected.Verses[i].Lines[j].Text.Count; k++)
                    {
                        Assert.AreEqual(expected.Verses[i].Lines[j].Text[k], actual.Verses[i].Lines[j].Text[k], "Wrong slide lyrics");
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void LoadSimpleTest()
        {
            OpenLyricsSongFileMapper mapper = new OpenLyricsSongFileMapper();

            OpenLyricsSong source = new OpenLyricsSong
            {
                Title             = "Amazing Grace",
                ModifiedTimestamp = "2012-04-10T22:00:00+10:00",
                CreatedIn         = "OpenLP 1.9.0",
                ModifiedIn        = "MyApp 0.0.1"
            };

            OpenLyricsSong.Verse verse = new OpenLyricsSong.Verse
            {
                Name = "v1"
            };

            OpenLyricsSong.TextLines lines = new OpenLyricsSong.TextLines();
            lines.Text.Add("Amazing grace how sweet the sound");
            lines.Text.Add("that saved a wretch like me;");
            verse.Lines.Add(lines);
            source.Verses.Add(verse);


            Song expected = new Song
            {
                Title             = "Amazing Grace",
                ModifiedTimestamp = "2012-04-10T22:00:00+10:00",
                CreatedIn         = "OpenLP 1.9.0",
                ModifiedIn        = "MyApp 0.0.1"
            };

            var part = new SongPart
            {
                Caption = "v1"
            };

            var slide = new SongSlide
            {
                Text = "Amazing grace how sweet the sound<br/>that saved a wretch like me;"
            };

            part.Slides.Add(slide);
            expected.Parts.Add(part);

            var actual = mapper.Map(source);

            Assert.AreEqual(expected.Title, actual.Title, "Wrong song title");
            Assert.AreEqual(expected.ModifiedTimestamp, actual.ModifiedTimestamp, "Wrong song modified date");
            Assert.AreEqual(expected.CreatedIn, actual.CreatedIn, "Wrong creator app");
            Assert.AreEqual(expected.ModifiedIn, actual.ModifiedIn, "Wrong modifier app");

            Assert.AreEqual(expected.Parts.Count, actual.Parts.Count, "Parts incomplete");
            for (int i = 0; i < expected.Parts.Count; i++)
            {
                Assert.AreEqual(expected.Parts[i].Caption, actual.Parts[i].Caption, "Wrong verse name");
                Assert.AreEqual(expected.Parts[i].Slides.Count, actual.Parts[i].Slides.Count, "Slides incomplete");
                for (int j = 0; j < expected.Parts[i].Slides.Count; j++)
                {
                    Assert.AreEqual(expected.Parts[i].Slides[j].Lines.Count, actual.Parts[i].Slides[j].Lines.Count, "Slide lines incomplete");
                    for (int k = 0; k < expected.Parts[i].Slides[j].Lines.Count; k++)
                    {
                        Assert.AreEqual(expected.Parts[i].Slides[j].Lines[k], actual.Parts[i].Slides[j].Lines[k], "Wrong slide lyrics");
                    }
                }
            }

            Assert.IsTrue(SongSearchUtil.GetSearchableSongText(actual).Contains(expected.Title.ToLower()));
            Assert.IsTrue(SongSearchUtil.GetSearchableSongText(actual).Contains("sweet"));
        }
Ejemplo n.º 5
0
        public void LoadComplexTest()
        {
            OpenLyricsSongFileMapper mapper = new OpenLyricsSongFileMapper();

            OpenLyricsSong source = new OpenLyricsSong
            {
                Title             = "Amazing Grace",
                ModifiedTimestamp = "2012-04-10T22:00:00+10:00",
                CreatedIn         = "OpenLP 1.9.0",
                ModifiedIn        = "ChangingSong 0.0.1",
                CcliIdentifier    = "4639462",
                Copyright         = "public domain",
                ReleaseYear       = "1779"
            };

            source.Comments.Add("This is one of the most popular songs in our congregation.");

            OpenLyricsSong.Verse verse = new OpenLyricsSong.Verse
            {
                Name     = "v1",
                Language = "en"
            };
            var lines = new OpenLyricsSong.TextLines();

            lines.Text.Add("Amazing grace how sweet the sound that saved a wretch like me;");
            verse.Lines.Add(lines);
            lines = new OpenLyricsSong.TextLines
            {
                Part = "women"
            };
            lines.Text.Add("A b c");
            lines.Text.Add("D e f");
            verse.Lines.Add(lines);
            source.Verses.Add(verse);

            verse = new OpenLyricsSong.Verse
            {
                Name     = "v1",
                Language = "de"
            };
            lines = new OpenLyricsSong.TextLines();
            lines.Text.Add("Erstaunliche Ahmut, wie");
            verse.Lines.Add(lines);
            source.Verses.Add(verse);

            verse = new OpenLyricsSong.Verse
            {
                Name = "c"
            };
            lines = new OpenLyricsSong.TextLines();
            lines.Text.Add("");
            lines.Text.Add("Line content.");
            verse.Lines.Add(lines);
            source.Verses.Add(verse);

            verse = new OpenLyricsSong.Verse
            {
                Name     = "v2",
                Language = "en-US"
            };
            lines = new OpenLyricsSong.TextLines
            {
                Part = "men"
            };
            lines.Text.Add("");
            lines.Text.Add("Amazing grace how sweet the sound that saved a wretch like me;");
            lines.Text.Add("");
            lines.Text.Add("Amazing grace how sweet the sound that saved a wretch like me;");
            lines.Text.Add("Amazing grace how sweet the sound that saved a wretch like me;");
            verse.Lines.Add(lines);
            lines = new OpenLyricsSong.TextLines
            {
                Part = "women"
            };
            lines.Text.Add("A b c");
            lines.Text.Add("");
            lines.Text.Add("D e f");
            verse.Lines.Add(lines);
            source.Verses.Add(verse);

            verse = new OpenLyricsSong.Verse
            {
                Name     = "emptyline",
                Language = "de"
            };
            lines = new OpenLyricsSong.TextLines();
            lines.Text.Add("");
            lines.Text.Add("");
            verse.Lines.Add(lines);
            lines = new OpenLyricsSong.TextLines();
            lines.Text.Add("");
            lines.Text.Add("");
            lines.Text.Add("");
            lines.Text.Add("");
            lines.Text.Add("");
            verse.Lines.Add(lines);
            source.Verses.Add(verse);

            verse = new OpenLyricsSong.Verse
            {
                Name     = "e",
                Language = "de"
            };
            lines = new OpenLyricsSong.TextLines();
            lines.Text.Add("This is text of ending.");
            verse.Lines.Add(lines);
            source.Verses.Add(verse);


            Song expected = new Song
            {
                Title             = "Amazing Grace",
                ModifiedTimestamp = "2012-04-10T22:00:00+10:00",
                CreatedIn         = "OpenLP 1.9.0",
                ModifiedIn        = "ChangingSong 0.0.1",
                CcliIdentifier    = "4639462",
                Copyright         = "public domain",
                ReleaseYear       = "1779",
                Comment           = "This is one of the most popular songs in our congregation."
            };


            var part = new SongPart
            {
                Caption  = "v1",
                Language = "en"
            };
            var slide = new SongSlide();

            slide.Lines.Add("Amazing grace how sweet the sound that saved a wretch like me;");
            part.Slides.Add(slide);
            slide = new SongSlide
            {
                PartName = "women"
            };
            slide.Lines.Add("A b c");
            slide.Lines.Add("D e f");
            part.Slides.Add(slide);
            expected.Parts.Add(part);

            part = new SongPart
            {
                Caption  = "v1",
                Language = "de"
            };
            slide = new SongSlide
            {
                Text = "Erstaunliche Ahmut, wie"
            };
            part.Slides.Add(slide);
            expected.Parts.Add(part);

            part = new SongPart
            {
                Caption = "c"
            };
            slide = new SongSlide();
            slide.Lines.Add("");
            slide.Lines.Add("Line content.");
            part.Slides.Add(slide);
            expected.Parts.Add(part);

            part = new SongPart
            {
                Caption  = "v2",
                Language = "en-US"
            };
            slide = new SongSlide
            {
                PartName = "men"
            };
            slide.Lines.Add("");
            slide.Lines.Add("Amazing grace how sweet the sound that saved a wretch like me;");
            slide.Lines.Add("");
            slide.Lines.Add("Amazing grace how sweet the sound that saved a wretch like me;");
            slide.Lines.Add("Amazing grace how sweet the sound that saved a wretch like me;");
            part.Slides.Add(slide);
            slide = new SongSlide
            {
                PartName = "women"
            };
            slide.Lines.Add("A b c");
            slide.Lines.Add("");
            slide.Lines.Add("D e f");
            part.Slides.Add(slide);
            expected.Parts.Add(part);

            part = new SongPart
            {
                Caption  = "emptyline",
                Language = "de"
            };
            slide = new SongSlide();
            slide.Lines.Add("");
            slide.Lines.Add("");
            part.Slides.Add(slide);
            slide = new SongSlide();
            slide.Lines.Add("");
            slide.Lines.Add("");
            slide.Lines.Add("");
            slide.Lines.Add("");
            slide.Lines.Add("");
            part.Slides.Add(slide);
            expected.Parts.Add(part);

            part = new SongPart
            {
                Caption  = "e",
                Language = "de"
            };
            slide = new SongSlide
            {
                Text = "This is text of ending."
            };
            part.Slides.Add(slide);
            expected.Parts.Add(part);

            Song actual = mapper.Map(source);

            Assert.AreEqual(expected.Title, actual.Title, "Wrong song title");
            Assert.AreEqual(expected.ModifiedTimestamp, actual.ModifiedTimestamp, "Wrong song modified date");
            Assert.AreEqual(expected.CreatedIn, actual.CreatedIn, "Wrong creator app");
            Assert.AreEqual(expected.ModifiedIn, actual.ModifiedIn, "Wrong modifier app");
            Assert.AreEqual(expected.Copyright, actual.Copyright, "Wrong copyright info");
            Assert.AreEqual(expected.CcliIdentifier, actual.CcliIdentifier, "Wrong CCLI number");
            Assert.AreEqual(expected.ReleaseYear, actual.ReleaseYear, "Wrong release date");

            Assert.AreEqual(expected.Parts.Count, actual.Parts.Count, "Parts incomplete");
            for (int i = 0; i < expected.Parts.Count; i++)
            {
                Assert.AreEqual(expected.Parts[i].Caption, actual.Parts[i].Caption, "Wrong verse name");
                Assert.AreEqual(expected.Parts[i].Language, actual.Parts[i].Language, "Wrong language");
                Assert.AreEqual(expected.Parts[i].Slides.Count, actual.Parts[i].Slides.Count, "Slides incomplete " + i);
                for (int j = 0; j < expected.Parts[i].Slides.Count; j++)
                {
                    Assert.AreEqual(expected.Parts[i].Slides[j].Lines.Count, actual.Parts[i].Slides[j].Lines.Count, "Slide lines incomplete " + i + " " + j);
                    Assert.AreEqual(expected.Parts[i].Slides[j].PartName, actual.Parts[i].Slides[j].PartName, "Wrong slide part name");
                    for (int k = 0; k < expected.Parts[i].Slides[j].Lines.Count; k++)
                    {
                        Assert.AreEqual(expected.Parts[i].Slides[j].Lines[k], actual.Parts[i].Slides[j].Lines[k], "Wrong slide lyrics");
                    }
                }
            }
        }