BaseDelegator.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Threading;
  3. using NUnit.Framework.Internal;
  4. namespace UnityEngine.TestTools.NUnitExtensions
  5. {
  6. internal abstract class BaseDelegator
  7. {
  8. protected ManualResetEvent m_Signal = new ManualResetEvent(false);
  9. protected object m_Result;
  10. protected Exception m_Exception;
  11. protected ITestExecutionContext m_Context;
  12. protected bool m_Aborted;
  13. protected object HandleResult()
  14. {
  15. SetCurrentTestContext();
  16. if (m_Exception != null)
  17. {
  18. var temp = m_Exception;
  19. m_Exception = null;
  20. throw temp;
  21. }
  22. var tempResult = m_Result;
  23. m_Result = null;
  24. return tempResult;
  25. }
  26. protected void WaitForSignal()
  27. {
  28. while (!m_Signal.WaitOne(100))
  29. {
  30. if (m_Aborted)
  31. {
  32. m_Aborted = false;
  33. Reflect.MethodCallWrapper = null;
  34. throw new Exception();
  35. }
  36. }
  37. }
  38. public void Abort()
  39. {
  40. m_Aborted = true;
  41. }
  42. protected void SetCurrentTestContext()
  43. {
  44. var prop = typeof(TestExecutionContext).GetProperty("CurrentContext");
  45. if (prop != null)
  46. {
  47. prop.SetValue(null, m_Context, null);
  48. }
  49. }
  50. }
  51. }