12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- // Alias Console to MockConsole so we don't accidentally use Console
- namespace Terminal.Gui.ApplicationTests;
- public class SyncrhonizationContextTests
- {
- [Fact]
- [AutoInitShutdown]
- public void SynchronizationContext_CreateCopy ()
- {
- SynchronizationContext context = SynchronizationContext.Current;
- Assert.NotNull (context);
- SynchronizationContext contextCopy = context.CreateCopy ();
- Assert.NotNull (contextCopy);
- Assert.NotEqual (context, contextCopy);
- }
- [Fact]
- [AutoInitShutdown]
- public void SynchronizationContext_Post ()
- {
- SynchronizationContext context = SynchronizationContext.Current;
- var success = false;
- Task.Run (
- () =>
- {
- Thread.Sleep (1_000);
- // 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);
- }
- [Fact]
- [AutoInitShutdown]
- public void SynchronizationContext_Send ()
- {
- SynchronizationContext context = SynchronizationContext.Current;
- var success = false;
- Task.Run (
- () =>
- {
- Thread.Sleep (1_000);
- // 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);
- }
- }
|