Fixes #4374 - Nukes all (?) legacy Driver and Application stuff; revamps tests (#4376)

This commit is contained in:
Tig
2025-11-11 16:29:33 -07:00
committed by GitHub
parent 559dea9239
commit d53fcd7485
310 changed files with 14827 additions and 16911 deletions

View File

@@ -0,0 +1,57 @@
#nullable enable
using UnitTests;
using Xunit.Abstractions;
namespace UnitTests_Parallelizable.ViewsTests;
public class AllViewsDrawTests (ITestOutputHelper output) : TestsAllViews
{
[Theory]
[MemberData (nameof (AllViewTypes))]
public void AllViews_Draw_Does_Not_Layout (Type viewType)
{
IDriver driver = CreateFakeDriver ();
View? view = CreateInstanceIfNotGeneric (viewType);
if (view is null)
{
output.WriteLine ($"Ignoring {viewType} - It's a Generic");
return;
}
output.WriteLine ($"Testing {viewType}");
if (view is IDesignable designable)
{
designable.EnableForDesign ();
}
var drawCompleteCount = 0;
view.DrawComplete += (s, e) => drawCompleteCount++;
var layoutStartedCount = 0;
view.SubViewLayout += (s, e) => layoutStartedCount++;
var layoutCompleteCount = 0;
view.SubViewsLaidOut += (s, e) => layoutCompleteCount++;
view.SetNeedsLayout ();
view.Layout ();
Assert.Equal (0, drawCompleteCount);
Assert.Equal (1, layoutStartedCount);
Assert.Equal (1, layoutCompleteCount);
if (view.Visible)
{
view.SetNeedsDraw ();
view.Draw ();
Assert.Equal (1, drawCompleteCount);
Assert.Equal (1, layoutStartedCount);
Assert.Equal (1, layoutCompleteCount);
}
}
}

View File

