OuterUnityTestActionCommand.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using NUnit.Framework.Internal;
  5. using NUnit.Framework.Internal.Commands;
  6. using UnityEngine.TestRunner.NUnitExtensions.Runner;
  7. namespace UnityEngine.TestTools
  8. {
  9. internal class OuterUnityTestActionCommand : BeforeAfterTestCommandBase<IOuterUnityTestAction>
  10. {
  11. static readonly Dictionary<MethodInfo, List<IOuterUnityTestAction>> m_TestActionsCache = new Dictionary<MethodInfo, List<IOuterUnityTestAction>>();
  12. public OuterUnityTestActionCommand(TestCommand innerCommand)
  13. : base(innerCommand, "BeforeTest", "AfterTest")
  14. {
  15. if (Test.TypeInfo.Type != null)
  16. {
  17. BeforeActions = GetTestActions(m_TestActionsCache, Test.Method.MethodInfo);
  18. AfterActions = BeforeActions;
  19. }
  20. }
  21. protected override IEnumerator InvokeBefore(IOuterUnityTestAction action, Test test, UnityTestExecutionContext context)
  22. {
  23. return action.BeforeTest(test);
  24. }
  25. protected override IEnumerator InvokeAfter(IOuterUnityTestAction action, Test test, UnityTestExecutionContext context)
  26. {
  27. return action.AfterTest(test);
  28. }
  29. protected override BeforeAfterTestCommandState GetState(UnityTestExecutionContext context)
  30. {
  31. return context.OuterUnityTestActionState;
  32. }
  33. }
  34. }