TestProgressReporter
TestProgressReporter translates ITestListener events into
the async callbacks that are used to inform the client
software about the progress of a test run.
using NUnit.Framework.Interfaces;
using System;
using System.Web.UI;
namespace NUnit.Framework.Internal
{
public class TestProgressReporter : ITestListener
{
private static Logger log = InternalTrace.GetLogger("TestProgressReporter");
private ICallbackEventHandler handler;
public TestProgressReporter(ICallbackEventHandler handler)
{
this.handler = handler;
}
public void TestStarted(ITest test)
{
string text = (test is TestSuite) ? "start-suite" : "start-test";
try {
string text2 = $"""{text}""{test.Id}""{FormatAttributeValue(test.Name)}""{FormatAttributeValue(test.FullName)}""";
handler.RaiseCallbackEvent(text2);
} catch (Exception ex) {
log.Error("Exception processing " + test.FullName + Env.NewLine + ex.ToString());
}
}
public void TestFinished(ITestResult result)
{
try {
handler.RaiseCallbackEvent(result.ToXml(false).OuterXml);
} catch (Exception ex) {
log.Error("Exception processing " + result.FullName + Env.NewLine + ex.ToString());
}
}
private static string FormatAttributeValue(string original)
{
return original.Replace("&", "&").Replace("\"", """).Replace("'", "'")
.Replace("<", "<")
.Replace(">", ">");
}
}
}