@@ -1,26 +1,108 @@
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.Utilities;
#nullable enable
using System.Reflection;
using UnitTests;
using Xunit.Abstractions;
namespace UnitTests_Parallelizable.ViewsTests;
[Collection ("Global Test Setup")]
public class AllViewsTests (ITestOutputHelper output) : TestsAllViews
{
[Theory]
[MemberData (nameof (AllViewTypes))]
public void AllViews_Layout_Does_Not_Draw (Type viewType)
{
IDriver driver = CreateFakeDriver ();
View? view = CreateInstanceIfNotGeneric (viewType);
if (view is null)
{
output.WriteLine ($"Ignoring {viewType} - It's a Generic");
return;
}
if (view is IDesignable designable)
{
designable.EnableForDesign ();
}
var drawContentCount = 0;
view.DrawingContent += (s, e) => drawContentCount++;
var layoutStartedCount = 0;
view.SubViewLayout += (s, e) => layoutStartedCount++;
var layoutCompleteCount = 0;
view.SubViewsLaidOut += (s, e) => layoutCompleteCount++;
view.SetNeedsLayout ();
view.SetNeedsDraw ();
view.Layout ();
Assert.Equal (0, drawContentCount);
Assert.Equal (1, layoutStartedCount);
Assert.Equal (1, layoutCompleteCount);
}
[Theory]
[MemberData (nameof (AllViewTypes))]
public void AllViews_Center_Properly (Type viewType)
{
IDriver driver = CreateFakeDriver ();
View? view = CreateInstanceIfNotGeneric (viewType);
if (view is null)
{
output.WriteLine ($"Ignoring {viewType} - It's a Generic");
return;
}
if (view is IDesignable designable)
{
designable.EnableForDesign ();
}
view.X = Pos.Center ();
view.Y = Pos.Center ();
// Ensure the view has positive dimensions
view.Width = 10;
view.Height = 10;
var frame = new View { X = 0, Y = 0, Width = 50, Height = 50 };
frame.Add (view);
frame.LayoutSubViews ();
frame.Dispose ();
// What's the natural width/height?
int expectedX = (frame.Frame.Width - view.Frame.Width) / 2;
int expectedY = (frame.Frame.Height - view.Frame.Height) / 2;
Assert.True (
view.Frame.Left == expectedX,
$"{view} did not center horizontally. Expected: {expectedX}. Actual: {view.Frame.Left}"
);
Assert.True (
view.Frame.Top == expectedY,
$"{view} did not center vertically. Expected: {expectedY}. Actual: {view.Frame.Top}"
);
}
[Theory]
[MemberData (nameof (AllViewTypes))]
public void AllViews_Tests_All_Constructors (Type viewType)
{
Assert.True (TestAllConstructorsOfType (viewType));
return;
bool TestAllConstructorsOfType (Type type)
{
foreach (ConstructorInfo ctor in type.GetConstructors ())
{
View view = CreateViewFromType (type, ctor);
View? view = CreateViewFromType (type, ctor);
if (view != null)
{

View File

@@ -1,10 +1,12 @@
using UnitTests;
namespace UnitTests_Parallelizable.ViewsTests;
/// <summary>
/// Pure unit tests for <see cref="Button"/> that don't require Application static dependencies.
/// These tests can run in parallel without interference.
/// </summary>
public class ButtonTests : UnitTests.Parallelizable.ParallelizableBase
public class ButtonTests : FakeDriverBase
{
[Fact]
public void Text_Mirrors_Title ()

View File

@@ -1,10 +1,12 @@
using UnitTests;
namespace UnitTests_Parallelizable.ViewsTests;
/// <summary>
/// Pure unit tests for <see cref="ColorPicker"/> that don't require Application.Driver or View context.
/// These tests can run in parallel without interference.
/// </summary>
public class ColorPickerTests : UnitTests.Parallelizable.ParallelizableBase
public class ColorPickerTests : FakeDriverBase
{
[Fact]
public void ColorPicker_ChangedEvent_Fires ()

View File

@@ -1,4 +1,5 @@
using System.Globalization;
using UnitTests;
namespace UnitTests_Parallelizable.ViewsTests;
@@ -6,7 +7,7 @@ namespace UnitTests_Parallelizable.ViewsTests;
/// Pure unit tests for <see cref="DatePicker"/> that don't require Application.Driver or View context.
/// These tests can run in parallel without interference.
/// </summary>
public class DatePickerTests : UnitTests.Parallelizable.ParallelizableBase
public class DatePickerTests : FakeDriverBase
{
[Fact]
public void DatePicker_ChangingCultureChangesFormat ()

View File

@@ -1,10 +1,12 @@
using UnitTests;
namespace UnitTests_Parallelizable.ViewsTests;
/// <summary>
/// Pure unit tests for <see cref="Label"/> that don't require Application.Driver or Application context.
/// These tests can run in parallel without interference.
/// </summary>
public class LabelTests : UnitTests.Parallelizable.ParallelizableBase
public class LabelTests : FakeDriverBase
{
[Fact]
public void Text_Mirrors_Title ()

View File

@@ -1,8 +1,9 @@
using System.Text;
using UnitTests;
namespace UnitTests_Parallelizable.ViewsTests;
public class SliderOptionTests : UnitTests.Parallelizable.ParallelizableBase
public class SliderOptionTests : FakeDriverBase
{
[Fact]
public void OnChanged_Should_Raise_ChangedEvent ()
@@ -94,7 +95,7 @@ public class SliderOptionTests : UnitTests.Parallelizable.ParallelizableBase
}
}
public class SliderEventArgsTests : UnitTests.Parallelizable.ParallelizableBase
public class SliderEventArgsTests : FakeDriverBase
{
[Fact]
public void Constructor_Sets_Cancel_Default_To_False ()
@@ -138,7 +139,7 @@ public class SliderEventArgsTests : UnitTests.Parallelizable.ParallelizableBase
}
}
public class SliderTests : UnitTests.Parallelizable.ParallelizableBase
public class SliderTests : FakeDriverBase
{
[Fact]
public void Constructor_Default ()

View File

@@ -1,11 +1,10 @@
using System.Text;
using UnitTests;
using UnitTests.Parallelizable;
using Xunit.Abstractions;
namespace UnitTests_Parallelizable.ViewsTests;
public class TextFieldTests (ITestOutputHelper output) : ParallelizableBase
public class TextFieldTests (ITestOutputHelper output) : FakeDriverBase
{
[Fact]
public void Cancel_TextChanging_ThenBackspace ()
@@ -561,7 +560,7 @@ public class TextFieldTests (ITestOutputHelper output) : ParallelizableBase
[Fact]
public void Accented_Letter_With_Three_Combining_Unicode_Chars ()
{
IConsoleDriver driver = CreateFakeDriver ();
IDriver driver = CreateFakeDriver ();
var tf = new TextField { Width = 3, Text = "ắ" };
tf.Driver = driver;
@@ -612,7 +611,7 @@ public class TextFieldTests (ITestOutputHelper output) : ParallelizableBase
[Fact]
public void Adjust_First ()
{
IConsoleDriver driver = CreateFakeDriver ();
IDriver driver = CreateFakeDriver ();
var tf = new TextField { Width = Dim.Fill (), Text = "This is a test." };
tf.Driver = driver;

View File

@@ -1,8 +1,9 @@
using System.Text.RegularExpressions;
using UnitTests;
namespace UnitTests_Parallelizable.ViewsTests;
public class TextValidateField_NET_Provider_Tests : UnitTests.Parallelizable.ParallelizableBase
public class TextValidateField_NET_Provider_Tests : FakeDriverBase
{
[Fact]
public void Backspace_Key_Deletes_Previous_Character ()
@@ -425,7 +426,7 @@ public class TextValidateField_NET_Provider_Tests : UnitTests.Parallelizable.Par
}
}
public class TextValidateField_Regex_Provider_Tests : UnitTests.Parallelizable.ParallelizableBase
public class TextValidateField_Regex_Provider_Tests : FakeDriverBase
{
[Fact]
public void End_Key_End_Of_Input ()