mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
This commit is contained in:
45
Tests/UnitTests/SetupFakeApplicationAttribute.cs
Normal file
45
Tests/UnitTests/SetupFakeApplicationAttribute.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
#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}");
|
||||
|
||||
_appDispose?.Dispose ();
|
||||
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;
|
||||
|
||||
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 (); }
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user