TeamCityLogger.cs :  » Testing » xUnit.net » Xunit » Runner » MSBuild » 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 » MSBuild » TeamCityLogger.cs
using System;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace Xunit.Runner.MSBuild{
    public class TeamCityLogger : IRunnerLogger
    {
        readonly TaskLoggingHelper log;

        public TeamCityLogger(TaskLoggingHelper log)
        {
            this.log = log;
        }

        public void AssemblyFinished(string assemblyFilename, int total, int failed, int skipped, double time)
        {
            log.LogMessage(MessageImportance.High, "##teamcity[testSuiteFinished name='{0}']", Escape(assemblyFilename));
        }

        public void AssemblyStart(string assemblyFilename, string configFilename, string xUnitVersion)
        {
            log.LogMessage(MessageImportance.High, "##teamcity[testSuiteStarted name='{0}']", Escape(assemblyFilename));
        }

        public bool ClassFailed(string className, string exceptionType, string message, string stackTrace)
        {
            log.LogMessage(MessageImportance.High, "##teamcity[buildStatus status='FAILURE' text='Class failed: {0}: {1}|r|n{2}']",
                           Escape(className),
                           Escape(message),
                           Escape(stackTrace));
            return true;
        }

        public void ExceptionThrown(string assemblyFilename, Exception exception)
        {
            log.LogError(exception.Message);
            log.LogError("While running: {0}", assemblyFilename);
        }

        public void TestFailed(string name, string type, string method, double duration, string output, string exceptionType, string message, string stackTrace)
        {
            log.LogMessage(MessageImportance.High, "##teamcity[testFailed name='{0}' details='{1}|r|n{2}']",
                           Escape(name),
                           Escape(message),
                           Escape(stackTrace));
            WriteOutput(name, output);
            WriteFinished(name, duration);
        }

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

        public void TestPassed(string name, string type, string method, double duration, string output)
        {
            WriteOutput(name, output);
            WriteFinished(name, duration);
        }

        public void TestSkipped(string name, string type, string method, string reason)
        {
            log.LogMessage(MessageImportance.High, "##teamcity[testIgnored name='{0}' message='{1}']",
                           Escape(name),
                           Escape(reason));

            WriteFinished(name, 0);
        }

        public bool TestStart(string name, string type, string method)
        {
            log.LogMessage(MessageImportance.High, "##teamcity[testStarted name='{0}']", Escape(name));
            return true;
        }

        static string Escape(string value)
        {
            return value.Replace("|", "||")
                        .Replace("'", "|'")
                        .Replace("\r", "|r")
                        .Replace("\n", "|n")
                        .Replace("]", "|]");
        }

        void WriteFinished(string name, double duration)
        {
            log.LogMessage(MessageImportance.High, "##teamcity[testFinished name='{0}' duration='{1}']",
                                       Escape(name),
                                       (int)(duration * 1000D));
        }

        void WriteOutput(string name, string output)
        {
            if (output != null)
                log.LogMessage(MessageImportance.High, "##teamcity[testStdOut name='{0}' out='{1}']", Escape(name), Escape(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.