Dom() public static method

public static Dom ( XmlDocument dom ) : AssertDom
dom System.Xml.XmlDocument
return AssertDom
コード例 #1
0
        public void GetXmlDomFromHtml_HasOpenLinkElement_Closes()
        {
            var dom = XmlHtmlConverter.GetXmlDomFromHtml("<!DOCTYPE html><html><head>    <link rel='stylesheet' href='basePage.css' type='text/css'> </head></html>", false);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//html", 1);            //makes sure no namespace was inserted (or does it? what if that assert is too smart))
            Assert.AreEqual("<html><head><link rel=\"stylesheet\" href=\"basePage.css\" type=\"text/css\" /><title></title></head><body></body></html>", dom.OuterXml);
        }
コード例 #2
0
        public void GetXmlDomFromHtml_MinimalWellFormedHtml5()
        {
            var dom = XmlHtmlConverter.GetXmlDomFromHtml("<!DOCTYPE html><html></html>", false);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//html", 1);            //makes sure no namespace was inserted (or does it? what if that assert is too smart))
            Assert.AreEqual("<html><head><title></title></head><body></body></html>", dom.OuterXml);
        }
コード例 #3
0
        public void GetXmlDomFromHtml_HasEmptyParagraphs_RetainsEmptyParagraphs()
        {
            var pattern = "<p></p><p></p><p>a</p><p></p><p>b</p>";
            var html    = "<!DOCTYPE html><html><body>" +
                          pattern +
                          "</body></html>";
            var dom = XmlHtmlConverter.GetXmlDomFromHtml(html, false);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//p", 5);
        }
コード例 #4
0
        public void GetXmlDomFromHtml_HasOpenLinkElement_Closes()
        {
            var dom = XmlHtmlConverter.GetXmlDomFromHtml("<!DOCTYPE html><html><head>    <link rel='stylesheet' href='basePage.css' type='text/css'> </head></html>", false);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//html", 1);            //makes sure no namespace was inserted (or does it? what if that assert is too smart))
            // The XmlDocument.PreserveWhitespace setting appears to insert newlines that we don't care about.
            var xml = dom.OuterXml;

            xml = xml.Replace(Environment.NewLine, "");
            Assert.AreEqual("<html><head><link rel=\"stylesheet\" href=\"basePage.css\" type=\"text/css\" /><title></title></head><body></body></html>", xml);
        }
コード例 #5
0
        public void GetXmlDomFromHtml_MinimalWellFormedHtml5()
        {
            var dom = XmlHtmlConverter.GetXmlDomFromHtml("<!DOCTYPE html><html></html>", false);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//html", 1);            //makes sure no namespace was inserted (or does it? what if that assert is too smart))
            // The XmlDocument.PreserveWhitespace setting appears to insert newlines that we don't care about.
            var xml = dom.OuterXml;

            xml = xml.Replace(Environment.NewLine, "");
            Assert.AreEqual("<html><head><title></title></head><body></body></html>", xml);
        }
コード例 #6
0
        public void UpdateAllHtmlDataAttributesForAllImgElements_HasBothImgAndBackgroundImageElements_UpdatesBoth()
        {
            var dom = new HtmlDom("<html><body><img src='test.png'/><div style='color:orange; background-image=url(\"test.png\")'/></body></html>");

            using (var folder = new TemporaryFolder("bloom pictures test source"))
            {
                MakeSamplePngImageWithMetadata(folder.Combine("test.png"));
                ImageUpdater.UpdateAllHtmlDataAttributesForAllImgElements(folder.FolderPath, dom, new NullProgress());
            }

            AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//*[@data-copyright='Copyright 1999 by me']", 2);
            AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//*[@data-creator='joe']", 2);
            AssertThatXmlIn.Dom(dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//*[@data-license='cc-by-nd']", 2);
        }
コード例 #7
0
        public void ChangePicture_ElementIsDivWithBackgroundImage_Changes()
        {
            var dom = new XmlDocument();

            dom.LoadXml("<html><body><div id='one' style='background-image:url(\"old.png\")'></div></body></html>");

            using (var src = new TemporaryFolder("bloom pictures test source"))
                using (var dest = new TemporaryFolder("bloom picture tests dest"))
                    using (var original = MakeSampleJpegImage(src.Combine("new.jpg")))
                    {
                        ChangePicture(dest.Path, dom, "one", original);
                        Assert.IsTrue(File.Exists(dest.Combine("new.jpg")));
                        AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='one' and @style=\"background-image:url(\'new.jpg\')\"]", 1);
                    }
        }
