ClassResult.cs :  » Testing » xUnit.net » Xunit » Sdk » 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 » Xunit » Sdk » ClassResult.cs
using System;
using System.Xml;

namespace Xunit.Sdk{
    /// <summary>
    /// Contains the test results from a test class.
    /// </summary>
    [Serializable]
    public class ClassResult : CompositeResult
    {
        string exceptionType;
        int failCount;
        string message;
        int passCount;
        int skipCount;
        string stackTrace;
        readonly string typeFullName;
        readonly string typeName;
        readonly string typeNamespace;

        /// <summary>
        /// Creates a new instance of the <see cref="ClassResult"/> class.
        /// </summary>
        /// <param name="type">The type under test</param>
        public ClassResult(Type type)
        {
            typeName = type.Name;
            typeFullName = type.FullName;
            typeNamespace = type.Namespace;
        }

        /// <summary>
        /// Creates a new instance of the <see cref="ClassResult"/> class.
        /// </summary>
        /// <param name="typeName">The simple name of the type under test</param>
        /// <param name="typeFullName">The fully qualified name of the type under test</param>
        /// <param name="typeNamespace">The namespace of the type under test</param>
        public ClassResult(string typeName,
                           string typeFullName,
                           string typeNamespace)
        {
            this.typeName = typeName;
            this.typeFullName = typeFullName;
            this.typeNamespace = typeNamespace;
        }

        /// <summary>
        /// Gets the fully qualified test fixture exception type, when an exception has occurred.
        /// </summary>
        public string ExceptionType
        {
            get { return exceptionType; }
        }

        /// <summary>
        /// Gets the number of tests which failed.
        /// </summary>
        public int FailCount
        {
            get { return failCount; }
        }

        /// <summary>
        /// Gets the fully qualified name of the type under test.
        /// </summary>
        public string FullyQualifiedName
        {
            get { return typeFullName; }
        }

        /// <summary>
        /// Gets the test fixture exception message, when an exception has occurred.
        /// </summary>
        public string Message
        {
            get { return message; }
        }

        /// <summary>
        /// Gets the simple name of the type under test.
        /// </summary>
        public string Name
        {
            get { return typeName; }
        }

        /// <summary>
        /// Gets the namespace of the type under test.
        /// </summary>
        public string Namespace
        {
            get { return typeNamespace; }
        }

        /// <summary>
        /// Gets the number of tests which passed.
        /// </summary>
        public int PassCount
        {
            get { return passCount; }
        }

        /// <summary>
        /// Gets the number of tests which were skipped.
        /// </summary>
        public int SkipCount
        {
            get { return skipCount; }
        }

        /// <summary>
        /// Gets the test fixture exception stack trace, when an exception has occurred.
        /// </summary>
        public string StackTrace
        {
            get { return stackTrace; }
        }

        /// <summary>
        /// Sets the exception thrown by the test fixture.
        /// </summary>
        /// <param name="ex">The thrown exception</param>
        public void SetException(Exception ex)
        {
            if (ex == null)
            {
                exceptionType = null;
                message = null;
                stackTrace = null;
            }
            else
            {
                exceptionType = ex.GetType().FullName;
                message = ExceptionUtility.GetMessage(ex);
                stackTrace = ExceptionUtility.GetStackTrace(ex);
            }
        }

        /// <summary>
        /// Converts the test result into XML that is consumed by the test runners.
        /// </summary>
        /// <param name="parentNode">The parent node.</param>
        /// <returns>The newly created XML node.</returns>
        public override XmlNode ToXml(XmlNode parentNode)
        {
            failCount = 0;
            passCount = 0;
            skipCount = 0;
            ExecutionTime = 0.0;

            XmlNode classNode = XmlUtility.AddElement(parentNode, "class");

            if (Message != null)
            {
                failCount += 1;

                XmlNode failureNode = XmlUtility.AddElement(classNode, "failure");
                XmlUtility.AddAttribute(failureNode, "exception-type", ExceptionType);
                XmlNode messageNode = XmlUtility.AddElement(failureNode, "message");
                messageNode.InnerText = Message;
                XmlNode stackTraceNode = XmlUtility.AddElement(failureNode, "stack-trace");
                stackTraceNode.InnerText = StackTrace;
            }

            foreach (ITestResult testResult in Results)
            {
                testResult.ToXml(classNode);

                if (testResult is PassedResult)
                    passCount++;
                else if (testResult is FailedResult)
                    failCount++;
                else if (testResult is SkipResult)
                    skipCount++;

                ExecutionTime += testResult.ExecutionTime;
            }

            AddTime(classNode);
            XmlUtility.AddAttribute(classNode, "name", FullyQualifiedName);
            XmlUtility.AddAttribute(classNode, "total", classNode.ChildNodes.Count);
            XmlUtility.AddAttribute(classNode, "passed", passCount);
            XmlUtility.AddAttribute(classNode, "failed", failCount);
            XmlUtility.AddAttribute(classNode, "skipped", skipCount);

            return classNode;
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.