Skip to content

Instantly share code, notes, and snippets.

@JoeGannon
Last active September 28, 2017 21:33
Show Gist options
  • Save JoeGannon/a7ae55a545f8471c7d173744651ac3a7 to your computer and use it in GitHub Desktop.
Save JoeGannon/a7ae55a545f8471c7d173744651ac3a7 to your computer and use it in GitHub Desktop.
namespace YourNamespace
{
using System.Collections.Generic;
using System.Reflection;
using Construktion;
using Xunit.Abstractions;
using Xunit.Sdk;
[DataDiscoverer("YourNamespace.NoDataDiscovery", "YourAssembly")]
public class ConstruktionData : DataAttribute
{
private readonly Construktion _construktion;
public ConstruktionData()
{
_construktion = new Construktion();
}
public override IEnumerable<object[]> GetData(MethodInfo testMethod)
{
var parameters = new List<object>();
foreach (var paramInfo in testMethod.GetParameters())
{
var result = _construktion.Construct(paramInfo);
parameters.Add(result);
}
return new[] { parameters.ToArray() };
}
}
public class NoDataDiscovery : DataDiscoverer
{
public override bool SupportsDiscoveryEnumeration(IAttributeInfo dataAttribute, IMethodInfo testMethod)
{
//If this was true Xunit will build out the parameters during test discovery and
//display the constructed values in the test runner as: "TestClass.Case(param1: value, param2: value)".
//We want to suppress that behavior since the parameters are generated dynamically, and the actual values
//used in the test case run would be different than what's displayed in the test runner.
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment