Пример #1
0
        /// <summary>
        /// Gets Value
        /// </summary>
        /// <param name="arrange">arrange parameter</param>
        /// <param name="assertionItem">assertionItem parameter</param>
        /// <returns>value from arrange</returns>
        protected virtual string GetValue(Arrange arrange, ContentAssertionItem assertionItem)
        {
            if (assertionItem.Value != null)
            {
                return(assertionItem.Value);
            }

            var value = arrange.HttpResponse.GetDocumentValue(assertionItem.Query, assertionItem.Attribute);

            if (assertionItem.Pattern != null)
            {
                return(TextAssertion.Match(value, assertionItem.Pattern));
            }

            return(value);
        }
Пример #2
0
        public void TestAssert()
        {
            // Arrange
            const string ExpectedXml = @"<Shop>a</Shop>";
            const string ActualHtml =
                @"<html>
                    <body>
                        <span>a</span>
                    </body>
                </html>";

            var item = new TextAssertion
            {
                IsList = false,
                Expected = new ContentAssertionItem
                {
                    Key = "Expected",
                    Value = null,
                    Query = "//Shop",
                    Attribute = null,
                    Pattern = null,
                },
                Actual = new ContentAssertionItem
                {
                    Key = "Actual",
                    Value = null,
                    Query = "//body/span",
                    Attribute = null,
                    Pattern = null,
                },
            };

            var expected = new Arrange { HttpResponse = new HttpResponse { Contents = ExpectedXml, ContentType = "text/xml" } };
            var actual = new Arrange { HttpResponse = new HttpResponse { Contents = ActualHtml, ContentType = "text/html" } };

            // Act
            item.Assert(expected, actual);

            // Assert
            Assert.IsTrue(item.Success);
        }
Пример #3
0
        public void TestAssertWithUrlDecode()
        {
            // Arrange
            const string ExpectedXml = @"<Shop>http://www.test.com/?query=a+b</Shop>";
            const string ActualHtml =
                @"<html>
                    <body>
                        <a href='http://www.test.com/?query=a+b'>link</a>
                    </body>
                </html>";

            var item = new TextAssertion
            {
                IsList = false,
                Expected = new ContentAssertionItem
                {
                    Key = "Expected",
                    Value = null,
                    Query = "//Shop",
                    Attribute = null,
                    Pattern = null,
                    UrlDecode = true,
                },
                Actual = new ContentAssertionItem
                {
                    Key = "Actual",
                    Value = null,
                    Query = "//body/a",
                    Attribute = "href",
                    Pattern = null,
                    UrlDecode = true,
                },
            };

            var expected = new Arrange { HttpResponse = new HttpResponse { Contents = ExpectedXml, ContentType = "text/xml" } };
            var actual = new Arrange { HttpResponse = new HttpResponse { Contents = ActualHtml, ContentType = "text/html" } };

            // Act
            item.Assert(expected, actual);

            // Assert
            Assert.IsTrue(item.Success);
        }
Пример #4
0
        public void TestAssertWithListAndStaticValue()
        {
            // Arrange
            const string ActualHtml =
                @"<html>
                    <body>
                        <span>aaa</span>
                        <span>aaa</span>
                    </body>
                </html>";

            var item = new TextAssertion
            {
                IsList = true,
                Expected = new ContentAssertionItem
                {
                    Key = null,
                    Value = "aaa",
                    Query = null,
                    Attribute = null,
                    Pattern = null,
                },
                Actual = new ContentAssertionItem
                {
                    Key = "Actual",
                    Value = null,
                    Query = "//body/span",
                    Attribute = null,
                    Pattern = null,
                },
            };

            var actual = new Arrange { HttpResponse = new HttpResponse { Contents = ActualHtml, ContentType = "text/html" } };

            // Act
            item.Assert(null, actual);
        }
