| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #nullable enable
- using System.Diagnostics;
- using System.Reflection;
- using JetBrains.Annotations;
- using TerminalGuiFluentTesting;
- using Xunit.Sdk;
- namespace UnitTests;
- /// <summary>
- /// Enables test functions annotated with the [SetupFakeDriver] attribute to set Application.Driver to new
- /// FakeDriver(). The driver is set up with 80 rows and 25 columns.
- /// </summary>
- [AttributeUsage (AttributeTargets.Class | AttributeTargets.Method)]
- public class SetupFakeApplicationAttribute : BeforeAfterTestAttribute
- {
- private IDisposable? _appDispose = null!;
- public override void Before (MethodInfo methodUnderTest)
- {
- Debug.WriteLine ($"Before: {methodUnderTest.Name}");
- var appFactory = new FakeApplicationFactory ();
- _appDispose = appFactory.SetupFakeApplication ();
- base.Before (methodUnderTest);
- }
- public override void After (MethodInfo methodUnderTest)
- {
- Debug.WriteLine ($"After: {methodUnderTest.Name}");
- _appDispose?.Dispose ();
- _appDispose = null;
- // TODO: This is troublesome; it seems to cause tests to hang when enabled, but shouldn't have any impact.
- // TODO: Uncomment after investigation.
- //ApplicationImpl.SetInstance (null);
- base.After (methodUnderTest);
- }
- /// <summary>
- /// Runs a single iteration of the main loop (layout, draw, run timed events etc.)
- /// </summary>
- public static void RunIteration () { ((ApplicationImpl)ApplicationImpl.Instance).Coordinator?.RunIteration (); }
- }
|