Files
speckle.xunit.runner.wpf/xunit.runner.worker/DiscoverUtil.cs
T
Jared Parsons d032f3e16d Don't use AppDomains
This is unnecessary overhead in the worker and makes the runner
significantly harder to debug.
2015-08-19 13:57:42 -07:00

67 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using xunit.runner.data;
namespace xunit.runner.worker
{
internal sealed class DiscoverUtil
{
private sealed class Impl : TestMessageVisitor<IDiscoveryCompleteMessage>
{
private readonly ITestFrameworkDiscoverer _discoverer;
private readonly BinaryWriter _writer;
private bool _continue = true;
internal Impl(ITestFrameworkDiscoverer discoverer, BinaryWriter writer)
{
_discoverer = discoverer;
_writer = writer;
}
protected override bool Visit(ITestCaseDiscoveryMessage testCaseDiscovered)
{
var testCase = testCaseDiscovered.TestCase;
var testCaseData = new TestCaseData(
_discoverer.Serialize(testCase),
testCase.DisplayName,
testCaseDiscovered.TestAssembly.Assembly.AssemblyPath);
try
{
testCaseData.WriteTo(_writer);
}
catch (Exception ex)
{
// This happens during a rude shutdown from the client.
Console.Error.WriteLine(ex.Message);
_continue = false;
}
return _continue;
}
}
internal static void Go(string fileName, Stream stream)
{
using (AssemblyHelper.SubscribeResolve())
using (var xunit = new XunitFrontController(
useAppDomain: false,
assemblyFileName: fileName,
diagnosticMessageSink: new MessageVisitor(),
shadowCopy: false))
using (var writer = new BinaryWriter(stream, Constants.Encoding, leaveOpen: true))
using (var impl = new Impl(xunit, writer))
{
xunit.Find(includeSourceInformation: false, messageSink: impl, discoveryOptions: TestFrameworkOptions.ForDiscovery());
impl.Finished.WaitOne();
}
}
}
}