Пример #5
0
        public void TestAssertWithListAndPattern()
        {
            // Arrange
            const string ExpectedXml =
                @"<Shop>
                    <Item>30 in</Item>
                    <Item>61°</Item>
                    <Item>66%</Item>
                    <Item>10 miles</Item>
                    <Item>0 mph</Item>
                </Shop>";
            const string ActualHtml =
                @"<html>
                    <body>
                        <ul>
                            <li>Barometer: 30 in</li>
                            <li>Dewpoint: 61°</li>
                            <li>Humidity: 66%</li>
                            <li>Visibility: 10 miles</li>
                            <li>Wind: 0 mph</li>
                        </ul>
                    </body>
                </html>";

            var item = new TextAssertion
            {
                IsList = true,
                Expected = new ContentAssertionItem
                {
                    Key = "Expected",
                    Value = null,
                    Query = "//Shop/Item",
                    Attribute = null,
                    Pattern = null,
                },
                Actual = new ContentAssertionItem
                {
                    Key = "Actual",
                    Value = null,
                    Query = "//body/ul/li",
                    Attribute = null,
                    Pattern = @"[^:]:\s(.*)",
                },
            };

            var expected = new Arrange { HttpResponse = new HttpResponse { Contents = ExpectedXml, ContentType = "text/xml" } };
            var actual = new Arrange { HttpResponse = new HttpResponse { Contents = ActualHtml, ContentType = "text/html" } };

            // Act
            item.Assert(expected, actual);

            // Assert
            Assert.IsTrue(item.Success);
        }
Пример #6
0
        public void TestAssertWithList()
        {
            // Arrange
            const string ExpectedXml =
                @"<Shop>
                    <Item Name='a' />
                    <Item Name='b' />
                    <Item Name='c' />
                    <Item Name='d' />
                    <Item Name='e' />
                </Shop>";
            const string ActualHtml =
                @"<html>
                    <body>
                        <ul>
                            <li>a</li>
                            <li>b</li>
                            <li>c</li>
                            <li>d</li>
                            <li>e</li>
                        </ul>
                    </body>
                </html>";

            var item = new TextAssertion
            {
                IsList = true,
                Expected = new ContentAssertionItem
                {
                    Key = "Expected",
                    Value = null,
                    Query = "//Shop/Item",
                    Attribute = "Name",
                    Pattern = null,
                },
                Actual = new ContentAssertionItem
                {
                    Key = "Actual",
                    Value = null,
                    Query = "//body/ul/li",
                    Attribute = null,
                    Pattern = null,
                },
            };

            var expected = new Arrange { HttpResponse = new HttpResponse { Contents = ExpectedXml, ContentType = "text/xml" } };
            var actual = new Arrange { HttpResponse = new HttpResponse { Contents = ActualHtml, ContentType = "text/html" } };

            // Act
            item.Assert(expected, actual);

            // Assert
            Assert.IsTrue(item.Success);
        }
Пример #7
0
        public void TestAssertWithFailedPattern()
        {
            // Arrange
            const string ExpectedXml =
                @"<Shop>
                    <Item>30 in</Item>
                </Shop>";
            const string ActualHtml =
                @"<html>
                    <body>
                        <ul><li>Barometer 30 in</li></ul>
                    </body>
                </html>";

            var item = new TextAssertion
            {
                IsList = false,
                Expected = new ContentAssertionItem
                {
                    Key = "Expected",
                    Value = null,
                    Query = "//Shop/Item",
                    Attribute = null,
                    Pattern = null,
                },
                Actual = new ContentAssertionItem
                {
                    Key = "Actual",
                    Value = null,
                    Query = "//body/ul/li",
                    Attribute = null,
                    Pattern = @"[^:]:\s(.*)",
                },
            };

            var expected = new Arrange { HttpResponse = new HttpResponse { Contents = ExpectedXml, ContentType = "text/xml" } };
            var actual = new Arrange { HttpResponse = new HttpResponse { Contents = ActualHtml, ContentType = "text/html" } };

            // Act
            item.Assert(expected, actual);
        }