From 1be3851154aec9e73dfc099a62e51ac7754d3906 Mon Sep 17 00:00:00 2001 From: Tig Date: Thu, 7 Mar 2024 09:04:24 -0700 Subject: [PATCH] Started on unit test --- UnitTests/TestHelpers.cs | 7 +++++++ UnitTests/View/DiagnosticsTests.cs | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 UnitTests/View/DiagnosticsTests.cs diff --git a/UnitTests/TestHelpers.cs b/UnitTests/TestHelpers.cs index 8de81cb35..273bc9807 100644 --- a/UnitTests/TestHelpers.cs +++ b/UnitTests/TestHelpers.cs @@ -69,6 +69,9 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute { Debug.WriteLine ($"After: {methodUnderTest.Name}"); + // Turn off diagnostic flags in case some test left them on + View.Diagnostics = ViewDiagnosticFlags.Off; + if (AutoInit) { Application.Shutdown (); @@ -145,6 +148,10 @@ public class SetupFakeDriverAttribute : BeforeAfterTestAttribute public override void After (MethodInfo methodUnderTest) { Debug.WriteLine ($"After: {methodUnderTest.Name}"); + + // Turn off diagnostic flags in case some test left them on + View.Diagnostics = ViewDiagnosticFlags.Off; + Application.Driver = null; } diff --git a/UnitTests/View/DiagnosticsTests.cs b/UnitTests/View/DiagnosticsTests.cs new file mode 100644 index 000000000..87eaaf0ad --- /dev/null +++ b/UnitTests/View/DiagnosticsTests.cs @@ -0,0 +1,29 @@ +#nullable enable +using Xunit.Abstractions; + +namespace Terminal.Gui.ViewTests; + +/// +/// Tests static property and enum. +/// +/// +[Trait("Category","Output")] +public class DiagnosticTests (ITestOutputHelper output) +{ + /// + /// /// Tests static property and enum. + /// /// + [Fact] + public void Diagnostics_Sets () + { + // View.Diagnostics is a static property that returns the current diagnostic flags. + Assert.Equal (ViewDiagnosticFlags.Off, View.Diagnostics); + + // View.Diagnostics can be set to a new value. + View.Diagnostics = ViewDiagnosticFlags.Padding; + Assert.Equal (ViewDiagnosticFlags.Padding, View.Diagnostics); + + // Ensure we turn off at the end of the test + View.Diagnostics = ViewDiagnosticFlags.Off; + } +}