mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2026-01-01 16:59:35 +01:00
* touching publish.yml
* Fixed UICatalog bugs. Added fluent tests.
* marked v1 menu stuff as obsolte
* Tweaks.
Added View.GetSubMenus<type>().
* fixed unit tests
* general messing around
* general messing around
* Playing with Fluent
* ColorScheme tweaks
* WIP: ColorScheme tweaks
* Playing with Fluent
* Merged from laptop2
* Hacky-ish fixes to:
- #4016
- #4014
* Fixed Region bug preventing menus without borders from working
* Tweaks
* Fixed a bunch of CM issues
* Fixed OoptionSelector
* ip
* FixedCM issues
* Fixed CM issues2
* Revert "FixedCM issues"
This reverts commit dd6c6a70a3.
* Reverted stuff
* Found and fixed bug in AllViews_Center_Properly
* Fixed CM issues2
* removed menuv2 onapplied.
Changed how UICatalog Applys CM
* changed test time out to see if it helkps with ubuntu fails
* reset app on fail?
* back to 1500ms
* Made StatusBar nullable.
* Code Cleanup.
* HexEditor Code Cleanup.
* HexEditor Code Cleanup.
* Back to 3000ms. Sigh.
* Trying different logic
* Trying different logic2
* Fixed potential crash in runlop
* Fixed potential crash in runlop2
* Tweaked Spinner stuff
* Removed TabView from TextEffects scenario. Not needed and possible culprit.
* back to 2000ms
* WIP: Revamping menu scenarios
* Menu Scenario refinements.
Fixed a few bugs.
Code cleanup.
* fixed unit test
* Fixed warnings
* Fixed warnings2
* Fixed File.Exit
* WIP: Dealing with QuitKey struggles
* WIP: Dealing with QuitKey struggles 2
* WIP: Dealing with QuitKey struggles 3
* Fixed ListView collection nav bug
* Fixed a bunch of menu stuff.
Fixed Appv2 stuff.
* Lots of refactoring and fixing
* Lots of unit test issues
* Fixed DebugIDisposable issues
* Fixed release build issue
* Fixed release build issue 2
* DebugIDisposable -> EnableDebugIDisposableAsserts and more
* DebugIDisposable -> EnableDebugIDisposableAsserts and more 2
* Fixed Menus scenario - context menu
* Added @bdisp suggested assert. Commented it out as it breaks tests.
* Code cleanup
* Fixed disposed but
* Fixed UICatalog exit
* Fixed Unit test I broke.
Added 'Minimal' Theme that turns off all borders etc...
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
#nullable enable
|
||||
using System.Collections.Concurrent;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
|
||||
namespace UnitTests.ConsoleDrivers.V2;
|
||||
public class ApplicationV2Tests
|
||||
{
|
||||
|
||||
|
||||
private ApplicationV2 NewApplicationV2 ()
|
||||
{
|
||||
var netInput = new Mock<INetInput> ();
|
||||
@@ -15,20 +16,20 @@ public class ApplicationV2Tests
|
||||
SetupRunInputMockMethodToBlock (winInput);
|
||||
|
||||
return new (
|
||||
()=>netInput.Object,
|
||||
() => netInput.Object,
|
||||
Mock.Of<IConsoleOutput>,
|
||||
() => winInput.Object,
|
||||
Mock.Of<IConsoleOutput>);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestInit_CreatesKeybindings ()
|
||||
public void Init_CreatesKeybindings ()
|
||||
{
|
||||
var v2 = NewApplicationV2();
|
||||
var v2 = NewApplicationV2 ();
|
||||
|
||||
Application.KeyBindings.Clear();
|
||||
Application.KeyBindings.Clear ();
|
||||
|
||||
Assert.Empty(Application.KeyBindings.GetBindings ());
|
||||
Assert.Empty (Application.KeyBindings.GetBindings ());
|
||||
|
||||
v2.Init ();
|
||||
|
||||
@@ -38,16 +39,16 @@ public class ApplicationV2Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestInit_DriverIsFacade ()
|
||||
public void Init_DriverIsFacade ()
|
||||
{
|
||||
var v2 = NewApplicationV2();
|
||||
var v2 = NewApplicationV2 ();
|
||||
|
||||
Assert.Null (Application.Driver);
|
||||
v2.Init ();
|
||||
Assert.NotNull (Application.Driver);
|
||||
|
||||
var type = Application.Driver.GetType ();
|
||||
Assert.True(type.IsGenericType);
|
||||
Assert.True (type.IsGenericType);
|
||||
Assert.True (type.GetGenericTypeDefinition () == typeof (ConsoleDriverFacade<>));
|
||||
v2.Shutdown ();
|
||||
|
||||
@@ -55,29 +56,30 @@ public class ApplicationV2Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestInit_ExplicitlyRequestWin ()
|
||||
public void Init_ExplicitlyRequestWin ()
|
||||
{
|
||||
Assert.Null (Application.Driver);
|
||||
var netInput = new Mock<INetInput> (MockBehavior.Strict);
|
||||
var netOutput = new Mock<IConsoleOutput> (MockBehavior.Strict);
|
||||
var winInput = new Mock<IWindowsInput> (MockBehavior.Strict);
|
||||
var winOutput = new Mock<IConsoleOutput> (MockBehavior.Strict);
|
||||
|
||||
winInput.Setup (i => i.Initialize (It.IsAny<ConcurrentQueue<WindowsConsole.InputRecord>> ()))
|
||||
.Verifiable(Times.Once);
|
||||
.Verifiable (Times.Once);
|
||||
SetupRunInputMockMethodToBlock (winInput);
|
||||
winInput.Setup (i=>i.Dispose ())
|
||||
.Verifiable(Times.Once);
|
||||
winInput.Setup (i => i.Dispose ())
|
||||
.Verifiable (Times.Once);
|
||||
winOutput.Setup (i => i.Dispose ())
|
||||
.Verifiable (Times.Once);
|
||||
|
||||
var v2 = new ApplicationV2 (
|
||||
()=> netInput.Object,
|
||||
() => netInput.Object,
|
||||
() => netOutput.Object,
|
||||
() => winInput.Object,
|
||||
() => winOutput.Object);
|
||||
|
||||
Assert.Null (Application.Driver);
|
||||
v2.Init (null,"v2win");
|
||||
v2.Init (null, "v2win");
|
||||
Assert.NotNull (Application.Driver);
|
||||
|
||||
var type = Application.Driver.GetType ();
|
||||
@@ -87,11 +89,11 @@ public class ApplicationV2Tests
|
||||
|
||||
Assert.Null (Application.Driver);
|
||||
|
||||
winInput.VerifyAll();
|
||||
winInput.VerifyAll ();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestInit_ExplicitlyRequestNet ()
|
||||
public void Init_ExplicitlyRequestNet ()
|
||||
{
|
||||
var netInput = new Mock<INetInput> (MockBehavior.Strict);
|
||||
var netOutput = new Mock<IConsoleOutput> (MockBehavior.Strict);
|
||||
@@ -155,20 +157,22 @@ public class ApplicationV2Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test_NoInitThrowOnRun ()
|
||||
public void NoInitThrowOnRun ()
|
||||
{
|
||||
var app = NewApplicationV2();
|
||||
Assert.Null (Application.Driver);
|
||||
var app = NewApplicationV2 ();
|
||||
|
||||
var ex = Assert.Throws<NotInitializedException> (() => app.Run (new Window ()));
|
||||
Assert.Equal ("Run cannot be accessed before Initialization", ex.Message);
|
||||
app.Shutdown();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test_InitRunShutdown ()
|
||||
public void InitRunShutdown_Top_Set_To_Null_After_Shutdown ()
|
||||
{
|
||||
var orig = ApplicationImpl.Instance;
|
||||
|
||||
var v2 = NewApplicationV2();
|
||||
var v2 = NewApplicationV2 ();
|
||||
ApplicationImpl.ChangeInstance (v2);
|
||||
|
||||
v2.Init ();
|
||||
@@ -191,17 +195,173 @@ public class ApplicationV2Tests
|
||||
|
||||
v2.Run (new Window ());
|
||||
|
||||
Assert.True(v2.RemoveTimeout (timeoutToken));
|
||||
Assert.True (v2.RemoveTimeout (timeoutToken));
|
||||
|
||||
Assert.NotNull (Application.Top);
|
||||
Application.Top?.Dispose ();
|
||||
v2.Shutdown ();
|
||||
Assert.Null (Application.Top);
|
||||
|
||||
ApplicationImpl.ChangeInstance (orig);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitRunShutdown_Running_Set_To_False ()
|
||||
{
|
||||
var orig = ApplicationImpl.Instance;
|
||||
|
||||
var v2 = NewApplicationV2 ();
|
||||
ApplicationImpl.ChangeInstance (v2);
|
||||
|
||||
v2.Init ();
|
||||
|
||||
Toplevel top = new Window ()
|
||||
{
|
||||
Title = "InitRunShutdown_Running_Set_To_False"
|
||||
};
|
||||
var timeoutToken = v2.AddTimeout (TimeSpan.FromMilliseconds (150),
|
||||
() =>
|
||||
{
|
||||
Assert.True (top!.Running);
|
||||
if (Application.Top != null)
|
||||
{
|
||||
Application.RequestStop ();
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
Assert.False (top!.Running);
|
||||
|
||||
// Blocks until the timeout call is hit
|
||||
v2.Run (top);
|
||||
|
||||
Assert.True (v2.RemoveTimeout (timeoutToken));
|
||||
|
||||
Assert.False (top!.Running);
|
||||
|
||||
// BUGBUG: Shutdown sets Top to null, not End.
|
||||
//Assert.Null (Application.Top);
|
||||
Application.Top?.Dispose ();
|
||||
v2.Shutdown ();
|
||||
|
||||
ApplicationImpl.ChangeInstance (orig);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitRunShutdown_End_Is_Called ()
|
||||
{
|
||||
var orig = ApplicationImpl.Instance;
|
||||
|
||||
var v2 = NewApplicationV2 ();
|
||||
ApplicationImpl.ChangeInstance (v2);
|
||||
|
||||
Assert.Null (Application.Top);
|
||||
Assert.Null (Application.Driver);
|
||||
|
||||
v2.Init ();
|
||||
|
||||
Toplevel top = new Window ();
|
||||
|
||||
// BUGBUG: Both Closed and Unloaded are called from End; what's the difference?
|
||||
int closedCount = 0;
|
||||
top.Closed
|
||||
+= (_, a) =>
|
||||
{
|
||||
closedCount++;
|
||||
};
|
||||
|
||||
int unloadedCount = 0;
|
||||
top.Unloaded
|
||||
+= (_, a) =>
|
||||
{
|
||||
unloadedCount++;
|
||||
};
|
||||
|
||||
var timeoutToken = v2.AddTimeout (TimeSpan.FromMilliseconds (150),
|
||||
() =>
|
||||
{
|
||||
Assert.True (top!.Running);
|
||||
if (Application.Top != null)
|
||||
{
|
||||
Application.RequestStop ();
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
Assert.Equal (0, closedCount);
|
||||
Assert.Equal (0, unloadedCount);
|
||||
|
||||
// Blocks until the timeout call is hit
|
||||
v2.Run (top);
|
||||
|
||||
Assert.Equal (1, closedCount);
|
||||
Assert.Equal (1, unloadedCount);
|
||||
|
||||
Assert.True (v2.RemoveTimeout (timeoutToken));
|
||||
|
||||
Application.Top?.Dispose ();
|
||||
v2.Shutdown ();
|
||||
Assert.Equal (1, closedCount);
|
||||
Assert.Equal (1, unloadedCount);
|
||||
|
||||
ApplicationImpl.ChangeInstance (orig);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Test_InitRunShutdown_Generic_IdleForExit ()
|
||||
public void InitRunShutdown_QuitKey_Quits ()
|
||||
{
|
||||
var orig = ApplicationImpl.Instance;
|
||||
|
||||
var v2 = NewApplicationV2 ();
|
||||
ApplicationImpl.ChangeInstance (v2);
|
||||
|
||||
v2.Init ();
|
||||
|
||||
Toplevel top = new Window ()
|
||||
{
|
||||
Title = "InitRunShutdown_QuitKey_Quits"
|
||||
};
|
||||
var timeoutToken = v2.AddTimeout (TimeSpan.FromMilliseconds (150),
|
||||
() =>
|
||||
{
|
||||
Assert.True (top!.Running);
|
||||
if (Application.Top != null)
|
||||
{
|
||||
Application.RaiseKeyDownEvent (Application.QuitKey);
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
Assert.False (top!.Running);
|
||||
|
||||
// Blocks until the timeout call is hit
|
||||
v2.Run (top);
|
||||
|
||||
Assert.True (v2.RemoveTimeout (timeoutToken));
|
||||
|
||||
Assert.False (top!.Running);
|
||||
|
||||
Assert.NotNull (Application.Top);
|
||||
top.Dispose ();
|
||||
v2.Shutdown ();
|
||||
Assert.Null (Application.Top);
|
||||
|
||||
ApplicationImpl.ChangeInstance (orig);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void InitRunShutdown_Generic_IdleForExit ()
|
||||
{
|
||||
var orig = ApplicationImpl.Instance;
|
||||
|
||||
@@ -217,14 +377,16 @@ public class ApplicationV2Tests
|
||||
|
||||
v2.Run<Window> ();
|
||||
|
||||
Assert.Null (Application.Top);
|
||||
Assert.NotNull (Application.Top);
|
||||
Application.Top?.Dispose ();
|
||||
v2.Shutdown ();
|
||||
Assert.Null (Application.Top);
|
||||
|
||||
ApplicationImpl.ChangeInstance (orig);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test_V2_ClosingRaised ()
|
||||
public void Shutdown_Closing_Closed_Raised ()
|
||||
{
|
||||
var orig = ApplicationImpl.Instance;
|
||||
|
||||
@@ -233,19 +395,19 @@ public class ApplicationV2Tests
|
||||
|
||||
v2.Init ();
|
||||
|
||||
int closing=0;
|
||||
int closing = 0;
|
||||
int closed = 0;
|
||||
var t=new Toplevel ();
|
||||
var t = new Toplevel ();
|
||||
t.Closing
|
||||
+= (_, a) =>
|
||||
{
|
||||
// Cancel the first time
|
||||
if (closing==0)
|
||||
if (closing == 0)
|
||||
{
|
||||
a.Cancel = true;
|
||||
}
|
||||
closing++;
|
||||
Assert.Same(t,a.RequestingTop);
|
||||
Assert.Same (t, a.RequestingTop);
|
||||
};
|
||||
|
||||
t.Closed
|
||||
@@ -261,14 +423,15 @@ public class ApplicationV2Tests
|
||||
|
||||
v2.Run (t);
|
||||
|
||||
Assert.Null (Application.Top);
|
||||
Application.Top?.Dispose ();
|
||||
v2.Shutdown ();
|
||||
|
||||
ApplicationImpl.ChangeInstance (orig);
|
||||
|
||||
Assert.Equal (2,closing);
|
||||
Assert.Equal (2, closing);
|
||||
Assert.Equal (1, closed);
|
||||
}
|
||||
|
||||
private bool IdleExit ()
|
||||
{
|
||||
if (Application.Top != null)
|
||||
@@ -281,28 +444,28 @@ public class ApplicationV2Tests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestRepeatedShutdownCalls_DoNotDuplicateDisposeOutput ()
|
||||
public void Shutdown_Called_Repeatedly_DoNotDuplicateDisposeOutput ()
|
||||
{
|
||||
var netInput = new Mock<INetInput> ();
|
||||
SetupRunInputMockMethodToBlock (netInput);
|
||||
Mock<IConsoleOutput>? outputMock = null;
|
||||
|
||||
|
||||
var v2 = new ApplicationV2(
|
||||
var v2 = new ApplicationV2 (
|
||||
() => netInput.Object,
|
||||
()=> (outputMock = new Mock<IConsoleOutput>()).Object,
|
||||
() => (outputMock = new Mock<IConsoleOutput> ()).Object,
|
||||
Mock.Of<IWindowsInput>,
|
||||
Mock.Of<IConsoleOutput>);
|
||||
|
||||
v2.Init (null,"v2net");
|
||||
v2.Init (null, "v2net");
|
||||
|
||||
|
||||
v2.Shutdown ();
|
||||
v2.Shutdown ();
|
||||
outputMock!.Verify(o=>o.Dispose (),Times.Once);
|
||||
outputMock!.Verify (o => o.Dispose (), Times.Once);
|
||||
}
|
||||
[Fact]
|
||||
public void TestRepeatedInitCalls_WarnsAndIgnores ()
|
||||
public void Init_Called_Repeatedly_WarnsAndIgnores ()
|
||||
{
|
||||
var v2 = NewApplicationV2 ();
|
||||
|
||||
@@ -318,13 +481,13 @@ public class ApplicationV2Tests
|
||||
v2.Init ();
|
||||
v2.Init ();
|
||||
|
||||
mockLogger.Verify(
|
||||
l=>l.Log (LogLevel.Error,
|
||||
mockLogger.Verify (
|
||||
l => l.Log (LogLevel.Error,
|
||||
It.IsAny<EventId> (),
|
||||
It.Is<It.IsAnyType> ((v, t) => v.ToString () == "Init called multiple times without shutdown, ignoring."),
|
||||
It.IsAny<Exception> (),
|
||||
It.IsAny<Func<It.IsAnyType, Exception, string>> ()!)
|
||||
,Times.Exactly (2));
|
||||
, Times.Exactly (2));
|
||||
|
||||
v2.Shutdown ();
|
||||
|
||||
@@ -332,8 +495,10 @@ public class ApplicationV2Tests
|
||||
Logging.Logger = beforeLogger;
|
||||
}
|
||||
|
||||
|
||||
// QUESTION: What does this test really test? It's poorly named.
|
||||
[Fact]
|
||||
public void Test_Open_CallsContinueWithOnUIThread ()
|
||||
public void Open_CallsContinueWithOnUIThread ()
|
||||
{
|
||||
var orig = ApplicationImpl.Instance;
|
||||
|
||||
@@ -346,7 +511,7 @@ public class ApplicationV2Tests
|
||||
bool result = false;
|
||||
|
||||
b.Accepting +=
|
||||
(_,_) =>
|
||||
(_, _) =>
|
||||
{
|
||||
|
||||
Task.Run (() =>
|
||||
@@ -366,7 +531,7 @@ public class ApplicationV2Tests
|
||||
};
|
||||
|
||||
v2.AddTimeout (TimeSpan.FromMilliseconds (150),
|
||||
()=>
|
||||
() =>
|
||||
{
|
||||
// Run asynchronous logic inside Task.Run
|
||||
if (Application.Top != null)
|
||||
@@ -382,14 +547,19 @@ public class ApplicationV2Tests
|
||||
|
||||
Assert.Null (Application.Top);
|
||||
|
||||
var w = new Window ();
|
||||
var w = new Window ()
|
||||
{
|
||||
Title = "Open_CallsContinueWithOnUIThread"
|
||||
};
|
||||
w.Add (b);
|
||||
|
||||
// Blocks until the timeout call is hit
|
||||
v2.Run (w);
|
||||
|
||||
Assert.Null (Application.Top);
|
||||
Assert.NotNull (Application.Top);
|
||||
Application.Top?.Dispose ();
|
||||
v2.Shutdown ();
|
||||
Assert.Null (Application.Top);
|
||||
|
||||
ApplicationImpl.ChangeInstance (orig);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user