A game about forced loneliness, made by TACStudios
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Linq;
5using System.Reflection;
6using NUnit.Framework.Internal;
7using NUnit.Framework.Internal.Commands;
8using Unity.Profiling;
9using UnityEngine.TestRunner.NUnitExtensions.Runner;
10
11namespace UnityEngine.TestTools
12{
13 internal class EnumerableSetUpTearDownCommand : BeforeAfterTestCommandBase<MethodInfo>
14 {
15 private static readonly Dictionary<Type, List<MethodInfo>> m_BeforeActionsCache = new Dictionary<Type, List<MethodInfo>>();
16 private static readonly Dictionary<Type, List<MethodInfo>> m_AfterActionsCache = new Dictionary<Type, List<MethodInfo>>();
17
18 public EnumerableSetUpTearDownCommand(TestCommand innerCommand)
19 : base(innerCommand, "SetUp", "TearDown")
20 {
21 using (new ProfilerMarker(nameof(EnumerableSetUpTearDownCommand)).Auto())
22 {
23 if (Test.TypeInfo.Type != null)
24 {
25 BeforeActions = GetActions(m_BeforeActionsCache, Test.TypeInfo.Type, typeof(UnitySetUpAttribute), new[] {typeof(IEnumerator)});
26 AfterActions = GetActions(m_AfterActionsCache, Test.TypeInfo.Type, typeof(UnityTearDownAttribute), new[] {typeof(IEnumerator)}).Reverse().ToArray();
27 }
28 }
29 }
30
31 protected override bool MoveAfterEnumerator(IEnumerator enumerator, Test test)
32 {
33 using (new ProfilerMarker(test.Name + ".TearDown").Auto())
34 return base.MoveAfterEnumerator(enumerator, test);
35 }
36
37 protected override bool MoveBeforeEnumerator(IEnumerator enumerator, Test test)
38 {
39 using (new ProfilerMarker(test.Name + ".Setup").Auto())
40 return base.MoveBeforeEnumerator(enumerator, test);
41 }
42
43 protected override IEnumerator InvokeBefore(MethodInfo action, Test test, UnityTestExecutionContext context)
44 {
45 return (IEnumerator)Reflect.InvokeMethod(action, context.TestObject);
46 }
47
48 protected override IEnumerator InvokeAfter(MethodInfo action, Test test, UnityTestExecutionContext context)
49 {
50 return (IEnumerator)Reflect.InvokeMethod(action, context.TestObject);
51 }
52
53 protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context)
54 {
55 return context.SetUpTearDownState;
56 }
57 }
58}