Merge pull request #54 from remcomulder/master

Updates from NCrunch integration
This commit is contained in:
Brad Wilson 2014-04-12 09:40:25 -07:00
Родитель 1eaf6f9bc6 9deeb474b7
Коммит 7971a1b866
13 изменённых файлов: 125 добавлений и 25 удалений

Просмотреть файл

@ -6,6 +6,7 @@ internal static class TestOptionsNames
internal static class Execution
{
public static readonly string SynchronousMessageReporting = "xunit.SynchronousMessageReporting";
public static readonly string DisableParallelization = "xunit.DisableParallelization";
public static readonly string MaxParallelThreads = "xunit.MaxParallelThreads";
}

Просмотреть файл

@ -63,5 +63,10 @@ namespace Xunit.Abstractions
/// assembly.
/// </remarks>
string UniqueID { get; }
/// <summary>
/// The arguments that will be passed to the test method.
/// </summary>
object[] Arguments { get; }
}
}

Просмотреть файл

@ -87,18 +87,20 @@ namespace Xunit.Sdk
var discovererAttribute = traitAttribute.GetCustomAttributes(typeof(TraitDiscovererAttribute)).First();
var args = discovererAttribute.GetConstructorArguments().Cast<string>().ToList();
var discovererType = Reflector.GetType(args[1], args[0]);
var discoverer = (ITraitDiscoverer)Activator.CreateInstance(discovererType);
foreach (var keyValuePair in discoverer.GetTraits(traitAttribute))
Traits.Add(keyValuePair.Key, keyValuePair.Value);
if (discovererType != null)
{
var discoverer = (ITraitDiscoverer) Activator.CreateInstance(discovererType);
foreach (var keyValuePair in discoverer.GetTraits(traitAttribute))
Traits.Add(keyValuePair.Key, keyValuePair.Value);
}
}
uniqueID = new Lazy<string>(GetUniqueID, true);
}
/// <summary>
/// The arguments that will be passed to the test method.
/// </summary>
/// <inheritdoc/>
public object[] Arguments { get; private set; }
/// <inheritdoc/>

Просмотреть файл

