TestEnumerator.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using System.Collections;
  3. using NUnit.Framework;
  4. using NUnit.Framework.Interfaces;
  5. using NUnit.Framework.Internal;
  6. namespace UnityEngine.TestTools
  7. {
  8. internal class TestEnumerator
  9. {
  10. private readonly ITestExecutionContext m_Context;
  11. private static IEnumerator m_TestEnumerator;
  12. public static IEnumerator Enumerator { get { return m_TestEnumerator; } }
  13. public TestEnumerator(ITestExecutionContext context, IEnumerator testEnumerator)
  14. {
  15. m_Context = context;
  16. m_TestEnumerator = testEnumerator;
  17. }
  18. public IEnumerator Execute()
  19. {
  20. m_Context.CurrentResult.SetResult(ResultState.Success);
  21. while (true)
  22. {
  23. object current = null;
  24. try
  25. {
  26. if (!m_TestEnumerator.MoveNext())
  27. {
  28. yield break;
  29. }
  30. if (!m_Context.CurrentResult.ResultState.Equals(ResultState.Success))
  31. {
  32. yield break;
  33. }
  34. current = m_TestEnumerator.Current;
  35. }
  36. catch (Exception exception)
  37. {
  38. m_Context.CurrentResult.RecordException(exception);
  39. yield break;
  40. }
  41. yield return current;
  42. }
  43. }
  44. }
  45. }