Commit af571a61 authored by BlackAngle233's avatar BlackAngle233
Browse files

212

parent 1d9b5391
using NUnit.Framework.Interfaces; using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
namespace UnityEngine.TestTools namespace UnityEngine.TestTools
{ {
internal class BeforeAfterTestCommandState : ScriptableObject internal class BeforeAfterTestCommandState : ScriptableObject
{ {
public int NextBeforeStepIndex; public int NextBeforeStepIndex;
public int NextBeforeStepPc; public int NextBeforeStepPc;
public int NextAfterStepIndex; public int NextAfterStepIndex;
public int NextAfterStepPc; public int NextAfterStepPc;
public bool TestHasRun; public bool TestHasRun;
public TestStatus CurrentTestResultStatus; public TestStatus CurrentTestResultStatus;
public string CurrentTestResultLabel; public string CurrentTestResultLabel;
public FailureSite CurrentTestResultSite; public FailureSite CurrentTestResultSite;
public string CurrentTestMessage; public string CurrentTestMessage;
public string CurrentTestStrackTrace; public string CurrentTestStrackTrace;
public bool TestAfterStarted; public bool TestAfterStarted;
public void Reset() public void Reset()
{ {
NextBeforeStepIndex = 0; NextBeforeStepIndex = 0;
NextBeforeStepPc = 0; NextBeforeStepPc = 0;
NextAfterStepIndex = 0; NextAfterStepIndex = 0;
NextAfterStepPc = 0; NextAfterStepPc = 0;
TestHasRun = false; TestHasRun = false;
CurrentTestResultStatus = TestStatus.Inconclusive; CurrentTestResultStatus = TestStatus.Inconclusive;
CurrentTestResultLabel = null; CurrentTestResultLabel = null;
CurrentTestResultSite = default(FailureSite); CurrentTestResultSite = default(FailureSite);
CurrentTestMessage = null; CurrentTestMessage = null;
CurrentTestStrackTrace = null; CurrentTestStrackTrace = null;
TestAfterStarted = false; TestAfterStarted = false;
} }
public void StoreTestResult(TestResult result) public void StoreTestResult(TestResult result)
{ {
CurrentTestResultStatus = result.ResultState.Status; CurrentTestResultStatus = result.ResultState.Status;
CurrentTestResultLabel = result.ResultState.Label; CurrentTestResultLabel = result.ResultState.Label;
CurrentTestResultSite = result.ResultState.Site; CurrentTestResultSite = result.ResultState.Site;
CurrentTestMessage = result.Message; CurrentTestMessage = result.Message;
CurrentTestStrackTrace = result.StackTrace; CurrentTestStrackTrace = result.StackTrace;
} }
public void ApplyTestResult(TestResult result) public void ApplyTestResult(TestResult result)
{ {
result.SetResult(new ResultState(CurrentTestResultStatus, CurrentTestResultLabel, CurrentTestResultSite), CurrentTestMessage, CurrentTestStrackTrace); result.SetResult(new ResultState(CurrentTestResultStatus, CurrentTestResultLabel, CurrentTestResultSite), CurrentTestMessage, CurrentTestStrackTrace);
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 7f65567c9026afb4db5de3355accc636 guid: 7f65567c9026afb4db5de3355accc636
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework.Interfaces; using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands; using NUnit.Framework.Internal.Commands;
using UnityEngine.TestRunner.NUnitExtensions.Runner; using UnityEngine.TestRunner.NUnitExtensions.Runner;
namespace UnityEngine.TestTools namespace UnityEngine.TestTools
{ {
internal class EnumerableApplyChangesToContextCommand : ApplyChangesToContextCommand, IEnumerableTestMethodCommand internal class EnumerableApplyChangesToContextCommand : ApplyChangesToContextCommand, IEnumerableTestMethodCommand
{ {
public EnumerableApplyChangesToContextCommand(TestCommand innerCommand, IEnumerable<IApplyToContext> changes) public EnumerableApplyChangesToContextCommand(TestCommand innerCommand, IEnumerable<IApplyToContext> changes)
: base(innerCommand, changes) { } : base(innerCommand, changes) { }
public IEnumerable ExecuteEnumerable(ITestExecutionContext context) public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
{ {
ApplyChanges(context); ApplyChanges(context);
if (innerCommand is IEnumerableTestMethodCommand) if (innerCommand is IEnumerableTestMethodCommand)
{ {
var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context); var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
foreach (var iterator in executeEnumerable) foreach (var iterator in executeEnumerable)
{ {
yield return iterator; yield return iterator;
} }
} }
else else
{ {
context.CurrentResult = innerCommand.Execute(context); context.CurrentResult = innerCommand.Execute(context);
} }
} }
} }
} }
\ No newline at end of file
fileFormatVersion: 2 fileFormatVersion: 2
guid: 3b4429eff9fcffb48b006e8edcc90338 guid: 3b4429eff9fcffb48b006e8edcc90338
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Collections; using System.Collections;
using System.Reflection; using System.Reflection;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Interfaces; using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands; using NUnit.Framework.Internal.Commands;
using UnityEngine.TestRunner.NUnitExtensions.Runner; using UnityEngine.TestRunner.NUnitExtensions.Runner;
namespace UnityEngine.TestTools namespace UnityEngine.TestTools
{ {
internal class EnumerableRepeatedTestCommand : DelegatingTestCommand, IEnumerableTestMethodCommand internal class EnumerableRepeatedTestCommand : DelegatingTestCommand, IEnumerableTestMethodCommand
{ {
private int repeatCount; private int repeatCount;
public EnumerableRepeatedTestCommand(RepeatAttribute.RepeatedTestCommand commandToReplace) : base(commandToReplace.GetInnerCommand()) public EnumerableRepeatedTestCommand(RepeatAttribute.RepeatedTestCommand commandToReplace) : base(commandToReplace.GetInnerCommand())
{ {
repeatCount = (int) typeof(RepeatAttribute.RepeatedTestCommand) repeatCount = (int) typeof(RepeatAttribute.RepeatedTestCommand)
.GetField("repeatCount", BindingFlags.NonPublic | BindingFlags.Instance) .GetField("repeatCount", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(commandToReplace); .GetValue(commandToReplace);
} }
public override TestResult Execute(ITestExecutionContext context) public override TestResult Execute(ITestExecutionContext context)
{ {
throw new NotImplementedException("Use ExecuteEnumerable"); throw new NotImplementedException("Use ExecuteEnumerable");
} }
public IEnumerable ExecuteEnumerable(ITestExecutionContext context) public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
{ {
var unityContext = (UnityTestExecutionContext)context; var unityContext = (UnityTestExecutionContext)context;
int count = unityContext.EnumerableRepeatedTestState; int count = unityContext.EnumerableRepeatedTestState;
while (count < repeatCount) while (count < repeatCount)
{ {
count++; count++;
unityContext.EnumerableRepeatedTestState = count; unityContext.EnumerableRepeatedTestState = count;
if (innerCommand is IEnumerableTestMethodCommand) if (innerCommand is IEnumerableTestMethodCommand)
{ {
var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context); var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
foreach (var iterator in executeEnumerable) foreach (var iterator in executeEnumerable)
{ {
yield return iterator; yield return iterator;
} }
} }
else else
{ {
context.CurrentResult = innerCommand.Execute(context); context.CurrentResult = innerCommand.Execute(context);
} }
if (context.CurrentResult.ResultState != ResultState.Success) if (context.CurrentResult.ResultState != ResultState.Success)
{ {
break; break;
} }
} }
unityContext.EnumerableRepeatedTestState = 0; unityContext.EnumerableRepeatedTestState = 0;
} }
} }
} }
\ No newline at end of file
fileFormatVersion: 2 fileFormatVersion: 2
guid: e273462feb9a65948826739f683cc9a9 guid: e273462feb9a65948826739f683cc9a9
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Collections; using System.Collections;
using System.Reflection; using System.Reflection;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Interfaces; using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands; using NUnit.Framework.Internal.Commands;
using UnityEngine.TestRunner.NUnitExtensions.Runner; using UnityEngine.TestRunner.NUnitExtensions.Runner;
namespace UnityEngine.TestTools namespace UnityEngine.TestTools
{ {
internal class EnumerableRetryTestCommand : DelegatingTestCommand, IEnumerableTestMethodCommand internal class EnumerableRetryTestCommand : DelegatingTestCommand, IEnumerableTestMethodCommand
{ {
private int retryCount; private int retryCount;
public EnumerableRetryTestCommand(RetryAttribute.RetryCommand commandToReplace) : base(commandToReplace.GetInnerCommand()) public EnumerableRetryTestCommand(RetryAttribute.RetryCommand commandToReplace) : base(commandToReplace.GetInnerCommand())
{ {
retryCount = (int) typeof(RetryAttribute.RetryCommand) retryCount = (int) typeof(RetryAttribute.RetryCommand)
.GetField("_retryCount", BindingFlags.NonPublic | BindingFlags.Instance) .GetField("_retryCount", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(commandToReplace); .GetValue(commandToReplace);
} }
public override TestResult Execute(ITestExecutionContext context) public override TestResult Execute(ITestExecutionContext context)
{ {
throw new NotImplementedException("Use ExecuteEnumerable"); throw new NotImplementedException("Use ExecuteEnumerable");
} }
public IEnumerable ExecuteEnumerable(ITestExecutionContext context) public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
{ {
var unityContext = (UnityTestExecutionContext)context; var unityContext = (UnityTestExecutionContext)context;
int count = unityContext.EnumerableRetryTestState; int count = unityContext.EnumerableRetryTestState;
while (count < retryCount) while (count < retryCount)
{ {
count++; count++;
unityContext.EnumerableRetryTestState = count; unityContext.EnumerableRetryTestState = count;
if (innerCommand is IEnumerableTestMethodCommand) if (innerCommand is IEnumerableTestMethodCommand)
{ {
var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context); var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
foreach (var iterator in executeEnumerable) foreach (var iterator in executeEnumerable)
{ {
yield return iterator; yield return iterator;
} }
} }
else else
{ {
context.CurrentResult = innerCommand.Execute(context); context.CurrentResult = innerCommand.Execute(context);
} }
if (context.CurrentResult.ResultState != ResultState.Failure) if (context.CurrentResult.ResultState != ResultState.Failure)
{ {
break; break;
} }
} }
unityContext.EnumerableRetryTestState = 0; unityContext.EnumerableRetryTestState = 0;
} }
} }
} }
\ No newline at end of file
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6de2f178a24cd2e48a0816cacd9a0583 guid: 6de2f178a24cd2e48a0816cacd9a0583
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Collections; using System.Collections;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands; using NUnit.Framework.Internal.Commands;
using UnityEngine.TestRunner.NUnitExtensions.Runner; using UnityEngine.TestRunner.NUnitExtensions.Runner;
namespace UnityEngine.TestTools namespace UnityEngine.TestTools
{ {
internal class EnumerableSetUpTearDownCommand : BeforeAfterTestCommandBase<MethodInfo> internal class EnumerableSetUpTearDownCommand : BeforeAfterTestCommandBase<MethodInfo>
{ {
public EnumerableSetUpTearDownCommand(TestCommand innerCommand) public EnumerableSetUpTearDownCommand(TestCommand innerCommand)
: base(innerCommand, "SetUp", "TearDown") : base(innerCommand, "SetUp", "TearDown")
{ {
if (Test.TypeInfo.Type != null) if (Test.TypeInfo.Type != null)
{ {
BeforeActions = GetMethodsWithAttributeFromFixture(Test.TypeInfo.Type, typeof(UnitySetUpAttribute)); BeforeActions = GetMethodsWithAttributeFromFixture(Test.TypeInfo.Type, typeof(UnitySetUpAttribute));
AfterActions = GetMethodsWithAttributeFromFixture(Test.TypeInfo.Type, typeof(UnityTearDownAttribute)).Reverse().ToArray(); AfterActions = GetMethodsWithAttributeFromFixture(Test.TypeInfo.Type, typeof(UnityTearDownAttribute)).Reverse().ToArray();
} }
} }
private static MethodInfo[] GetMethodsWithAttributeFromFixture(Type fixtureType, Type setUpType) private static MethodInfo[] GetMethodsWithAttributeFromFixture(Type fixtureType, Type setUpType)
{ {
MethodInfo[] methodsWithAttribute = Reflect.GetMethodsWithAttribute(fixtureType, setUpType, true); MethodInfo[] methodsWithAttribute = Reflect.GetMethodsWithAttribute(fixtureType, setUpType, true);
return methodsWithAttribute.Where(x => x.ReturnType == typeof(IEnumerator)).ToArray(); return methodsWithAttribute.Where(x => x.ReturnType == typeof(IEnumerator)).ToArray();
} }
protected override IEnumerator InvokeBefore(MethodInfo action, Test test, UnityTestExecutionContext context) protected override IEnumerator InvokeBefore(MethodInfo action, Test test, UnityTestExecutionContext context)
{ {
return (IEnumerator)Reflect.InvokeMethod(action, context.TestObject); return (IEnumerator)Reflect.InvokeMethod(action, context.TestObject);
} }
protected override IEnumerator InvokeAfter(MethodInfo action, Test test, UnityTestExecutionContext context) protected override IEnumerator InvokeAfter(MethodInfo action, Test test, UnityTestExecutionContext context)
{ {
return (IEnumerator)Reflect.InvokeMethod(action, context.TestObject); return (IEnumerator)Reflect.InvokeMethod(action, context.TestObject);
} }
protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context) protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context)
{ {
return context.SetUpTearDownState; return context.SetUpTearDownState;
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: dd85a35169d313840a0874aea1a28629 guid: dd85a35169d313840a0874aea1a28629
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Interfaces; using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands; using NUnit.Framework.Internal.Commands;
using NUnit.Framework.Internal.Execution; using NUnit.Framework.Internal.Execution;
using UnityEngine.TestRunner.NUnitExtensions.Runner; using UnityEngine.TestRunner.NUnitExtensions.Runner;
using UnityEngine.TestTools.TestRunner; using UnityEngine.TestTools.TestRunner;
namespace UnityEngine.TestTools namespace UnityEngine.TestTools
{ {
internal class EnumerableTestMethodCommand : TestCommand, IEnumerableTestMethodCommand internal class EnumerableTestMethodCommand : TestCommand, IEnumerableTestMethodCommand
{ {
private readonly TestMethod testMethod; private readonly TestMethod testMethod;
public EnumerableTestMethodCommand(TestMethod testMethod) public EnumerableTestMethodCommand(TestMethod testMethod)
: base(testMethod) : base(testMethod)
{ {
this.testMethod = testMethod; this.testMethod = testMethod;
} }
public IEnumerable ExecuteEnumerable(ITestExecutionContext context) public IEnumerable ExecuteEnumerable(ITestExecutionContext context)
{ {
yield return null; yield return null;
var currentExecutingTestEnumerator = new TestEnumeratorWrapper(testMethod).GetEnumerator(context); var currentExecutingTestEnumerator = new TestEnumeratorWrapper(testMethod).GetEnumerator(context);
if (currentExecutingTestEnumerator != null) if (currentExecutingTestEnumerator != null)
{ {
var testEnumeraterYieldInstruction = new TestEnumerator(context, currentExecutingTestEnumerator); var testEnumeraterYieldInstruction = new TestEnumerator(context, currentExecutingTestEnumerator);
yield return testEnumeraterYieldInstruction; yield return testEnumeraterYieldInstruction;
var enumerator = testEnumeraterYieldInstruction.Execute(); var enumerator = testEnumeraterYieldInstruction.Execute();
var executingEnumerator = ExecuteEnumerableAndRecordExceptions(enumerator, context); var executingEnumerator = ExecuteEnumerableAndRecordExceptions(enumerator, context);
while (executingEnumerator.MoveNext()) while (executingEnumerator.MoveNext())
{ {
yield return executingEnumerator.Current; yield return executingEnumerator.Current;
} }
} }
else else
{ {
if (context.CurrentResult.ResultState != ResultState.Ignored) if (context.CurrentResult.ResultState != ResultState.Ignored)
{ {
context.CurrentResult.SetResult(ResultState.Success); context.CurrentResult.SetResult(ResultState.Success);
} }
} }
} }
private static IEnumerator ExecuteEnumerableAndRecordExceptions(IEnumerator enumerator, ITestExecutionContext context) private static IEnumerator ExecuteEnumerableAndRecordExceptions(IEnumerator enumerator, ITestExecutionContext context)
{ {
while (true) while (true)
{ {
try try
{ {
if (!enumerator.MoveNext()) if (!enumerator.MoveNext())
{ {
break; break;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
context.CurrentResult.RecordException(ex); context.CurrentResult.RecordException(ex);
break; break;
} }
if (enumerator.Current is IEnumerator) if (enumerator.Current is IEnumerator)
{ {
var current = (IEnumerator)enumerator.Current; var current = (IEnumerator)enumerator.Current;
yield return ExecuteEnumerableAndRecordExceptions(current, context); yield return ExecuteEnumerableAndRecordExceptions(current, context);
} }
else else
{ {
yield return enumerator.Current; yield return enumerator.Current;
} }
} }
} }
public override TestResult Execute(ITestExecutionContext context) public override TestResult Execute(ITestExecutionContext context)
{ {
throw new NotImplementedException("Use ExecuteEnumerable"); throw new NotImplementedException("Use ExecuteEnumerable");
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 19a6f000f81e24c4a826c1abd43e77c7 guid: 19a6f000f81e24c4a826c1abd43e77c7
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Collections; using System.Collections;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands; using NUnit.Framework.Internal.Commands;
using UnityEngine.TestRunner.NUnitExtensions.Runner; using UnityEngine.TestRunner.NUnitExtensions.Runner;
namespace UnityEngine.TestTools namespace UnityEngine.TestTools
{ {
internal class ImmediateEnumerableCommand : DelegatingTestCommand internal class ImmediateEnumerableCommand : DelegatingTestCommand
{ {
public ImmediateEnumerableCommand(TestCommand innerCommand) public ImmediateEnumerableCommand(TestCommand innerCommand)
: base(innerCommand) { } : base(innerCommand) { }
public override TestResult Execute(ITestExecutionContext context) public override TestResult Execute(ITestExecutionContext context)
{ {
if (innerCommand is IEnumerableTestMethodCommand) if (innerCommand is IEnumerableTestMethodCommand)
{ {
var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context); var executeEnumerable = ((IEnumerableTestMethodCommand)innerCommand).ExecuteEnumerable(context);
foreach (var iterator in executeEnumerable) foreach (var iterator in executeEnumerable)
{ {
if (iterator != null) if (iterator != null)
{ {
throw new Exception("Only null can be yielded at this point."); throw new Exception("Only null can be yielded at this point.");
} }
} }
return context.CurrentResult; return context.CurrentResult;
} }
return innerCommand.Execute(context); return innerCommand.Execute(context);
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 8349e42a2b30c7a4abd8678c203428ba guid: 8349e42a2b30c7a4abd8678c203428ba
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands; using NUnit.Framework.Internal.Commands;
using UnityEngine.TestRunner.NUnitExtensions.Runner; using UnityEngine.TestRunner.NUnitExtensions.Runner;
namespace UnityEngine.TestTools namespace UnityEngine.TestTools
{ {
internal class OuterUnityTestActionCommand : BeforeAfterTestCommandBase<IOuterUnityTestAction> internal class OuterUnityTestActionCommand : BeforeAfterTestCommandBase<IOuterUnityTestAction>
{ {
public OuterUnityTestActionCommand(TestCommand innerCommand) public OuterUnityTestActionCommand(TestCommand innerCommand)
: base(innerCommand, "BeforeTest", "AfterTest") : base(innerCommand, "BeforeTest", "AfterTest")
{ {
if (Test.TypeInfo.Type != null) if (Test.TypeInfo.Type != null)
{ {
BeforeActions = GetUnityTestActionsFromMethod(Test.Method.MethodInfo); BeforeActions = GetUnityTestActionsFromMethod(Test.Method.MethodInfo);
AfterActions = BeforeActions; AfterActions = BeforeActions;
} }
} }
private static IOuterUnityTestAction[] GetUnityTestActionsFromMethod(MethodInfo method) private static IOuterUnityTestAction[] GetUnityTestActionsFromMethod(MethodInfo method)
{ {
var attributes = method.GetCustomAttributes(false); var attributes = method.GetCustomAttributes(false);
List<IOuterUnityTestAction> actions = new List<IOuterUnityTestAction>(); List<IOuterUnityTestAction> actions = new List<IOuterUnityTestAction>();
foreach (var attribute in attributes) foreach (var attribute in attributes)
{ {
if (attribute is IOuterUnityTestAction) if (attribute is IOuterUnityTestAction)
actions.Add(attribute as IOuterUnityTestAction); actions.Add(attribute as IOuterUnityTestAction);
} }
return actions.ToArray(); return actions.ToArray();
} }
protected override IEnumerator InvokeBefore(IOuterUnityTestAction action, Test test, UnityTestExecutionContext context) protected override IEnumerator InvokeBefore(IOuterUnityTestAction action, Test test, UnityTestExecutionContext context)
{ {
return action.BeforeTest(test); return action.BeforeTest(test);
} }
protected override IEnumerator InvokeAfter(IOuterUnityTestAction action, Test test, UnityTestExecutionContext context) protected override IEnumerator InvokeAfter(IOuterUnityTestAction action, Test test, UnityTestExecutionContext context)
{ {
return action.AfterTest(test); return action.AfterTest(test);
} }
protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context) protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context)
{ {
return context.OuterUnityTestActionState; return context.OuterUnityTestActionState;
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 0d4fc309a0784294c8ab658b53b12320 guid: 0d4fc309a0784294c8ab658b53b12320
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Collections; using System.Collections;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands; using NUnit.Framework.Internal.Commands;
using NUnit.Framework.Internal.Execution; using NUnit.Framework.Internal.Execution;
using UnityEngine.TestRunner.NUnitExtensions.Runner; using UnityEngine.TestRunner.NUnitExtensions.Runner;
namespace UnityEngine.TestTools namespace UnityEngine.TestTools
{ {
internal class SetUpTearDownCommand : BeforeAfterTestCommandBase<MethodInfo> internal class SetUpTearDownCommand : BeforeAfterTestCommandBase<MethodInfo>
{ {
public SetUpTearDownCommand(TestCommand innerCommand) public SetUpTearDownCommand(TestCommand innerCommand)
: base(innerCommand, "SetUp", "TearDown", true) : base(innerCommand, "SetUp", "TearDown", true)
{ {
if (Test.TypeInfo.Type != null) if (Test.TypeInfo.Type != null)
{ {
BeforeActions = GetMethodsWithAttributeFromFixture(Test.TypeInfo.Type, typeof(SetUpAttribute)); BeforeActions = GetMethodsWithAttributeFromFixture(Test.TypeInfo.Type, typeof(SetUpAttribute));
AfterActions = GetMethodsWithAttributeFromFixture(Test.TypeInfo.Type, typeof(TearDownAttribute)).Reverse().ToArray(); AfterActions = GetMethodsWithAttributeFromFixture(Test.TypeInfo.Type, typeof(TearDownAttribute)).Reverse().ToArray();
} }
} }
private static MethodInfo[] GetMethodsWithAttributeFromFixture(Type fixtureType, Type setUpType) private static MethodInfo[] GetMethodsWithAttributeFromFixture(Type fixtureType, Type setUpType)
{ {
MethodInfo[] methodsWithAttribute = Reflect.GetMethodsWithAttribute(fixtureType, setUpType, true); MethodInfo[] methodsWithAttribute = Reflect.GetMethodsWithAttribute(fixtureType, setUpType, true);
return methodsWithAttribute.Where(x => x.ReturnType == typeof(void)).ToArray(); return methodsWithAttribute.Where(x => x.ReturnType == typeof(void)).ToArray();
} }
protected override IEnumerator InvokeBefore(MethodInfo action, Test test, UnityTestExecutionContext context) protected override IEnumerator InvokeBefore(MethodInfo action, Test test, UnityTestExecutionContext context)
{ {
Reflect.InvokeMethod(action, context.TestObject); Reflect.InvokeMethod(action, context.TestObject);
yield return null; yield return null;
} }
protected override IEnumerator InvokeAfter(MethodInfo action, Test test, UnityTestExecutionContext context) protected override IEnumerator InvokeAfter(MethodInfo action, Test test, UnityTestExecutionContext context)
{ {
Reflect.InvokeMethod(action, context.TestObject); Reflect.InvokeMethod(action, context.TestObject);
yield return null; yield return null;
} }
protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context) protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context)
{ {
return null; return null;
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: e0db3f3921670cd4ca2e925737c3fba4 guid: e0db3f3921670cd4ca2e925737c3fba4
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.Internal; using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands; using NUnit.Framework.Internal.Commands;
using UnityEngine.TestRunner.NUnitExtensions.Runner; using UnityEngine.TestRunner.NUnitExtensions.Runner;
namespace UnityEngine.TestTools namespace UnityEngine.TestTools
{ {
internal class TestActionCommand : BeforeAfterTestCommandBase<ITestAction> internal class TestActionCommand : BeforeAfterTestCommandBase<ITestAction>
{ {
public TestActionCommand(TestCommand innerCommand) public TestActionCommand(TestCommand innerCommand)
: base(innerCommand, "BeforeTest", "AfterTest", true) : base(innerCommand, "BeforeTest", "AfterTest", true)
{ {
if (Test.TypeInfo.Type != null) if (Test.TypeInfo.Type != null)
{ {
BeforeActions = GetTestActionsFromMethod(Test.Method.MethodInfo); BeforeActions = GetTestActionsFromMethod(Test.Method.MethodInfo);
AfterActions = BeforeActions; AfterActions = BeforeActions;
} }
} }
private static ITestAction[] GetTestActionsFromMethod(MethodInfo method) private static ITestAction[] GetTestActionsFromMethod(MethodInfo method)
{ {
var attributes = method.GetCustomAttributes(false); var attributes = method.GetCustomAttributes(false);
List<ITestAction> actions = new List<ITestAction>(); List<ITestAction> actions = new List<ITestAction>();
foreach (var attribute in attributes) foreach (var attribute in attributes)
{ {
if (attribute is ITestAction) if (attribute is ITestAction)
actions.Add(attribute as ITestAction); actions.Add(attribute as ITestAction);
} }
return actions.ToArray(); return actions.ToArray();
} }
protected override IEnumerator InvokeBefore(ITestAction action, Test test, UnityTestExecutionContext context) protected override IEnumerator InvokeBefore(ITestAction action, Test test, UnityTestExecutionContext context)
{ {
action.BeforeTest(test); action.BeforeTest(test);
yield return null; yield return null;
} }
protected override IEnumerator InvokeAfter(ITestAction action, Test test, UnityTestExecutionContext context) protected override IEnumerator InvokeAfter(ITestAction action, Test test, UnityTestExecutionContext context)
{ {
action.AfterTest(test); action.AfterTest(test);
yield return null; yield return null;
} }
protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context) protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context)
{ {
return null; return null;
} }
} }
} }
fileFormatVersion: 2 fileFormatVersion: 2
guid: 2de8ba3b840049641897e0da7ce1d5cd guid: 2de8ba3b840049641897e0da7ce1d5cd
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2
defaultReferences: [] defaultReferences: []
executionOrder: 0 executionOrder: 0
icon: {instanceID: 0} icon: {instanceID: 0}
userData: userData:
assetBundleName: assetBundleName:
assetBundleVariant: assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment