コード例 #1
0
        public void Rip_ComplexCss_ReturnsExpectedResources()
        {
            var subUriStrings = new[] { "importUri", "selector2Property2Uri", "selector3Property1Uri", "selector3Property2Uri" };
            var css           = string.Format(@"/* comment */
@import '{0}';

selector1 {{
    property:value;
}}
selector2 {{
    property1:value;
    property2:url('{1}');
}}
selector3 {{
    property1:url('{2}');
    property2:url('{3}');
}}
", subUriStrings.Cast <object>().ToArray());

            using (var webTest = new WebTestInfo(CssParser.MimeType, css))
            {
                var expected = WebTest.GetExpectedResources(webTest, subUriStrings);
                var actual   = WebTest.GetActualResources(webTest,
                                                          subUriStrings.Select(subUriString => new WebTestInfo(webTest, subUriString)).ToArray());
                Assert.Equal(expected, actual);
            }
        }
コード例 #2
0
 public void Rip_EmptyCss_ReturnsCssParser()
 {
     using (var webTest = new WebTestInfo(CssParser.MimeType, EmptyCss))
     {
         var expected = typeof(CssParser);
         var actual   = WebTest.GetActualResources(webTest).Single().Parser;
         Assert.IsType(expected, actual);
     }
 }
コード例 #3
0
 public void Rip_EmptyHtml_ReturnsSingleResource(string html)
 {
     using (var webTest = new WebTestInfo(HtmlParser.MimeType, html))
     {
         var expected = WebTest.GetExpectedResources(webTest);
         var actual   = WebTest.GetActualResources(webTest);
         Assert.Equal(expected, actual);
     }
 }
コード例 #4
0
 public void Rip_EmptyHtml_ReturnsHtmlMimeType()
 {
     using (var webTest = new WebTestInfo(HtmlParser.MimeType, EmptyHtml))
     {
         var expected = HtmlParser.MimeType;
         var actual   = WebTest.GetActualResources(webTest).Single().Parser.ActualMimeType;
         Assert.Equal(expected, actual);
     }
 }
コード例 #5
0
 public void Rip_EmptyHtml_ReturnsExpectedUri()
 {
     using (var webTest = new WebTestInfo(HtmlParser.MimeType, EmptyHtml))
     {
         var expected = webTest.Uri;
         var actual   = WebTest.GetActualResources(webTest).Single().OriginalUri;
         Assert.Equal(expected, actual);
     }
 }
コード例 #6
0
 public void Rip_BasicCssWithNoReferences_ReturnsSingleResource(string css)
 {
     using (var webTest = new WebTestInfo(CssParser.MimeType, css))
     {
         var expected = WebTest.GetExpectedResources(webTest);
         var actual   = WebTest.GetActualResources(webTest);
         Assert.Equal(expected, actual);
     }
 }
コード例 #7
0
 public void Rip_EmptyXml_ReturnsXmlParser(string mimeType)
 {
     using (var webTest = new WebTestInfo(mimeType, EmptyXml))
     {
         var expected = typeof(XmlParser);
         var actual   = WebTest.GetActualResources(webTest).Single().Parser;
         Assert.IsType(expected, actual);
     }
 }
コード例 #8
0
        public void Rip_BasicXmlWithEscapedReferenceInDocType_ReturnsExpectedResources(string processingInstructionsFormat, string subUriString)
        {
            var xml = GetXml(processingInstructions: string.Format(processingInstructionsFormat, subUriString));

            using (var webTest = new WebTestInfo(XmlParser.MimeType, xml))
            {
                var expected = WebTest.GetExpectedResources(webTest, subUriString);
                var actual   = WebTest.GetActualResources(webTest, new WebTestInfo(webTest, subUriString));
                Assert.Equal(expected, actual);
            }
        }
コード例 #9
0
        public void Rip_BasicXmlWithMultipleReferences_ReturnsExpectedResources(string rootAttributesFormat, string @namespace, string[] subUriStrings)
        {
            var xml = string.Format(GetXml(rootAttributes: string.Format(rootAttributesFormat, subUriStrings.Cast <object>().ToArray())), @namespace);

            using (var webTest = new WebTestInfo(XmlParser.MimeType, xml))
            {
                var expected = WebTest.GetExpectedResources(webTest, subUriStrings);
                var actual   = WebTest.GetActualResources(webTest, subUriStrings.Select(subUriString => new WebTestInfo(webTest, subUriString)).ToArray());
                Assert.Equal(expected, actual);
            }
        }
コード例 #10
0
        public void Rip_BasicHtmlWithNoReferences_ReturnsSingleResource(string headNodes, string bodyNodes)
        {
            var html = GetHtml(headNodes: headNodes, bodyNodes: bodyNodes);

            using (var webTest = new WebTestInfo(HtmlParser.MimeType, html))
            {
                var expected = WebTest.GetExpectedResources(webTest);
                var actual   = WebTest.GetActualResources(webTest);
                Assert.Equal(expected, actual);
            }
        }
コード例 #11
0
        public void Rip_BasicHtmlWithMultipleReferences_ReturnsExpectedResources(string bodyNodesFormat, string[] subUriStrings)
        {
            var html = GetHtml(bodyNodes: string.Format(bodyNodesFormat, subUriStrings.Cast <object>().ToArray()));

            using (var webTest = new WebTestInfo(HtmlParser.MimeType, html))
            {
                var expected = WebTest.GetExpectedResources(webTest, subUriStrings);
                var actual   = WebTest.GetActualResources(webTest, subUriStrings.Select(subUriString => new WebTestInfo(webTest, subUriString)).ToArray());
                Assert.Equal(expected, actual);
            }
        }
コード例 #12
0
        public void Rip_BasicCssWithReference_ReturnsExpectedResources(string cssFormat)
        {
            const string subUriString = "uri";
            var          css          = string.Format(cssFormat, subUriString);

            using (var webTest = new WebTestInfo(CssParser.MimeType, css))
            {
                var expected = WebTest.GetExpectedResources(webTest, subUriString);
                var actual   = WebTest.GetActualResources(webTest, new WebTestInfo(webTest, subUriString));
                Assert.Equal(expected, actual);
            }
        }
コード例 #13
0
        public void Rip_BasicXmlStyleSheetWithType_ReturnsResourcesWithExpectedMimeType()
        {
            const string mimeType     = "type/subtype";
            const string subUriString = "uri";
            var          xml          = GetXml(processingInstructions: string.Format("<?xml-stylesheet type=\"{0}\" href=\"{1}\"?>", mimeType, subUriString));

            using (var webTest = new WebTestInfo(XmlParser.MimeType, xml))
            {
                var actual = WebTest.GetActualResources(webTest, new WebTestInfo(webTest, subUriString));
                Assert.Single(actual, resource => string.Equals(resource.Parser.ActualMimeType, mimeType, StringComparison.OrdinalIgnoreCase));
            }
        }
コード例 #14
0
        public void Rip_BasicHtmlWithDuplicateBases_ReturnsSingleResource()
        {
            var html = GetHtml(
                baseNodes: string.Format("{0}{1}", GetBaseNode("base1"), GetBaseNode("base2")),
                bodyNodes: "<a href=value>Text</a>");

            using (var webTest = new WebTestInfo(HtmlParser.MimeType, html))
            {
                var expected = WebTest.GetExpectedResources(webTest);
                var actual   = WebTest.GetActualResources(webTest);
                Assert.Equal(expected, actual);
            }
        }
コード例 #15
0
        public void Rip_BasicHtmlWithBase_ReturnsExpectedBaseUri(string baseNodeFormat, string baseUriStringWithoutScheme)
        {
            var baseUri = baseUriStringWithoutScheme != null?WebTest.GetUri(baseUriStringWithoutScheme) : null;

            var html = GetHtml(baseNodes: string.Format(baseNodeFormat, baseUri));

            using (var webTest = new WebTestInfo(HtmlParser.MimeType, html))
            {
                var expected = baseUri;
                var actual   = ((HtmlParser)WebTest.GetActualResources(webTest).Single().Parser).BaseUri;
                Assert.Equal(expected, actual);
            }
        }
コード例 #16
0
        public void Rip_ComplexHtml_ReturnsExpectedResources()
        {
            var subUriStrings = new[]
            {
                "htmlManifestUri", "headProfileUri", "linkIconHrefUri", "linkPingBackHrefUri", "linkPrefetchHrefUri",
                "linkStyleSheetHrefUri", "bodyBackgroundUri", "aHrefUri", "appletArchiveUri1", "appletArchiveUri2",
                "appletCodeUri", "areaHrefUri", "audioSrcUri", "embedSrcUri", "frameLongDescUri", "frameSrcUri",
                "iframeLongDescUri", "iframeSrcUri", "imgLongDescUri", "imgSrcUri", "inputSrcUri", "menuItemIconUri",
                "objectClassIdUri", "objectArchiveUri1", "objectArchiveUri2", "objectDataUri", "scriptSrcUri",
                "sourceSrcUri", "sourceSrcSetUri1", "sourceSrcSetUri2", "trackSrcUri", "videoPosterUri", "videoSrcUri"
            };
            var html = string.Format(@"<!-- comment -->
<html manifest={0}>
    <head profile={1}>
        <title>Title</title>
        <link rel=dns-prefetch href=value>Text</link>
        <link rel=icon href={2}>Text</link>
        <link rel=pingback href={3}>Text</link>
        <link rel=prefetch href={4}>Text</link>
        <link rel=stylesheet href={5}>Text</link>
    </head>
    <body background={6}>
        Body<br>
        A: <a href={7}>Text</a><br>
        Applet: <applet archive=""{8},{9}"" code={10}>Text</applet><br>
        Area: <map><area href={11}>Text</area></map><br>
        Audio: <audio src={12}>Text</audio><br>
        Node: <node attribute=value>Text</node>
        Embed: <embed src={13}>Text</embed><br>
        Frame: <frameset><frame longdesc={14} src={15}>Text</frame></frameset><br>
        Iframe: <iframe longdesc={16} src={17}>Text</iframe><br>
        Img: <img longdesc={18} src={19}>Text</img><br>
        Input: <input src={20}>Text</input><br>
        MenuItem: <menu><menuitem icon={21}>Text</menuitem></menu><br>
        Object: <object archive=""{22} {23}"" classid={24} data={25}>Text</object><br>
        Script: <script src={26}>Text</script><br>
        Source: <audio><source src={27} srcset=""{28},{29}"">Text</source></audio><br>
        Track: <video><track src={30}>Text</track></video><br>
        Video: <video poster={31} src={32}>Text</video><br>
    </body>
</html>
", subUriStrings.Cast <object>().ToArray());

            using (var webTest = new WebTestInfo(HtmlParser.MimeType, html))
            {
                var expected = WebTest.GetExpectedResources(webTest, subUriStrings);
                var actual   = WebTest.GetActualResources(webTest,
                                                          subUriStrings.Select(subUriString => new WebTestInfo(webTest, subUriString)).ToArray());
                Assert.Equal(expected, actual);
            }
        }
コード例 #17
0
        public void Rip_BasicXmlWithNoReferences_ReturnsSingleResource(string processingInstructions, string rootAttributes, string rootElements)
        {
            var xml = GetXml(
                processingInstructions: processingInstructions,
                rootAttributes: rootAttributes,
                rootElements: rootElements);

            using (var webTest = new WebTestInfo(XmlParser.MimeType, xml))
            {
                var expected = WebTest.GetExpectedResources(webTest);
                var actual   = WebTest.GetActualResources(webTest);
                Assert.Equal(expected, actual);
            }
        }
コード例 #18
0
        public void Rip_BasicHtmlWithMultipleReferencesSpecificBaseUri_ReturnsExpectedRebasedResources()
        {
            var          subUriStrings = new[] { "uri1", "uri2", "uri3" };
            const string specificBaseUriStringWithoutScheme = "specificBaseUri";
            var          specificBaseUri = WebTest.GetUri(specificBaseUriStringWithoutScheme);
            var          html            = GetHtml(bodyNodes: string.Format("<object archive={1} classid={2} codebase={0} data={3}>Text</object>", subUriStrings.Cast <object>().Prepend(specificBaseUri).ToArray()));

            using (var webTest = new WebTestInfo(HtmlParser.MimeType, html))
            {
                var subUris  = subUriStrings.Select(subUriString => new Uri(specificBaseUri, subUriString)).ToArray();
                var expected = WebTest.GetExpectedResources(webTest, subUris);
                var actual   = WebTest.GetActualResources(webTest, subUris.Select(subUri => new WebTestInfo(webTest, subUri)).ToArray());
                Assert.Equal(expected, actual);
            }
        }
コード例 #19
0
        public void Rip_BasicXmlWithReference_ReturnsExpectedResources(string processingInstructionsFormat,
                                                                       string rootElement, string rootAttributesFormat, string rootElementsFormat, string @namespace)
        {
            const string subUriString = "uri";
            var          xml          = string.Format(GetXml(
                                                          processingInstructions: string.Format(processingInstructionsFormat, subUriString),
                                                          rootElement: rootElement,
                                                          rootAttributes: string.Format(rootAttributesFormat, subUriString),
                                                          rootElements: string.Format(rootElementsFormat, subUriString)), @namespace);

            using (var webTest = new WebTestInfo(XmlParser.MimeType, xml))
            {
                var expected = WebTest.GetExpectedResources(webTest, subUriString);
                var actual   = WebTest.GetActualResources(webTest, new WebTestInfo(webTest, subUriString));
                Assert.Equal(expected, actual);
            }
        }
コード例 #20
0
        public void Rip_BasicHtmlWithReference_ReturnsExpectedResources(string htmlAttributesFormat,
                                                                        string headAttributesFormat, string headNodesFormat,
                                                                        string bodyAttributesFormat, string bodyNodesFormat)
        {
            const string subUriString = "uri";
            var          html         = GetHtml(
                htmlAttributes: string.Format(htmlAttributesFormat, subUriString),
                headAttributes: string.Format(headAttributesFormat, subUriString),
                headNodes: string.Format(headNodesFormat, subUriString),
                bodyAttributes: string.Format(bodyAttributesFormat, subUriString),
                bodyNodes: string.Format(bodyNodesFormat, subUriString));

            using (var webTest = new WebTestInfo(HtmlParser.MimeType, html))
            {
                var expected = WebTest.GetExpectedResources(webTest, subUriString);
                var actual   = WebTest.GetActualResources(webTest, new WebTestInfo(webTest, subUriString));
                Assert.Equal(expected, actual);
            }
        }
コード例 #21
0
        public void Rip_ComplexXml_ReturnsExpectedResources()
        {
            var args          = new[] { _encodingName, XmlParser.XsdNamespace, XmlParser.XsiNamespace, XmlParser.XsltNamespace };
            var subUriStrings = new[]
            {
                "doctypeUri", "xmlStyleSheetUri", "xsiSchemaLocationUri1", "xsiSchemaLocationUri2",
                "xsiNoNamespaceSchemaLocationUri", "schemaIncludeSchemaLocationUri", "xsdIncludeSchemaLocationUri",
                "xsdRedefineSchemaLocationUri", "xsdOverrideSchemaLocationUri", "xsdImportSchemaLocationUri",
                "xsdAppInfoSourceUri", "xsdDocumentationSourceUri", "xsltImportHrefUri",
                "xsltImportSchemaSchemaLocationUri", "xsltIncludeHrefUri"
            };
            var xml = string.Format(@"<?xml version=""1.0"" encoding=""{0}""?>
<!DOCTYPE root SYSTEM ""{4}"">
<?xml-stylesheet href=""{5}""?>
<root xmlns=""nsUri"" xmlns:prefix=""prefixNsUri"" xmlns:xsi=""{2}"" xsi:schemaLocation=""ns1 {6} ns2 {7}"" xsi:noNamespaceSchemaLocation=""{8}"">
    <schema xmlns=""{1}"">
        <include schemaLocation=""{9}""/>
    </schema>
    <xsd:schema xmlns:xsd=""{1}"">
        <xsd:include schemaLocation=""{10}""/>
        <xsd:redefine schemaLocation=""{11}""/>
        <xsd:override schemaLocation=""{12}""/>
        <xsd:import schemaLocation=""{13}""/>
        <xsd:appinfo source=""{14}""/>
        <xsd:documentation source=""{15}""/>
    </xsd:schema>
    <xsl:stylesheet xmlns:xsl=""{3}"" version=""1.0"">
        <xsl:import href=""{16}""/>
        <xsl:import-schema schema-location=""{17}""/>
        <xsl:include href=""{18}""/>
    </xsl:stylesheet>
</root>
", args.Concat(subUriStrings).Cast <object>().ToArray());

            using (var webTest = new WebTestInfo(XmlParser.MimeType, xml))
            {
                var expected = WebTest.GetExpectedResources(webTest, subUriStrings);
                var actual   = WebTest.GetActualResources(webTest,
                                                          subUriStrings.Select(subUriString => new WebTestInfo(webTest, subUriString)).ToArray());
                Assert.Equal(expected, actual);
            }
        }
コード例 #22
0
        public void Rip_BasicHtmlWithBaseSensitiveReference_ReturnsRebasedResources(string htmlAttributesFormat,
                                                                                    string headAttributesFormat, string headNodesFormat,
                                                                                    string bodyAttributesFormat, string bodyNodesFormat)
        {
            const string subUriString = "uri";
            const string baseUriStringWithoutScheme = "baseUri";
            var          html = GetHtml(
                htmlAttributes: string.Format(htmlAttributesFormat, subUriString),
                headAttributes: string.Format(headAttributesFormat, subUriString),
                baseNodes: GetBaseNode(baseUriStringWithoutScheme),
                headNodes: string.Format(headNodesFormat, subUriString),
                bodyAttributes: string.Format(bodyAttributesFormat, subUriString),
                bodyNodes: string.Format(bodyNodesFormat, subUriString));

            using (var webTest = new WebTestInfo(HtmlParser.MimeType, html))
            {
                var subUri   = new Uri(WebTest.GetUri(baseUriStringWithoutScheme), subUriString);
                var expected = WebTest.GetExpectedResources(webTest, subUri);
                var actual   = WebTest.GetActualResources(webTest, new WebTestInfo(webTest, subUri));
                Assert.Equal(expected, actual);
            }
        }
コード例 #23
0
        public void Rip_ComplexXmlWithEmbeddedStyleSheet_ReturnsExpectedResources()
        {
            // This test comes from: http://www.w3.org/TR/2007/REC-xslt20-20070123/#embedded
            var subUriStrings = new[] { "doc.dtd", "doc.xsl" };
            var xml           = string.Format(@"<?xml-stylesheet type=""application/xslt+xml"" href=""#style1""?>
<!DOCTYPE doc SYSTEM ""{1}"">
<doc>
    <head>
        <xsl:stylesheet id=""style1""
                        version=""2.0""
                        xmlns:xsl=""{0}""
                        xmlns:fo=""http://www.w3.org/1999/XSL/Format"">
        <xsl:import href=""{2}""/>
        <xsl:template match=""id('foo')"">
          <fo:block font-weight=""bold""><xsl:apply-templates/></fo:block>
        </xsl:template>
        <xsl:template match=""xsl:stylesheet"">
          <!-- ignore -->
        </xsl:template>
        </xsl:stylesheet>
    </head>
    <body>
        <para id=""foo"">
        ...
        </para>
    </body>
</doc>
", subUriStrings.Prepend(XmlParser.XsltNamespace).Cast <object>().ToArray());

            using (var webTest = new WebTestInfo(XmlParser.MimeType, xml))
            {
                var expected = WebTest.GetExpectedResources(webTest, subUriStrings);
                var actual   = WebTest.GetActualResources(webTest,
                                                          subUriStrings.Select(subUriString => new WebTestInfo(webTest, subUriString)).ToArray());
                Assert.Equal(expected, actual);
            }
        }