Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
// *********************************************************************
// Copyright 2007, Andreas Schlapsi
// This is free software licensed under the MIT license.
// *********************************************************************
using System;
using System.Reflection;
using NUnit.Core;
using NUnit.Core.Extensibility;
namespace NUnit.Core.Extensions.RowTest
{
[NUnitAddin(Name = "Row Test Extension")]
public class RowTestAddIn : IAddin, ITestCaseBuilder
{
private RowTestFactory _testFactory;
public RowTestAddIn()
{
_testFactory = new RowTestFactory();
}
public bool Install(IExtensionHost host)
{
if (host == null)
throw new ArgumentNullException("host");
IExtensionPoint testCaseBuilders = host.GetExtensionPoint("TestCaseBuilders");
if (testCaseBuilders == null)
return false;
testCaseBuilders.Install(this);
return true;
}
public bool CanBuildFrom(MethodInfo method)
{
return RowTestFramework.IsRowTest(method);
}
public Test BuildFrom(MethodInfo method)
{
if (method == null)
throw new ArgumentNullException("method");
RowTestSuite suite = _testFactory.CreateRowTestSuite(method);
Attribute[] rows = RowTestFramework.GetRowAttributes(method);
foreach (Attribute row in rows)
suite.Add(_testFactory.CreateRowTestCase(row, method));
return suite;
}
}
}

View File

@@ -0,0 +1,37 @@
// *********************************************************************
// Copyright 2007, Andreas Schlapsi
// This is free software licensed under the MIT license.
// *********************************************************************
using System;
using System.Reflection;
using System.Text;
using NUnit.Core;
namespace NUnit.Core.Extensions.RowTest
{
public class RowTestCase : NUnitTestMethod
{
private object[] _arguments;
public RowTestCase(MethodInfo method, string testName, object[] arguments)
: base(method)
{
RowTestNameBuilder testNameBuilder = new RowTestNameBuilder(method, testName, arguments);
this.TestName.Name = testNameBuilder.TestName;
this.TestName.FullName = testNameBuilder.FullTestName;
_arguments = arguments;
}
public object[] Arguments
{
get { return _arguments; }
}
public override void RunTestMethod(TestCaseResult testResult)
{
object[] arguments = _arguments != null ? _arguments : new object[] { null };
Reflect.InvokeMethod(this.Method, this.Fixture, arguments);
}
}
}

View File

@@ -0,0 +1,79 @@
// *********************************************************************
// Copyright 2007, Andreas Schlapsi
// This is free software licensed under the MIT license.
// *********************************************************************
using System;
using System.Reflection;
using NUnit.Core;
namespace NUnit.Core.Extensions.RowTest
{
public class RowTestFactory
{
public RowTestFactory()
{
}
public RowTestSuite CreateRowTestSuite(MethodInfo method)
{
if (method == null)
throw new ArgumentNullException("method");
RowTestSuite testSuite = new RowTestSuite(method);
NUnitFramework.ApplyCommonAttributes(method, testSuite);
return testSuite;
}
public RowTestCase CreateRowTestCase(Attribute row, MethodInfo method)
{
if (row == null)
throw new ArgumentNullException("row");
if (method == null)
throw new ArgumentNullException("method");
object[] rowArguments = RowTestFramework.GetRowArguments(row);
rowArguments = FilterSpecialValues(rowArguments);
string testName = RowTestFramework.GetTestName(row);
Type expectedExceptionType = RowTestFramework.GetExpectedExceptionType(row);
RowTestCase testCase = new RowTestCase(method, testName, rowArguments);
if (expectedExceptionType != null)
{
testCase.ExceptionExpected = true;
testCase.ExpectedExceptionType = expectedExceptionType;
testCase.ExpectedMessage = RowTestFramework.GetExpectedExceptionMessage(row);
}
return testCase;
}
private object[] FilterSpecialValues(object[] arguments)
{
if (arguments == null)
return null;
for (int i = 0; i < arguments.Length; i++)
{
if (RowTestFramework.IsSpecialValue(arguments[i]))
arguments[i] = MapSpecialValue(arguments[i]);
}
return arguments;
}
private object MapSpecialValue(object specialValue)
{
switch (specialValue.ToString())
{
case "Null":
return null;
default:
return specialValue;
}
}
}
}

View File

@@ -0,0 +1,65 @@
// *********************************************************************
// Copyright 2007, Andreas Schlapsi
// This is free software licensed under the MIT license.
// *********************************************************************
using System;
using System.Reflection;
using NUnit.Core;
namespace NUnit.Core.Extensions.RowTest
{
public sealed class RowTestFramework
{
public const string RowTestAttribute = "NUnit.Framework.Extensions.RowTestAttribute";
public const string RowAttribute = "NUnit.Framework.Extensions.RowAttribute";
public const string SpecialValueEnum = "NUnit.Framework.Extensions.SpecialValue";
private RowTestFramework()
{
}
public static bool IsRowTest(MethodInfo method)
{
if (method == null)
return false;
return Reflect.HasAttribute(method, RowTestAttribute, false);;
}
public static Attribute[] GetRowAttributes(MethodInfo method)
{
if (method == null)
throw new ArgumentNullException("method");
return Reflect.GetAttributes(method, RowAttribute, false);
}
public static object[] GetRowArguments(Attribute attribute)
{
return Reflect.GetPropertyValue(attribute, "Arguments") as object[];
}
public static bool IsSpecialValue(object argument)
{
if (argument == null)
return false;
return argument.GetType().FullName == SpecialValueEnum;
}
public static Type GetExpectedExceptionType(Attribute attribute)
{
return Reflect.GetPropertyValue(attribute, "ExpectedException") as Type;
}
public static string GetExpectedExceptionMessage(Attribute attribute)
{
return Reflect.GetPropertyValue(attribute, "ExceptionMessage") as string;
}
public static string GetTestName(Attribute attribute)
{
return Reflect.GetPropertyValue(attribute, "TestName") as string;
}
}
}

View File

@@ -0,0 +1,92 @@
// *********************************************************************
// Copyright 2007, Andreas Schlapsi
// This is free software licensed under the MIT license.
// *********************************************************************
using System;
using System.Reflection;
using System.Text;
namespace NUnit.Core.Extensions.RowTest
{
public class RowTestNameBuilder
{
private MethodInfo _method;
private string _baseTestName;
private object[] _arguments;
private string _argumentList;
public RowTestNameBuilder(MethodInfo method, string baseTestName, object[] arguments)
{
_method = method;
_baseTestName = baseTestName;
_arguments = arguments;
}
public MethodInfo Method
{
get { return _method; }
}
public string BaseTestName
{
get { return _baseTestName; }
}
public object[] Arguments
{
get { return _arguments; }
}
public string TestName
{
get
{
string baseTestName = _baseTestName;
if (baseTestName == null || baseTestName.Length == 0)
baseTestName = _method.Name;
return baseTestName + GetArgumentList();
}
}
public string FullTestName
{
get { return _method.DeclaringType.FullName + "." + TestName; }
}
private string GetArgumentList()
{
if (_argumentList == null)
_argumentList = "(" + CreateArgumentList() + ")";
return _argumentList;
}
private string CreateArgumentList()
{
if (_arguments == null)
return "null";
StringBuilder argumentListBuilder = new StringBuilder();
for (int i = 0; i < _arguments.Length; i++)
{
if (i > 0)
argumentListBuilder.Append(", ");
argumentListBuilder.Append (GetArgumentString (_arguments[i]));
}
return argumentListBuilder.ToString();
}
private string GetArgumentString (object argument)
{
if (argument == null)
return "null";
return argument.ToString();
}
}
}

View File

@@ -0,0 +1,50 @@
// *********************************************************************
// Copyright 2007, Andreas Schlapsi
// This is free software licensed under the MIT license.
// *********************************************************************
using System;
using System.Reflection;
using NUnit.Core;
namespace NUnit.Core.Extensions.RowTest
{
public class RowTestSuite : TestSuite
{
private static string GetParentName(MethodInfo method)
{
if (method == null)
throw new ArgumentNullException("method");
return method.DeclaringType.ToString();
}
private static string GetTestName(MethodInfo method)
{
if (method == null)
throw new ArgumentNullException("method");
return method.Name;
}
public RowTestSuite(MethodInfo method)
: base (GetParentName(method), GetTestName(method))
{
}
public override TestResult Run(EventListener listener, ITestFilter filter)
{
if (this.Parent != null)
this.Fixture = this.Parent.Fixture;
return base.Run(listener, filter);
}
protected override void DoOneTimeSetUp(TestResult suiteResult)
{
}
protected override void DoOneTimeTearDown(TestResult suiteResult)
{
}
}
}