A game about forced loneliness, made by TACStudios
1using System;
2using System.Collections;
3using System.Reflection;
4using NUnit.Framework;
5using NUnit.Framework.Interfaces;
6using NUnit.Framework.Internal;
7
8namespace UnityEngine.TestTools.TestRunner
9{
10 internal class TestEnumeratorWrapper
11 {
12 private readonly TestMethod m_TestMethod;
13
14 public TestEnumeratorWrapper(TestMethod testMethod)
15 {
16 m_TestMethod = testMethod;
17 }
18
19 public IEnumerator GetEnumerator(ITestExecutionContext context)
20 {
21 if (m_TestMethod.Method.ReturnType.Type == typeof(IEnumerator))
22 {
23 return HandleEnumerableTest(context);
24 }
25 var message = string.Format("Return type {0} of {1} in {2} is not supported.",
26 m_TestMethod.Method.ReturnType, m_TestMethod.Method.Name, m_TestMethod.Method.TypeInfo.FullName);
27 if (m_TestMethod.Method.ReturnType.Type == typeof(IEnumerable))
28 {
29 message += "\nDid you mean IEnumerator?";
30 }
31 throw new InvalidSignatureException(message);
32 }
33
34 private IEnumerator HandleEnumerableTest(ITestExecutionContext context)
35 {
36 try
37 {
38 return m_TestMethod.Method.MethodInfo.Invoke(context.TestObject, m_TestMethod.parms != null ? m_TestMethod.parms.OriginalArguments : null) as IEnumerator;
39 }
40 catch (TargetInvocationException e)
41 {
42 if (e.InnerException is IgnoreException)
43 {
44 context.CurrentResult.SetResult(ResultState.Ignored, e.InnerException.Message);
45 return null;
46 }
47 throw;
48 }
49 }
50 }
51}