@ -130,7 +130,7 @@ namespace Xunit.Sdk
var ordererAttribute = assemblyInfo.GetCustomAttributes(typeof(TestCaseOrdererAttribute)).SingleOrDefault();
var orderer = ordererAttribute != null ? GetTestCaseOrderer(ordererAttribute) : new DefaultTestCaseOrderer();
using (var messageBus = new MessageBus(messageSink))
using (var messageBus = createMessageBus(messageSink, executionOptions))
{
try
{
@ -179,6 +179,14 @@ namespace Xunit.Sdk
}
}
private static IMessageBus createMessageBus(IMessageSink messageSink, ITestFrameworkOptions executionOptions)
{
if (executionOptions.GetValue(TestOptionsNames.Execution.SynchronousMessageReporting, false))
return new SynchronousMessageBus(messageSink);
return new MessageBus(messageSink);
}
private async Task<RunSummary> RunTestCollectionAsync(IMessageBus messageBus,
ITestCollection collection,
IEnumerable<XunitTestCase> testCases,

Просмотреть файл

@ -0,0 +1,29 @@
using Xunit.Abstractions;
namespace Xunit.Sdk
{
/// <summary>
/// This is an internal class, and is not intended to be called from end-user code.
/// </summary>
public class SynchronousMessageBus : IMessageBus
{
private IMessageSink _messageSink;
/// <summary/>
public SynchronousMessageBus(IMessageSink messageSink)
{
_messageSink = messageSink;
}
public void Dispose()
{
}
/// <summary/>
public bool QueueMessage(IMessageSinkMessage message)
{
return _messageSink.OnMessage(message);
}
}
}

Просмотреть файл

@ -147,6 +147,7 @@
<Compile Include="Sdk\Reflection\ReflectionAttributeInfo.cs" />
<Compile Include="Sdk\Reflection\Reflector.cs" />
<Compile Include="Sdk\SerializationHelper.cs" />
<Compile Include="Sdk\SynchronousMessageBus.cs" />
<Compile Include="Sdk\TestClassException.cs" />
<Compile Include="Sdk\TestMessageVisitor.cs" />
<Compile Include="Sdk\TraitDiscoverer.cs" />

Просмотреть файл

@ -93,6 +93,9 @@ namespace Xunit
get { return reflectionWrapper.UniqueID; }
}
/// <inheritdoc/>
public object[] Arguments { get; private set; }
/// <inheritdoc/>
public void Dispose()
{

Просмотреть файл

@ -9,6 +9,15 @@ namespace Xunit
/// </summary>
public class XunitExecutionOptions : TestFrameworkOptions
{
/// <summary>
/// Gets or sets a flag that determines whether xunit should report test results synchronously.
/// </summary>
public bool SynchronousMessageReporting
{
get { return GetValue<bool>(TestOptionsNames.Execution.SynchronousMessageReporting, false); }
set { SetValue(TestOptionsNames.Execution.SynchronousMessageReporting, value); }
}
/// <summary>
/// Gets or sets a flag to disable parallelization.
/// </summary>

Просмотреть файл

@ -28,6 +28,7 @@ public class TestCase : ITestCase
public ITestCollection TestCollection { get; set; }
public Dictionary<string, List<string>> Traits { get; set; }
public string UniqueID { get; set; }
public object[] Arguments { get; set; }
public void Dispose() { }
}

Просмотреть файл

@ -7,27 +7,11 @@ using Xunit.Sdk;
public class MessageBusTests
{
IMessageSink SpySink(List<IMessageSinkMessage> messages = null)
{
var result = Substitute.For<IMessageSink>();
result.OnMessage(null).ReturnsForAnyArgs(
callInfo =>
{
if (messages != null)
messages.Add((IMessageSinkMessage)callInfo[0]);
return true;
});
return result;
}
[Fact]
public void QueuedMessageShowUpInMessageSink()
{
var messages = new List<IMessageSinkMessage>();
var sink = SpySink(messages);
var sink = SpyMessageSink.Create(messages);
var msg1 = Substitute.For<IMessageSinkMessage>();
var msg2 = Substitute.For<IMessageSinkMessage>();
var msg3 = Substitute.For<IMessageSinkMessage>();
@ -49,7 +33,7 @@ public class MessageBusTests
[Fact]
public void TryingToQueueMessageAfterDisposingThrows()
{
var bus = new MessageBus(SpySink());
var bus = new MessageBus(SpyMessageSink.Create());
bus.Dispose();
var exception = Record.Exception(

Просмотреть файл

@ -0,0 +1,25 @@
using System.Collections.Generic;
using NSubstitute;
using Xunit.Abstractions;
namespace Xunit.Sdk
{
public static class SpyMessageSink
{
public static IMessageSink Create(List<IMessageSinkMessage> messages = null, bool returnResult = true)
{
var result = Substitute.For<IMessageSink>();
result.OnMessage(null).ReturnsForAnyArgs(
callInfo =>
{
if (messages != null)
messages.Add((IMessageSinkMessage)callInfo[0]);
return returnResult;
});
return result;
}
}
}

Просмотреть файл

@ -0,0 +1,30 @@
using System.Collections.Generic;
using NSubstitute;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
public class SynchronousMessageBusTests
{
[Fact]
public void MessagesAreDispatchedImmediatelyFromBus()
{
var msg1 = Substitute.For<IMessageSinkMessage>();
var dispatchedMessages = new List<IMessageSinkMessage>();
using (var bus = new SynchronousMessageBus(SpyMessageSink.Create(dispatchedMessages)))
{
Assert.True(bus.QueueMessage(msg1));
}
Assert.Collection(dispatchedMessages, message => Assert.Same(msg1, message));
}
[Fact]
public void BusShouldReportShutdownWhenMessageSinkReturnsFalse()
{
using (var bus = new SynchronousMessageBus(SpyMessageSink.Create(returnResult: false)))
{
Assert.False(bus.QueueMessage(Substitute.For<IMessageSinkMessage>()));
}
}
}

Просмотреть файл

@ -96,6 +96,8 @@
<Compile Include="Sdk\Frameworks\XunitTheoryTestCaseTests.cs" />
<Compile Include="Sdk\MessageBusTests.cs" />
<Compile Include="Sdk\Frameworks\TheoryDiscovererTests.cs" />
<Compile Include="Sdk\SpyMessageSink.cs" />
<Compile Include="Sdk\SynchronousMessageBusTests.cs" />
<Compile Include="Sdk\TestCaseSerializerTests.cs" />
<Compile Include="SerializationTests.cs" />
</ItemGroup>