TdNetLogger.cs :  » Testing » xUnit.net » Xunit » Runner » TdNet » 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 » Runner » TdNet » TdNetLogger.cs
using System;
using System.Reflection;
using TestDriven.Framework;

namespace Xunit.Runner.TdNet{
    using TestResult = TestDriven.Framework.TestResult;

    public class TdNetLogger : IRunnerLogger
    {
        private readonly Assembly assembly;
        private readonly ITestListener listener;

        public TdNetLogger(ITestListener listener, Assembly assembly)
        {
            this.listener = listener;
            this.assembly = assembly;
        }

        public bool FoundTests { get; private set; }

        public void AssemblyFinished(string assemblyFilename, int total, int failed, int skipped, double time) { }

        public void AssemblyStart(string assemblyFilename, string configFilename, string xUnitVersion) { }

        public bool ClassFailed(string className, string exceptionType, string message, string stackTrace)
        {
            Type type = assembly.GetType(className);

            TestResult testResult =
                new TestResult
                    {
                        FixtureType = type,
                        Name = ("Fixture " + type.FullName),
                        TotalTests = 1,
                        State = TestState.Failed,
                        Message = message,
                        StackTrace = stackTrace
                    };

            if (listener != null)
                listener.TestFinished(testResult);

            return true;
        }

        public void ExceptionThrown(string assemblyFilename, Exception exception)
        {
            if (listener != null)
                listener.WriteLine(exception.ToString(), Category.Error);
        }

        public void TestFailed(string name, string type, string method, double duration, string output, string exceptionType, string message, string stackTrace)
        {
            TestResult testResult = CreateTestResult(type, method, name, duration);

            testResult.State = TestState.Failed;
            testResult.Message = message;
            testResult.StackTrace = stackTrace;

            if (listener != null)
                listener.TestFinished(testResult);

            WriteOutput(name, output);
        }

        public bool TestFinished(string name, string type, string method)
        {
            FoundTests = true;
            return true;
        }

        public void TestPassed(string name, string type, string method, double duration, string output)
        {
            TestResult testResult = CreateTestResult(type, method, name, duration);

            testResult.State = TestState.Passed;

            if (listener != null)
                listener.TestFinished(testResult);

            WriteOutput(name, output);
        }

        public void TestSkipped(string name, string type, string method, string reason)
        {
            TestResult testResult = CreateTestResult(type, method, name, 0);

            testResult.State = TestState.Ignored;
            testResult.Message = reason;

            if (listener != null)
                listener.TestFinished(testResult);
        }

        public bool TestStart(string name, string type, string method)
        {
            return true;
        }

        TestResult CreateTestResult(string type, string method, string name, double duration)
        {
            Type fixtureType = assembly.GetType(type);

            return new TestResult
                       {
                           FixtureType = fixtureType,
                           Method = fixtureType.GetMethod(method),
                           Name = name,
                           TimeSpan = new TimeSpan((long)(10000.0 * duration)),
                           TotalTests = 1,
                       };
        }

        private void WriteOutput(string name, string output)
        {
            if (output != null)
            {
                listener.WriteLine(String.Format("Output from {0}:", name), Category.Output);
                foreach (string line in output.Trim().Split(new[] { Environment.NewLine }, StringSplitOptions.None))
                    listener.WriteLine(String.Format("  {0}", line), Category.Output);
            }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.