コード例 #8
0
        private void TestUpdateImgMetadataAttributesToMatchImage(string contents)
        {
            var dom = new XmlDocument();

            dom.LoadXml(contents);

            using (var folder = new TemporaryFolder("bloom pictures test source"))
            {
                MakeSamplePngImageWithMetadata(folder.Combine("test.png"));
                ImageUpdater.UpdateImgMetdataAttributesToMatchImage(folder.FolderPath,
                                                                    dom.SelectSingleNode("//*[@id='two']") as XmlElement, new NullProgress());
            }

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//*[@data-copyright='Copyright 1999 by me']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//*[@data-creator='joe']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//*[@data-license='cc-by-nd']", 1);
        }
コード例 #9
0
        public void ChangePicture_PictureIsFromOutsideProject_PictureCopiedAndAttributeChanged()
        {
            var dom = new XmlDocument();

            dom.LoadXml("<html><body><div/><div><img id='one'/><img id='two' src='old.png'/></div></body></html>");

            using (var src = new TemporaryFolder("bloom pictures test source"))
                using (var dest = new TemporaryFolder("bloom picture tests dest"))
                {
                    var newImagePath = src.Combine("new.png");
                    using (var original = MakeSamplePngImage(newImagePath))
                    {
                        ChangePicture(dest.Path, dom, "two", original);
                        Assert.IsTrue(File.Exists(dest.Combine("new.png")));
                        AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath(@"//img[@id='two' and @src='new.png']", 1);
                    }
                }
        }
コード例 #10
0
        public void ChangePicture_PictureIsJpg_StaysJpg()
        {
            var dom = new XmlDocument();

            dom.LoadXml("<html><body><div/><div><img id='one'/><img id='two' src='old.png'/></div></body></html>");

            using (var src = new TemporaryFolder("bloom pictures test source"))
                using (var dest = new TemporaryFolder("bloom picture tests dest"))
                    using (var original = MakeSampleJpegImage(src.Combine("new.jpg")))
                    {
                        ChangePicture(dest.Path, dom, "two", original);
                        Assert.IsTrue(File.Exists(dest.Combine("new.jpg")));
                        AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath(@"//img[@id='two' and @src='new.jpg']", 1);
                        using (var converted = Image.FromFile(dest.Combine("new.jpg")))
                        {
                            Assert.AreEqual(ImageFormat.Jpeg.Guid, converted.RawFormat.Guid);
                        }
                    }
        }
コード例 #11
0
        public void ChangePicture_PictureIsFromOutsideProject_PictureCopiedAndAttributeChanged_AndMetadataSaved()
        {
            var dom = new XmlDocument();

            dom.LoadXml("<html><body><div/><div><img id='one'/><img id='two' src='old.png'/></div></body></html>");

            using (var src = new TemporaryFolder("bloom pictures test source"))
                using (var dest = new TemporaryFolder("bloom picture tests dest"))
                {
                    var newImagePath = src.Combine("new.png");
                    using (var original = MakeSamplePngImage(newImagePath))
                    {
                        original.Metadata.Creator    = "Some nice user";
                        original.Metadata.HasChanges = true;
                        ChangePicture(dest.Path, dom, "two", original);
                        var pathToNewImage = dest.Combine("new.png");
                        Assert.IsTrue(File.Exists(pathToNewImage));
                        AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath(@"//img[@id='two' and @src='new.png']", 1);
                        var metadataFromImage = Metadata.FromFile(pathToNewImage);
                        Assert.That(metadataFromImage.Creator, Is.EqualTo("Some nice user"));
                    }
                }
        }