Files
Terminal.Gui/UnitTests/AssemblyInfo.cs
BDisp 9dc40088bc UseKeysUpDownAsKeysLeftRight and UseSubMenusSingleFrame cannot be both true. (#1789)
* Fixes the throwing an exception if menu item is null.

* UseKeysUpDownAsKeysLeftRight and UseSubMenusSingleFrame cannot be both true.

* Refactoring the code.

* Trying fixing the Run_All_Scenarios unit test.

* Fixing typo to test again.

* Added Attribute suffix to he AutoInitShutdown class.
2022-06-12 09:09:41 -07:00

34 lines
1.1 KiB
C#

using System;
using System.Diagnostics;
using System.Reflection;
using Terminal.Gui;
using Xunit;
// Since Application is a singleton we can't run tests in parallel
[assembly: CollectionBehavior (DisableTestParallelization = true)]
// This class enables test functions annotated with the [AutoInitShutdown] attribute to
// automatically call Application.Init before called and Application.Shutdown after
//
// This is necessary because a) Application is a singleton and Init/Shutdown must be called
// as a pair, and b) all unit test functions should be atomic.
[AttributeUsage (AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class AutoInitShutdownAttribute : Xunit.Sdk.BeforeAfterTestAttribute {
static bool _init = false;
public override void Before (MethodInfo methodUnderTest)
{
if (_init) {
throw new InvalidOperationException ("After did not run.");
}
Application.Init (new FakeDriver (), new FakeMainLoop (() => FakeConsole.ReadKey (true)));
_init = true;
}
public override void After (MethodInfo methodUnderTest)
{
Application.Shutdown ();
_init = false;
}
}