TheoryAttribute
Adding this attribute to a method within a TestFixtureAttribute
class makes the method callable from the NUnit test runner. There is a property
called Description which is optional which you can provide a more detailed test
description. This class cannot be inherited.
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Builders;
using System;
using System.Collections;
using System.Collections.Generic;
namespace NUnit.Framework
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class TheoryAttribute : NUnitAttribute, ITestBuilder, IImplyFixture
{
private NUnitTestCaseBuilder _builder = new NUnitTestCaseBuilder();
private IParameterDataProvider _dataProvider = new DatapointProvider();
public IEnumerable<TestMethod> BuildFrom(IMethodInfo method, Test suite)
{
IParameterInfo[] parameters = method.GetParameters();
List<TestMethod> list = new List<TestMethod>();
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 new CombinatorialStrategy().GetTestCases(array)) {
list.Add(_builder.BuildTestMethod(method, suite, (TestCaseParameters)testCase));
}
return list;
}
}
return list;
}
}
}