TestFixtureAttribute
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Builders;
using System;
using System.Collections;
namespace NUnit.Framework
{
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public class TestFixtureAttribute : FixtureBuilderAttribute, IFixtureBuilder, IApplyToTest
{
private readonly NUnitTestFixtureBuilder builder = new NUnitTestFixtureBuilder();
public string Description { get; set; }
public string Author { get; set; }
public Type TestOf { get; set; }
public object[] Arguments { get; set; }
public string Ignore {
get {
return IgnoreReason;
}
set {
IgnoreReason = value;
}
}
public string IgnoreReason { get; set; }
public Type[] TypeArgs { get; set; }
public string Category { get; set; }
public IList Categories {
get {
if (Category != null)
return Category.Split(new char[1] {
','
});
return null;
}
}
public TestFixtureAttribute()
: this(new object[0])
{
}
public TestFixtureAttribute(params object[] arguments)
{
Arguments = arguments;
TypeArgs = new Type[0];
}
public void ApplyToTest(Test test)
{
if (!string.IsNullOrEmpty(IgnoreReason) && test.RunState != 0) {
test.Properties.Set("_SKIPREASON", IgnoreReason);
test.RunState = RunState.Ignored;
}
if (!test.Properties.ContainsKey("Description") && Description != null)
test.Properties.Set("Description", Description);
if (!test.Properties.ContainsKey("Author") && Author != null)
test.Properties.Set("Author", Author);
if (!test.Properties.ContainsKey("TestOf") && TestOf != (Type)null)
test.Properties.Set("TestOf", TestOf.FullName);
if (Category != null) {
string[] array = Category.Split(new char[1] {
','
});
foreach (string value in array) {
test.Properties.Add("Category", value);
}
}
}
public TestSuite BuildFrom(Type type)
{
return builder.BuildFrom(type, this);
}
}
}