CombiningStrategyAttribute
public abstract class CombiningStrategyAttribute : TestCaseBuilderAttribute, ITestBuilder, IApplyToTest
Marks a test to use a particular CombiningStrategy to join
any parameter data provided. Since this is the default, the
attribute is optional.
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Builders;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
namespace NUnit.Framework
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public abstract class CombiningStrategyAttribute : TestCaseBuilderAttribute, ITestBuilder, IApplyToTest
{
private NUnitTestCaseBuilder _builder = new NUnitTestCaseBuilder();
private IParameterDataProvider _dataProvider = new ParameterDataProvider();
private ICombiningStrategy _strategy;
protected CombiningStrategyAttribute(ICombiningStrategy strategy)
{
_strategy = strategy;
}
protected CombiningStrategyAttribute(object strategy)
: this((ICombiningStrategy)strategy)
{
}
public IEnumerable<TestMethod> BuildFrom(MethodInfo method, Test suite)
{
List<TestMethod> list = new List<TestMethod>();
ParameterInfo[] parameters = method.GetParameters();
if (parameters.Length > 0) {
IEnumerable[] array = new IEnumerable[parameters.Length];
for (int i = 0; i < parameters.Length; i++) {
array[i] = _dataProvider.GetDataFor(parameters[i]);
}
{
foreach (ITestCaseData testCase in _strategy.GetTestCases(array)) {
list.Add(_builder.BuildTestMethod(method, suite, (ParameterSet)testCase));
}
return list;
}
}
return list;
}
public void ApplyToTest(Test test)
{
string text = _strategy.GetType().Name;
if (text.EndsWith("Strategy"))
text = text.Substring(0, text.Length - 8);
test.Properties.Set("_JOINTYPE", text);
}
}
}