2
0

AssemblyInfo.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using System.Diagnostics;
  3. using System.Reflection;
  4. using Terminal.Gui;
  5. using Xunit;
  6. // Since Application is a singleton we can't run tests in parallel
  7. [assembly: CollectionBehavior (DisableTestParallelization = true)]
  8. // This class enables test functions annotaed with the [AutoInitShutdown] attribute to
  9. // automatically call Application.Init before called and Application.Shutdown after
  10. //
  11. // This is necessary because a) Application is a singleton and Init/Shutdown must be called
  12. // as a pair, and b) all unit test functions should be atomic.
  13. [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
  14. public class AutoInitShutdown : Xunit.Sdk.BeforeAfterTestAttribute {
  15. static bool _init = false;
  16. public override void Before (MethodInfo methodUnderTest)
  17. {
  18. if (_init) {
  19. throw new InvalidOperationException ("After did not run.");
  20. }
  21. Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
  22. _init = true;
  23. }
  24. public override void After (MethodInfo methodUnderTest)
  25. {
  26. Application.Shutdown ();
  27. _init = false;
  28. }
  29. }