This commit is contained in:
136
Plan B Html Parser (XNA 3.1)/TestProject1/AuthoringTests.txt
Normal file
136
Plan B Html Parser (XNA 3.1)/TestProject1/AuthoringTests.txt
Normal file
@@ -0,0 +1,136 @@
|
||||
==========================================================================
|
||||
Visual Studio Team System: Overview of Authoring and Running Tests
|
||||
==========================================================================
|
||||
|
||||
This overview describes the features for authoring and running tests in
|
||||
Visual Studio Team System and Visual Studio Team Edition for Software Testers.
|
||||
|
||||
Opening Tests
|
||||
-------------
|
||||
To open a test, open a test project or a test metadata file (a file with
|
||||
extension .vsmdi) that contains the definition of the test. You can find
|
||||
test projects and metadata files in Solution Explorer.
|
||||
|
||||
Viewing Tests
|
||||
-------------
|
||||
To see which tests are available to you, open the Test View window. Or,
|
||||
if you have installed Team Edition for Software Testers, you can also open
|
||||
the Test List Editor window to view tests.
|
||||
|
||||
To open the Test View window, click the Test menu, point to Windows, and
|
||||
then click Test View. To open the Test List Editor window (if you have
|
||||
installed Team Edition for Software Testers), click Test, point to Windows,
|
||||
and then click Test List Editor.
|
||||
|
||||
Running Tests
|
||||
-------------
|
||||
You can run tests from the Test View window and the Test List Editor window.
|
||||
See Viewing Tests to learn how to open these windows. To run one or more
|
||||
tests displayed in the Test View window, first select the tests in that
|
||||
window; to select multiple tests, hold either the Shift or CTRL key while
|
||||
clicking tests. Then click the Run Tests button in the Test View window
|
||||
toolbar.
|
||||
|
||||
If you have installed Visual Studio Team Edition for Software Testers, you can
|
||||
also use the Test List Editor window to run tests. To run tests in Test List Editor,
|
||||
select the check box next to each test that you want to run. Then click the
|
||||
Run Tests button in the Test List Editor window toolbar.
|
||||
|
||||
Viewing Test Results
|
||||
--------------------
|
||||
When you run a test or a series of tests, the results of the test run will be
|
||||
shown in the Test Results window. Each individual test in the run is shown on
|
||||
a separate line so that you can see its status. The window contains an
|
||||
embedded status bar in the top half of the window that provides you with
|
||||
summary details of the complete test run.
|
||||
|
||||
To see more detailed results for a particular test result, double-click it in
|
||||
the Test Results window. This opens a window that provides more information
|
||||
about the particular test result, such as any specific error messages returned
|
||||
by the test.
|
||||
|
||||
Changing the way that tests are run
|
||||
-----------------------------------
|
||||
Each time you run one or more tests, a collection of settings is used to
|
||||
determine how those tests are run. These settings are contained in a “test
|
||||
run configuration” file.
|
||||
|
||||
Here is a partial list of the changes you can make with a test run
|
||||
configuration file:
|
||||
|
||||
- Change the naming scheme for each test run.
|
||||
- Change the test controller that the tests are run on so that you can run
|
||||
tests remotely.
|
||||
- Gather code coverage data for the code being tested so that you can see
|
||||
which lines of code are covered by your tests.
|
||||
- Enable and disable test deployment.
|
||||
- Specify additional files to deploy before tests are run.
|
||||
- Select a different host, ASP.NET, for running ASP.NET unit tests.
|
||||
- Select a different host, the smart device test host, for running smart device unit tests.
|
||||
- Set various properties for the test agents that run your tests.
|
||||
- Run custom scripts at the start and end of each test run so that you can
|
||||
set up the test environment exactly as required each time tests are run.
|
||||
- Set time limits for tests and test runs.
|
||||
- Set the browser mix and the number of times to repeat Web tests in the
|
||||
test run.
|
||||
|
||||
By default, a test run configuration file is created whenever you create a
|
||||
new test project. You make changes to this file by double-clicking it in
|
||||
Solution Explorer and then changing its settings. (Test run configuration
|
||||
files have the extension .testrunconfig.)
|
||||
|
||||
A solution can contain multiple test run configuration files. Only one of
|
||||
those files, known as the “Active” test run configuration file, is used to
|
||||
determine the settings that are currently used for test runs. You select
|
||||
the active test run configuration by clicking Select Active Test Run
|
||||
Configuration on the Test menu.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
Test Types
|
||||
----------
|
||||
Using Visual Studio Team Edition for Software Testers, you can create a number
|
||||
of different test types:
|
||||
|
||||
Unit test: Use a unit test to create a programmatic test in C++, Visual C# or
|
||||
Visual Basic that exercises source code. A unit test calls the methods of a
|
||||
class, passing suitable parameters, and verifies that the returned value is
|
||||
what you expect.
|
||||
There are three specialized variants of unit tests:
|
||||
- Data-driven unit tests are created when you configure a unit test to be
|
||||
called repeatedly for each row of a data source. The data from each row
|
||||
is used by the unit test as input data.
|
||||
- ASP.NET unit tests are unit tests that exercise code in an ASP.NET Web
|
||||
application.
|
||||
- Smart device unit tests are unit tests that are deployed to a smart device
|
||||
or emulator and then executed by the smart device test host.
|
||||
|
||||
Web Test: Web tests consist of an ordered series of HTTP requests that you
|
||||
record in a browser session using Microsoft Internet Explorer. You can have
|
||||
the test report specific details about the pages or sites it requests, such
|
||||
as whether a particular page contains a specified string.
|
||||
|
||||
Load Test: You use a load test to encapsulate non-manual tests, such as
|
||||
unit, Web, and generic tests, and then run them simultaneously by using
|
||||
virtual users. Running these tests under load generates test results,
|
||||
including performance and other counters, in tables and in graphs.
|
||||
|
||||
Generic test: A generic test is an existing program wrapped to function as a
|
||||
test in Visual Studio. The following are examples of tests or programs that
|
||||
you can turn into generic tests:
|
||||
- An existing test that uses process exit codes to communicate whether the
|
||||
test passed or failed. 0 indicates passing and any other value indicates
|
||||
a failure.
|
||||
- A general program to obtain specific functionality during a test scenario.
|
||||
- A test or program that uses a special XML file (called a “summary results
|
||||
file”), to communicate detailed results.
|
||||
|
||||
Manual test: The manual test type is used when the test tasks are to be
|
||||
completed by a test engineer as opposed to an automated script.
|
||||
|
||||
Ordered test: Use an ordered test to execute a set of tests in an order you
|
||||
specify.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
|
||||
|
||||
178
Plan B Html Parser (XNA 3.1)/TestProject1/ParseErrorTests.cs
Normal file
178
Plan B Html Parser (XNA 3.1)/TestProject1/ParseErrorTests.cs
Normal file
@@ -0,0 +1,178 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using PlanB.Html.Nodes;
|
||||
using PlanB.Html;
|
||||
|
||||
namespace TestProject1
|
||||
{
|
||||
[TestClass]
|
||||
public class ParseErrorTests
|
||||
{
|
||||
public ParseErrorTests()
|
||||
{
|
||||
//
|
||||
// TODO: Add constructor logic here
|
||||
//
|
||||
}
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region Additional test attributes
|
||||
//
|
||||
// You can use the following additional attributes as you write your tests:
|
||||
//
|
||||
// Use ClassInitialize to run code before running the first test in the class
|
||||
// [ClassInitialize()]
|
||||
// public static void MyClassInitialize(TestContext testContext) { }
|
||||
//
|
||||
// Use ClassCleanup to run code after all tests in a class have run
|
||||
// [ClassCleanup()]
|
||||
// public static void MyClassCleanup() { }
|
||||
//
|
||||
// Use TestInitialize to run code before running each test
|
||||
// [TestInitialize()]
|
||||
// public void MyTestInitialize() { }
|
||||
//
|
||||
// Use TestCleanup to run code after each test has run
|
||||
// [TestCleanup()]
|
||||
// public void MyTestCleanup() { }
|
||||
//
|
||||
#endregion
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_UnknownTag()
|
||||
{
|
||||
String htmlText = "<asdf></asdf>";
|
||||
String expectedResult = "<asdf></asdf>";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode, "The HtmlNode returned by the parser is null.");
|
||||
|
||||
Assert.AreEqual<int>(htmlNode.Children.Count, 1);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlTextNode));
|
||||
|
||||
Assert.AreEqual<int>(htmlNode.Children[0].Children.Count, 0);
|
||||
|
||||
Assert.AreEqual<string>(expectedResult, htmlNode.InnerHtml);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_UnclosedTag()
|
||||
{
|
||||
String htmlText = "<div>asdf<span>fdsa</span>jkl;";
|
||||
String expectedResult = "<div>asdf<span>fdsa</span>jkl;</div>";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode, "The HtmlNode returned by the parser is null.");
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlDivNode));
|
||||
|
||||
Assert.AreEqual<string>(expectedResult, htmlNode.InnerHtml);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_UnescapedAmpersand()
|
||||
{
|
||||
String htmlText = "hello&world";
|
||||
String expectedResult = "hello&world";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode);
|
||||
|
||||
Assert.AreEqual<string>(expectedResult, htmlNode.InnerHtml);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_UnescapedLessThan()
|
||||
{
|
||||
String htmlText = "hello<world";
|
||||
String expectedResult = "hello<world";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode);
|
||||
|
||||
Assert.AreEqual<string>(expectedResult, htmlNode.InnerHtml);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_UnescapedLessThanThatLooksLikeATag()
|
||||
{
|
||||
String htmlText = "hello<div world";
|
||||
String expectedResult = "hello<div world";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode);
|
||||
|
||||
Assert.AreEqual<string>(expectedResult, htmlNode.InnerHtml);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_UnescapedGreaterThan()
|
||||
{
|
||||
String htmlText = "hello>world";
|
||||
String expectedResult = "hello>world";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode);
|
||||
|
||||
Assert.AreEqual<string>(expectedResult, htmlNode.InnerHtml);
|
||||
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_UnescapedQuote()
|
||||
{
|
||||
String htmlText = "hello\"world";
|
||||
String expectedResult = "hello"world";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlTextNode));
|
||||
|
||||
Assert.AreEqual<string>(expectedResult, htmlNode.InnerHtml);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_UnopenedTag()
|
||||
{
|
||||
String htmlText = "<div>hello world</span></div>";
|
||||
String expectedResult = "<div>hello world</div>";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlDivNode));
|
||||
|
||||
Assert.AreEqual<string>(expectedResult, htmlNode.InnerHtml);
|
||||
}
|
||||
}
|
||||
}
|
||||
346
Plan B Html Parser (XNA 3.1)/TestProject1/ParseTests.cs
Normal file
346
Plan B Html Parser (XNA 3.1)/TestProject1/ParseTests.cs
Normal file
@@ -0,0 +1,346 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using PlanB.Html.Nodes;
|
||||
using PlanB.Html;
|
||||
|
||||
namespace TestProject1
|
||||
{
|
||||
/// <summary>
|
||||
/// Summary description for UnitTest1
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public class ParseTests
|
||||
{
|
||||
public ParseTests()
|
||||
{
|
||||
//
|
||||
// TODO: Add constructor logic here
|
||||
//
|
||||
}
|
||||
|
||||
private TestContext testContextInstance;
|
||||
|
||||
/// <summary>
|
||||
///Gets or sets the test context which provides
|
||||
///information about and functionality for the current test run.
|
||||
///</summary>
|
||||
public TestContext TestContext
|
||||
{
|
||||
get
|
||||
{
|
||||
return testContextInstance;
|
||||
}
|
||||
set
|
||||
{
|
||||
testContextInstance = value;
|
||||
}
|
||||
}
|
||||
|
||||
#region Additional test attributes
|
||||
//
|
||||
// You can use the following additional attributes as you write your tests:
|
||||
//
|
||||
// Use ClassInitialize to run code before running the first test in the class
|
||||
// [ClassInitialize()]
|
||||
// public static void MyClassInitialize(TestContext testContext) { }
|
||||
//
|
||||
// Use ClassCleanup to run code after all tests in a class have run
|
||||
// [ClassCleanup()]
|
||||
// public static void MyClassCleanup() { }
|
||||
//
|
||||
// Use TestInitialize to run code before running each test
|
||||
// [TestInitialize()]
|
||||
// public void MyTestInitialize() { }
|
||||
//
|
||||
// Use TestCleanup to run code after each test has run
|
||||
// [TestCleanup()]
|
||||
// public void MyTestCleanup() { }
|
||||
//
|
||||
#endregion
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_HtmlTextNode()
|
||||
{
|
||||
String htmlText = "asdf";
|
||||
String expectedResult = "asdf";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode, "The HtmlNode returned by the parser is null.");
|
||||
|
||||
Assert.AreEqual<int>(htmlNode.Children.Count, 1);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlTextNode));
|
||||
|
||||
HtmlTextNode htmlTextNode = htmlNode.Children[0] as HtmlTextNode;
|
||||
|
||||
Assert.AreEqual(expectedResult, htmlTextNode.Text);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_Returns_HtmlDocumentNode()
|
||||
{
|
||||
String htmlText = String.Empty;
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode, typeof(HtmlDocumentNode));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_HtmlTextNode_Constructors()
|
||||
{
|
||||
HtmlTextNode htmlTextNode = new HtmlTextNode();
|
||||
|
||||
Assert.IsNotNull(htmlTextNode.Attributes, "The default constructor failed to initialize the Attributes property.");
|
||||
Assert.IsNotNull(htmlTextNode.Children, "The default constructor failed to initialize the Children property.");
|
||||
Assert.IsNotNull(htmlTextNode.InnerHtml, "The default constructor failed to initialize the InnerHtml property.");
|
||||
Assert.IsNotNull(htmlTextNode.OuterHtml, "The default constructor failed to initialize the OuterHtml property.");
|
||||
Assert.IsNotNull(htmlTextNode.Text, "The default constructor failed to initialize the Text property");
|
||||
Assert.IsNotNull(htmlTextNode.Type, "The default constructor failed to initialize the Type property");
|
||||
Assert.AreEqual<HtmlNodeType>(HtmlNodeType.Text_, htmlTextNode.Type);
|
||||
|
||||
String expectedValue = "This is some sample text.";
|
||||
htmlTextNode = new HtmlTextNode(expectedValue);
|
||||
Assert.IsNotNull(htmlTextNode.Attributes, "The HtmlTextNode(string) constructor failed to initialize the Attributes property.");
|
||||
Assert.IsNotNull(htmlTextNode.Children, "The HtmlTextNode(string) constructor failed to initialize the Children property.");
|
||||
Assert.IsNotNull(htmlTextNode.InnerHtml, "The HtmlTextNode(string) constructor failed to initialize the InnerHtml property.");
|
||||
Assert.AreEqual<String>(String.Empty, htmlTextNode.InnerHtml);
|
||||
Assert.IsNotNull(htmlTextNode.OuterHtml, "The HtmlTextNode(string) constructor failed to initialize the OuterHtml property.");
|
||||
Assert.AreEqual<String>(expectedValue, htmlTextNode.OuterHtml);
|
||||
Assert.IsNotNull(htmlTextNode.Text, "The HtmlTextNode(string) constructor failed to initialize the Text property");
|
||||
Assert.AreEqual<String>(expectedValue, htmlTextNode.Text);
|
||||
Assert.IsNotNull(htmlTextNode.Type, "The HtmlTextNode(string) constructor failed to initialize the Type property");
|
||||
Assert.AreEqual<HtmlNodeType>(HtmlNodeType.Text_, htmlTextNode.Type);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_HtmlDocumentNode_Constructors()
|
||||
{
|
||||
HtmlDocumentNode htmlDocumentNode = new HtmlDocumentNode();
|
||||
Assert.IsNotNull(htmlDocumentNode.Attributes);
|
||||
Assert.IsNotNull(htmlDocumentNode.Children);
|
||||
Assert.AreEqual<int>(0, htmlDocumentNode.Children.Count);
|
||||
Assert.IsNotNull(htmlDocumentNode.InnerHtml);
|
||||
Assert.AreEqual<String>(String.Empty, htmlDocumentNode.InnerHtml);
|
||||
Assert.IsNotNull(htmlDocumentNode.OuterHtml);
|
||||
Assert.AreEqual<String>(String.Empty, htmlDocumentNode.OuterHtml);
|
||||
Assert.IsNotNull(htmlDocumentNode.Type);
|
||||
Assert.AreEqual<HtmlNodeType>(HtmlNodeType.Document_, htmlDocumentNode.Type);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_HtmlBrNode_Constructor()
|
||||
{
|
||||
HtmlBrNode htmlBrNode = new HtmlBrNode();
|
||||
String expectedOuterHtml = "<br />";
|
||||
|
||||
Assert.IsNotNull(htmlBrNode.Attributes, "The default constructor failed to initialize the Attributes property.");
|
||||
Assert.AreEqual<int>(0, htmlBrNode.Attributes.Count);
|
||||
Assert.IsNotNull(htmlBrNode.Children, "The default constructor failed to initialize the Children property.");
|
||||
Assert.AreEqual<int>(0, htmlBrNode.Children.Count);
|
||||
Assert.IsNotNull(htmlBrNode.InnerHtml, "The default constructor failed to initialize the InnerHtml property.");
|
||||
Assert.AreEqual<String>(htmlBrNode.InnerHtml, String.Empty);
|
||||
Assert.IsNotNull(htmlBrNode.OuterHtml, "The default constructor failed to initialize the OuterHtml property.");
|
||||
Assert.AreEqual<String>(htmlBrNode.OuterHtml, expectedOuterHtml);
|
||||
Assert.IsNotNull(htmlBrNode.Type, "The default constructor failed to initialize the Type property");
|
||||
Assert.AreEqual<HtmlNodeType>(HtmlNodeType.Br, htmlBrNode.Type);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_HtmlSpanNode_Constructor()
|
||||
{
|
||||
|
||||
//Default constructor
|
||||
HtmlSpanNode htmlSpanNode = new HtmlSpanNode();
|
||||
Assert.IsNotNull(htmlSpanNode.Attributes, "The default constructor failed to initialize the Attributes property.");
|
||||
Assert.AreEqual<int>(0, htmlSpanNode.Attributes.Count);
|
||||
Assert.IsNotNull(htmlSpanNode.Children, "The default constructor failed to initialize the Children property.");
|
||||
Assert.AreEqual<int>(0, htmlSpanNode.Children.Count);
|
||||
Assert.IsNotNull(htmlSpanNode.InnerHtml, "The default constructor failed to initialize the InnerHtml property.");
|
||||
Assert.AreEqual<string>(String.Empty, htmlSpanNode.InnerHtml);
|
||||
Assert.IsNotNull(htmlSpanNode.OuterHtml, "The default constructor failed to initialize the OuterHtml property.");
|
||||
Assert.AreEqual<string>("<span />", htmlSpanNode.OuterHtml);
|
||||
Assert.IsNotNull(htmlSpanNode.Type, "The default constructor failed to initialize the Type property");
|
||||
Assert.AreEqual<HtmlNodeType>(HtmlNodeType.Span, htmlSpanNode.Type);
|
||||
|
||||
//HtmlSpanNode(String)
|
||||
String text = "test";
|
||||
htmlSpanNode = new HtmlSpanNode(text);
|
||||
Assert.IsNotNull(htmlSpanNode.Attributes, "The HtmlSpanNode(String) constructor failed to initialize the Attributes property.");
|
||||
Assert.AreEqual<int>(0, htmlSpanNode.Attributes.Count);
|
||||
Assert.IsNotNull(htmlSpanNode.Children, "The HtmlSpanNode(String) constructor failed to initialize the Children property.");
|
||||
Assert.AreEqual<int>(1, htmlSpanNode.Children.Count);
|
||||
Assert.IsNotNull(htmlSpanNode.InnerHtml, "The HtmlSpanNode(String) constructor failed to initialize the InnerHtml property.");
|
||||
Assert.AreEqual<string>(text, htmlSpanNode.InnerHtml);
|
||||
Assert.IsNotNull(htmlSpanNode.OuterHtml, "The HtmlSpanNode(String) constructor failed to initialize the OuterHtml property.");
|
||||
Assert.AreEqual<string>("<span>" + text + "</span>", htmlSpanNode.OuterHtml);
|
||||
Assert.IsNotNull(htmlSpanNode.Type, "The HtmlSpanNode(String) constructor failed to initialize the Type property");
|
||||
Assert.AreEqual<HtmlNodeType>(HtmlNodeType.Span, htmlSpanNode.Type);
|
||||
|
||||
//HtmlSpanNode(IEnumerable<HtmlNode>)
|
||||
htmlSpanNode = new HtmlSpanNode(new HtmlNode[] { new HtmlTextNode(text), new HtmlBrNode(), new HtmlTextNode(text) });
|
||||
Assert.IsNotNull(htmlSpanNode.Attributes, "The HtmlSpanNode(IEnumerable<HtmlNode>) constructor failed to initialize the Attributes property.");
|
||||
Assert.AreEqual<int>(0, htmlSpanNode.Attributes.Count);
|
||||
Assert.IsNotNull(htmlSpanNode.Children, "The HtmlSpanNode(IEnumerable<HtmlNode>) constructor failed to initialize the Children property.");
|
||||
Assert.AreEqual<int>(3, htmlSpanNode.Children.Count);
|
||||
Assert.IsNotNull(htmlSpanNode.InnerHtml, "The HtmlSpanNode(IEnumerable<HtmlNode>) constructor failed to initialize the InnerHtml property.");
|
||||
Assert.AreEqual<string>(text + "<br />" + text, htmlSpanNode.InnerHtml);
|
||||
Assert.IsNotNull(htmlSpanNode.OuterHtml, "The HtmlSpanNode(IEnumerable<HtmlNode>) constructor failed to initialize the OuterHtml property.");
|
||||
Assert.AreEqual<string>("<span>" + text + "<br />" + text + "</span>", htmlSpanNode.OuterHtml);
|
||||
Assert.IsNotNull(htmlSpanNode.Type, "The HtmlSpanNode(IEnumerable<HtmlNode>) constructor failed to initialize the Type property");
|
||||
Assert.AreEqual<HtmlNodeType>(HtmlNodeType.Span, htmlSpanNode.Type);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_TextWithSpanTag()
|
||||
{
|
||||
String htmlText = "asdf<span>123</span>fdsa";
|
||||
String expectedFirstNodeOuterHtml = "asdf";
|
||||
String expectedSecondNodeOuterHtml = "<span>123</span>";
|
||||
String expectedThirdNodeOuterHtml = "fdsa";
|
||||
String expectedSecondNodeInnerHtml = "123";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode, "");
|
||||
Assert.IsInstanceOfType(htmlNode, typeof(HtmlDocumentNode));
|
||||
Assert.AreEqual<string>(htmlText, htmlNode.OuterHtml);
|
||||
Assert.AreEqual<int>(3, htmlNode.Children.Count);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlTextNode));
|
||||
Assert.AreEqual<string>(expectedFirstNodeOuterHtml, htmlNode.Children[0].OuterHtml);
|
||||
Assert.AreEqual<int>(0, htmlNode.Children[0].Children.Count);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[1], typeof(HtmlSpanNode));
|
||||
Assert.AreEqual<string>(expectedSecondNodeOuterHtml, htmlNode.Children[1].OuterHtml);
|
||||
Assert.AreEqual<int>(1, htmlNode.Children[1].Children.Count);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[1].Children[0], typeof(HtmlTextNode));
|
||||
Assert.AreEqual<string>(expectedSecondNodeInnerHtml, htmlNode.Children[1].Children[0].OuterHtml);
|
||||
Assert.AreEqual<int>(0, htmlNode.Children[1].Children[0].Children.Count);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[2], typeof(HtmlTextNode));
|
||||
Assert.AreEqual<string>(expectedThirdNodeOuterHtml, htmlNode.Children[2].OuterHtml);
|
||||
Assert.AreEqual<int>(0, htmlNode.Children[2].Children.Count);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_TextWithBrTag()
|
||||
{
|
||||
String htmlText = "asdf<br />asdf";
|
||||
String expectedResult = "asdf<br />asdf";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode, "The HtmlNode returned by the parser is null.");
|
||||
|
||||
Assert.AreEqual<int>(htmlNode.Children.Count, 3);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlTextNode));
|
||||
|
||||
HtmlTextNode htmlTextNode = htmlNode.Children[0] as HtmlTextNode;
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[1], typeof(HtmlBrNode));
|
||||
|
||||
HtmlBrNode htmlBrNode = htmlNode.Children[1] as HtmlBrNode;
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[2], typeof(HtmlTextNode));
|
||||
|
||||
htmlTextNode = htmlNode.Children[2] as HtmlTextNode;
|
||||
|
||||
Assert.AreEqual(expectedResult, htmlNode.InnerHtml);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_SpanWithStyle()
|
||||
{
|
||||
String htmlText = "<span style=\"color:black\">asdf</span>";
|
||||
String expectedResult = "<span style=\"color:black;\">asdf</span>";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode, "The HtmlNode returned by the parser is null.");
|
||||
|
||||
Assert.AreEqual<int>(htmlNode.Children.Count, 1);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlSpanNode));
|
||||
|
||||
HtmlSpanNode spanNode = htmlNode.Children[0] as HtmlSpanNode;
|
||||
|
||||
IEnumerable<KeyValuePair<string,string>> spanStyleAttributes = spanNode.Attributes.Where(i=>i.Key == "style");
|
||||
/*
|
||||
Assert.AreEqual<int>(spanStyleAttributes.Count(), 1);
|
||||
|
||||
KeyValuePair<string, string> spanStyleAttribute = spanStyleAttributes.First();
|
||||
|
||||
Assert.AreEqual<string>(spanStyleAttribute.Value, "color:black");
|
||||
/**/
|
||||
|
||||
IEnumerable<KeyValuePair<string, string>> spanColorStyles = spanNode.Styles.Where(i => i.Key == "color");
|
||||
|
||||
Assert.AreEqual<int>(spanColorStyles.Count(), 1);
|
||||
|
||||
KeyValuePair<string, string> spanColorStyle = spanColorStyles.First();
|
||||
|
||||
//Assert.AreEqual<string>(spanColorStyle.Value, "rgb(0,0,0)");
|
||||
Assert.AreEqual<string>(spanColorStyle.Value, "black");
|
||||
/**/
|
||||
|
||||
Assert.AreEqual(expectedResult, htmlNode.InnerHtml);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_Div()
|
||||
{
|
||||
String htmlText = "<div>asdf</div>";
|
||||
String expectedResult = "<div>asdf</div>";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode, "The HtmlNode returned by the parser is null.");
|
||||
|
||||
Assert.AreEqual<int>(htmlNode.Children.Count, 1);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlDivNode));
|
||||
|
||||
HtmlDivNode divNode = htmlNode.Children[0] as HtmlDivNode;
|
||||
|
||||
Assert.AreEqual<int>(divNode.Children.Count, 1);
|
||||
|
||||
Assert.AreEqual<string>(expectedResult, htmlNode.InnerHtml);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Test_Parse_Img()
|
||||
{
|
||||
String htmlText = "<img src=\"http://blogs.msdn.com/blogfiles/klevereblog/WindowsLiveWriter/Bingishere_A002/bing-logo_2.jpg\"/>";
|
||||
String expectedResult = "<img src=\"http://blogs.msdn.com/blogfiles/klevereblog/WindowsLiveWriter/Bingishere_A002/bing-logo_2.jpg\" />";
|
||||
|
||||
HtmlNode htmlNode = Parser.Parse(htmlText);
|
||||
|
||||
Assert.IsNotNull(htmlNode, "The HtmlNode returned by the parser is null.");
|
||||
|
||||
Assert.AreEqual<int>(htmlNode.Children.Count, 1);
|
||||
|
||||
Assert.IsInstanceOfType(htmlNode.Children[0], typeof(HtmlImgNode));
|
||||
|
||||
HtmlImgNode imgNode = htmlNode.Children[0] as HtmlImgNode;
|
||||
|
||||
Assert.AreEqual<int>(imgNode.Children.Count, 0);
|
||||
|
||||
Assert.AreEqual<string>(expectedResult, htmlNode.InnerHtml);
|
||||
|
||||
Assert.AreEqual<int>(imgNode.Attributes.Count, 1);
|
||||
Assert.AreEqual<int>(imgNode.Styles.Count, 0);
|
||||
var temp = imgNode.Attributes.Where(i=>i.Key == "src");
|
||||
Assert.AreEqual<int>(temp.Count(), 1);
|
||||
Assert.AreEqual<string>(temp.Single().Value, "http://blogs.msdn.com/blogfiles/klevereblog/WindowsLiveWriter/Bingishere_A002/bing-logo_2.jpg");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("TestProject1")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("TestProject1")]
|
||||
[assembly: AssemblyCopyright("Copyright © Microsoft 2009")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM componenets. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("e044337f-2da1-429d-8f24-45bc7651026c")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,68 @@
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{9E7D5692-C2E9-4219-977E-143CC75B5737}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>TestProject1</RootNamespace>
|
||||
<AssemblyName>TestProject1</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ParseErrorTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ParseTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="AuthoringTests.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Plan B Html Parser\Plan B Html Parser.csproj">
|
||||
<Project>{A6FA0455-ACB5-4E80-9E58-6B79976AA717}</Project>
|
||||
<Name>Plan B Html Parser</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,10 @@
|
||||
""
|
||||
{
|
||||
"FILE_VERSION" = "9237"
|
||||
"ENLISTMENT_CHOICE" = "NEVER"
|
||||
"PROJECT_FILE_RELATIVE_PATH" = ""
|
||||
"NUMBER_OF_EXCLUDED_FILES" = "0"
|
||||
"ORIGINAL_PROJECT_FILE_PATH" = ""
|
||||
"NUMBER_OF_NESTED_PROJECTS" = "0"
|
||||
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
|
||||
}
|
||||
Reference in New Issue
Block a user