XmlAcceptanceTests.cs :  » Testing » xUnit.net » Namespace2 » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Testing » xUnit.net 
xUnit.net » Namespace2 » XmlAcceptanceTests.cs
using System;
using System.Linq;
using System.Xml;
using TestUtility;
using Xunit;

public class XmlAcceptanceTests : AcceptanceTest
{
    [Fact]
    public void EndToEndXmlValidation()
    {
        string code =
            @"
                using System;
                using Xunit;

                namespace Namespace1
                {
                    public class Class1
                    {
                        [Fact]
                        [Trait(""Bug"", ""123"")]
                        [Trait(""Bug"", ""456"")]
                        public void Passing()
                        {
                            Assert.Equal(2, 2);
                        }

                        [Fact]
                        public void Failing()
                        {
                            Assert.Equal(2, 3);
                        }

                        [Fact(Skip=""Skipping"")]
                        public void Skipped() {}
                    }
                }

                namespace Namespace2{
                    public class OuterClass
                    {
                        public class Class2
                        {
                            [Fact]
                            public void Passing()
                            {
                                Assert.Equal(2, 2);
                            }
                        }
                    }
                }
            ";

        XmlNode assemblyNode = Execute(code);

        Assert.Equal("4", assemblyNode.Attributes["total"].Value);
        Assert.Equal("2", assemblyNode.Attributes["passed"].Value);
        Assert.Equal("1", assemblyNode.Attributes["failed"].Value);
        Assert.Equal("1", assemblyNode.Attributes["skipped"].Value);

        XmlNodeList classNodes = assemblyNode.SelectNodes("class");
        Assert.Equal(classNodes.Count, 2);

        XmlNode class1Node = classNodes[0];
        Assert.Equal("Namespace1.Class1", class1Node.Attributes["name"].Value);

        XmlNodeList class1TestNodes = class1Node.SelectNodes("test");
        Assert.Equal(class1TestNodes.Count, 3);
        Assert.NotNull(class1Node.SelectSingleNode(@"//test[@name=""Namespace1.Class1.Passing""]"));
        Assert.NotNull(class1Node.SelectSingleNode(@"//test[@name=""Namespace1.Class1.Failing""]"));
        Assert.NotNull(class1Node.SelectSingleNode(@"//test[@name=""Namespace1.Class1.Skipped""]"));

        XmlNode passingNode = class1Node.SelectSingleNode(@"//test[@name=""Namespace1.Class1.Passing""]");
        XmlNodeList traitsNodes = passingNode.SelectNodes("traits/trait");
        Assert.Equal(2, traitsNodes.Count);
        Assert.True(traitsNodes.OfType<XmlNode>().Any(n => n.Attributes["name"].Value == "Bug" &&
                                                           n.Attributes["value"].Value == "123"));
        Assert.True(traitsNodes.OfType<XmlNode>().Any(n => n.Attributes["name"].Value == "Bug" &&
                                                           n.Attributes["value"].Value == "456"));

        XmlNode failingNode = class1Node.SelectSingleNode(@"//test[@name=""Namespace1.Class1.Failing""]");
        Assert.Equal("   at Namespace1.Class1.Failing()", failingNode.SelectSingleNode("failure/stack-trace").InnerText);

        XmlNode class2Node = classNodes[1];
        Assert.Equal("Namespace2.OuterClass+Class2", class2Node.Attributes["name"].Value);

        XmlNodeList class2TestNodes = class2Node.SelectNodes("test");
        Assert.Equal(class2TestNodes.Count, 1);
        Assert.Equal("Namespace2.OuterClass+Class2.Passing", class2TestNodes[0].Attributes["name"].Value);
        Assert.Equal("Namespace2.OuterClass+Class2", class2TestNodes[0].Attributes["type"].Value);
        Assert.Equal("Passing", class2TestNodes[0].Attributes["method"].Value);
    }

    [Fact]
    public void ExceptionCommentsCanIncludeCDATADeclarations()
    {
        string code =
        @"
                using System;
                using Xunit;

                public class Class1
                {
                    [Fact]
                    public void Failing()
                    {
                        throw new Exception(""<![CDATA[This is"" + Environment.NewLine + ""dummy CData]]>"");
                    }
                }
            ";

        XmlNode assemblyNode = Execute(code);

        XmlNode testNode = assemblyNode.SelectSingleNode("class/test");
        Assert.Equal("System.Exception : <![CDATA[This is" + Environment.NewLine + "dummy CData]]>", testNode.SelectSingleNode("failure/message").InnerText);
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.