Files
Terminal.Gui/UnitTests/Application/SynchronizatonContextTests.cs
2024-11-25 10:12:01 -07:00

94 lines
2.9 KiB
C#

// Alias Console to MockConsole so we don't accidentally use Console
namespace Terminal.Gui.ApplicationTests;
public class SyncrhonizationContextTests
{
[Fact(Skip = "Causes ubuntu to crash in github action.")]
public void SynchronizationContext_CreateCopy ()
{
Application.Init ();
SynchronizationContext context = SynchronizationContext.Current;
Assert.NotNull (context);
SynchronizationContext contextCopy = context.CreateCopy ();
Assert.NotNull (contextCopy);
Assert.NotEqual (context, contextCopy);
Application.Shutdown ();
}
[Theory]
[InlineData (typeof (FakeDriver))]
//[InlineData (typeof (NetDriver))]
[InlineData (typeof (WindowsDriver))]
//[InlineData (typeof (CursesDriver))]
public void SynchronizationContext_Post (Type driverType)
{
Application.Init (driverName: driverType.Name);
SynchronizationContext context = SynchronizationContext.Current;
var success = false;
Task.Run (
() =>
{
Thread.Sleep (500);
// non blocking
context.Post (
delegate
{
success = true;
// then tell the application to quit
Application.Invoke (() => Application.RequestStop ());
},
null
);
Assert.False (success);
}
);
// blocks here until the RequestStop is processed at the end of the test
Application.Run ().Dispose ();
Assert.True (success);
Application.Shutdown ();
}
[Fact]
[AutoInitShutdown]
public void SynchronizationContext_Send ()
{
Application.Init ();
SynchronizationContext context = SynchronizationContext.Current;
var success = false;
Task.Run (
() =>
{
Thread.Sleep (500);
// blocking
context.Send (
delegate
{
success = true;
// then tell the application to quit
Application.Invoke (() => Application.RequestStop ());
},
null
);
Assert.True (success);
}
);
// blocks here until the RequestStop is processed at the end of the test
Application.Run ().Dispose ();
Assert.True (success);
Application.Shutdown ();
}
}