From 23f7c8faf25880ff4ba87ae79b96bdc7b82a7c50 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Sep 2024 14:20:16 +0000 Subject: [PATCH 1/5] build(deps): bump MSTest from 3.5.2 to 3.6.0 Bumps [MSTest](https://github.com/microsoft/testfx) from 3.5.2 to 3.6.0. - [Release notes](https://github.com/microsoft/testfx/releases) - [Changelog](https://github.com/microsoft/testfx/blob/main/docs/Changelog.md) - [Commits](https://github.com/microsoft/testfx/compare/v3.5.2...v3.6.0) --- updated-dependencies: - dependency-name: MSTest dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../ThScoreFileConverter.Core.Tests.csproj | 2 +- ThScoreFileConverter.Tests/ThScoreFileConverter.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ThScoreFileConverter.Core.Tests/ThScoreFileConverter.Core.Tests.csproj b/ThScoreFileConverter.Core.Tests/ThScoreFileConverter.Core.Tests.csproj index 94da4fcc..0f40e747 100644 --- a/ThScoreFileConverter.Core.Tests/ThScoreFileConverter.Core.Tests.csproj +++ b/ThScoreFileConverter.Core.Tests/ThScoreFileConverter.Core.Tests.csproj @@ -15,7 +15,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all diff --git a/ThScoreFileConverter.Tests/ThScoreFileConverter.Tests.csproj b/ThScoreFileConverter.Tests/ThScoreFileConverter.Tests.csproj index 0c6a4098..5ffef86f 100644 --- a/ThScoreFileConverter.Tests/ThScoreFileConverter.Tests.csproj +++ b/ThScoreFileConverter.Tests/ThScoreFileConverter.Tests.csproj @@ -19,7 +19,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all From eff6187aa55c9ae9c6c0db24447b1439d1fd76d0 Mon Sep 17 00:00:00 2001 From: IIHOSHI Yoshinori Date: Sat, 14 Sep 2024 00:33:42 +0900 Subject: [PATCH 2/5] Replace STATestMethodAttribute with the one of MSTest --- .../Interactivity/CommonDialogActionTests.cs | 1 - .../Interactivity/Win32WindowTests.cs | 1 - .../UnitTesting/STATestMethodAttribute.cs | 32 ------------------- 3 files changed, 34 deletions(-) delete mode 100644 ThScoreFileConverter.Tests/UnitTesting/STATestMethodAttribute.cs diff --git a/ThScoreFileConverter.Tests/Interactivity/CommonDialogActionTests.cs b/ThScoreFileConverter.Tests/Interactivity/CommonDialogActionTests.cs index 1e89508f..59f08ea2 100644 --- a/ThScoreFileConverter.Tests/Interactivity/CommonDialogActionTests.cs +++ b/ThScoreFileConverter.Tests/Interactivity/CommonDialogActionTests.cs @@ -3,7 +3,6 @@ using System.Windows; using System.Windows.Input; using ThScoreFileConverter.Interactivity; -using ThScoreFileConverter.Tests.UnitTesting; namespace ThScoreFileConverter.Tests.Interactivity; diff --git a/ThScoreFileConverter.Tests/Interactivity/Win32WindowTests.cs b/ThScoreFileConverter.Tests/Interactivity/Win32WindowTests.cs index a969830f..b5f95bc7 100644 --- a/ThScoreFileConverter.Tests/Interactivity/Win32WindowTests.cs +++ b/ThScoreFileConverter.Tests/Interactivity/Win32WindowTests.cs @@ -2,7 +2,6 @@ using System.Windows; using System.Windows.Interop; using ThScoreFileConverter.Interactivity; -using ThScoreFileConverter.Tests.UnitTesting; namespace ThScoreFileConverter.Tests.Interactivity; diff --git a/ThScoreFileConverter.Tests/UnitTesting/STATestMethodAttribute.cs b/ThScoreFileConverter.Tests/UnitTesting/STATestMethodAttribute.cs deleted file mode 100644 index c6169fd9..00000000 --- a/ThScoreFileConverter.Tests/UnitTesting/STATestMethodAttribute.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Threading; - -namespace ThScoreFileConverter.Tests.UnitTesting; - -public sealed class STATestMethodAttribute : TestMethodAttribute -{ - public override TestResult[] Execute(ITestMethod testMethod) - { - // HACK: avoid null dereferences in net8.0 tests - // - // Although the root cause is unknown, accessing Thread.CurrentThread - // during testing can cause a NullReferenceException on net8.0. - // This behavior has only been observed on the GitHub-hosted runners - // (at least windows-2022 20231205.1.0 and 20231211.1.0). - -#if NET8_0_OR_GREATER - return [ - new TestResult { Outcome = UnitTestOutcome.Inconclusive } - ]; -#else - if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) - return base.Execute(testMethod); - - TestResult[]? result = null; - var thread = new Thread(() => result = base.Execute(testMethod)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - thread.Join(); - return result!; -#endif - } -} From 5af06b91a2d191af06c8e1353025a90b4609d852 Mon Sep 17 00:00:00 2001 From: IIHOSHI Yoshinori Date: Sat, 14 Sep 2024 23:29:12 +0900 Subject: [PATCH 3/5] Revert "Replace STATestMethodAttribute with the one of MSTest" This reverts commit eff6187aa55c9ae9c6c0db24447b1439d1fd76d0. --- .../Interactivity/CommonDialogActionTests.cs | 1 + .../Interactivity/Win32WindowTests.cs | 1 + .../UnitTesting/STATestMethodAttribute.cs | 32 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 ThScoreFileConverter.Tests/UnitTesting/STATestMethodAttribute.cs diff --git a/ThScoreFileConverter.Tests/Interactivity/CommonDialogActionTests.cs b/ThScoreFileConverter.Tests/Interactivity/CommonDialogActionTests.cs index 59f08ea2..1e89508f 100644 --- a/ThScoreFileConverter.Tests/Interactivity/CommonDialogActionTests.cs +++ b/ThScoreFileConverter.Tests/Interactivity/CommonDialogActionTests.cs @@ -3,6 +3,7 @@ using System.Windows; using System.Windows.Input; using ThScoreFileConverter.Interactivity; +using ThScoreFileConverter.Tests.UnitTesting; namespace ThScoreFileConverter.Tests.Interactivity; diff --git a/ThScoreFileConverter.Tests/Interactivity/Win32WindowTests.cs b/ThScoreFileConverter.Tests/Interactivity/Win32WindowTests.cs index b5f95bc7..a969830f 100644 --- a/ThScoreFileConverter.Tests/Interactivity/Win32WindowTests.cs +++ b/ThScoreFileConverter.Tests/Interactivity/Win32WindowTests.cs @@ -2,6 +2,7 @@ using System.Windows; using System.Windows.Interop; using ThScoreFileConverter.Interactivity; +using ThScoreFileConverter.Tests.UnitTesting; namespace ThScoreFileConverter.Tests.Interactivity; diff --git a/ThScoreFileConverter.Tests/UnitTesting/STATestMethodAttribute.cs b/ThScoreFileConverter.Tests/UnitTesting/STATestMethodAttribute.cs new file mode 100644 index 00000000..c6169fd9 --- /dev/null +++ b/ThScoreFileConverter.Tests/UnitTesting/STATestMethodAttribute.cs @@ -0,0 +1,32 @@ +using System.Threading; + +namespace ThScoreFileConverter.Tests.UnitTesting; + +public sealed class STATestMethodAttribute : TestMethodAttribute +{ + public override TestResult[] Execute(ITestMethod testMethod) + { + // HACK: avoid null dereferences in net8.0 tests + // + // Although the root cause is unknown, accessing Thread.CurrentThread + // during testing can cause a NullReferenceException on net8.0. + // This behavior has only been observed on the GitHub-hosted runners + // (at least windows-2022 20231205.1.0 and 20231211.1.0). + +#if NET8_0_OR_GREATER + return [ + new TestResult { Outcome = UnitTestOutcome.Inconclusive } + ]; +#else + if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) + return base.Execute(testMethod); + + TestResult[]? result = null; + var thread = new Thread(() => result = base.Execute(testMethod)); + thread.SetApartmentState(ApartmentState.STA); + thread.Start(); + thread.Join(); + return result!; +#endif + } +} From 62aa618f5cb516591dc8a5460d7c216be4cad99f Mon Sep 17 00:00:00 2001 From: IIHOSHI Yoshinori Date: Sat, 14 Sep 2024 23:57:47 +0900 Subject: [PATCH 4/5] Fix to avoid name conflicts of STATestMethodAttribute --- .../Commands/CloseWindowCommandTests.cs | 6 +++--- .../Interactivity/CommonDialogActionTests.cs | 2 +- .../Interactivity/TextBoxBaseScrollBehaviorTests.cs | 4 ++-- .../Interactivity/Win32WindowTests.cs | 4 ++-- ...stMethodAttribute.cs => SkipOrSTATestMethodAttribute.cs} | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) rename ThScoreFileConverter.Tests/UnitTesting/{STATestMethodAttribute.cs => SkipOrSTATestMethodAttribute.cs} (93%) diff --git a/ThScoreFileConverter.Tests/Commands/CloseWindowCommandTests.cs b/ThScoreFileConverter.Tests/Commands/CloseWindowCommandTests.cs index ad15c25f..4988d26c 100644 --- a/ThScoreFileConverter.Tests/Commands/CloseWindowCommandTests.cs +++ b/ThScoreFileConverter.Tests/Commands/CloseWindowCommandTests.cs @@ -15,7 +15,7 @@ public void InstanceTest() Assert.IsNotNull(instance); } - [STATestMethod] + [SkipOrSTATestMethod] public void CanExecuteTest() { var instance = CloseWindowCommand.Instance; @@ -37,7 +37,7 @@ public void CanExecuteTestInvalid() Assert.IsFalse(instance.CanExecute(5)); } - [STATestMethod] + [SkipOrSTATestMethod] public void ExecuteTest() { var instance = CloseWindowCommand.Instance; @@ -73,7 +73,7 @@ public void ExecuteTestInvalid() instance.Execute(5); } - [STATestMethod] + [SkipOrSTATestMethod] public void CanExecuteChangedTest() { var instance = CloseWindowCommand.Instance; diff --git a/ThScoreFileConverter.Tests/Interactivity/CommonDialogActionTests.cs b/ThScoreFileConverter.Tests/Interactivity/CommonDialogActionTests.cs index 1e89508f..c363a62d 100644 --- a/ThScoreFileConverter.Tests/Interactivity/CommonDialogActionTests.cs +++ b/ThScoreFileConverter.Tests/Interactivity/CommonDialogActionTests.cs @@ -53,7 +53,7 @@ public void CancelCommandTest() Assert.AreSame(command, action.CancelCommand); } - [STATestMethod] + [SkipOrSTATestMethod] public void OwnerTest() { var action = new DerivedAction(); diff --git a/ThScoreFileConverter.Tests/Interactivity/TextBoxBaseScrollBehaviorTests.cs b/ThScoreFileConverter.Tests/Interactivity/TextBoxBaseScrollBehaviorTests.cs index a6aad9e1..9ebffc19 100644 --- a/ThScoreFileConverter.Tests/Interactivity/TextBoxBaseScrollBehaviorTests.cs +++ b/ThScoreFileConverter.Tests/Interactivity/TextBoxBaseScrollBehaviorTests.cs @@ -36,7 +36,7 @@ private void RaisePropertyChanged([CallerMemberName] string propertyName = "") [TestClass] public class TextBoxBaseScrollBehaviorTests { - [STATestMethod] + [SkipOrSTATestMethod] public void AutoScrollToEndTest() { var logger = new Logger(); @@ -79,7 +79,7 @@ static void onLayoutUpdated(object? sender, EventArgs eventArgs) BindingOperations.ClearBinding(textbox, TextBox.TextProperty); } - [STATestMethod] + [SkipOrSTATestMethod] public void NotAutoScrollToEndTest() { var logger = new Logger(); diff --git a/ThScoreFileConverter.Tests/Interactivity/Win32WindowTests.cs b/ThScoreFileConverter.Tests/Interactivity/Win32WindowTests.cs index a969830f..4ffad320 100644 --- a/ThScoreFileConverter.Tests/Interactivity/Win32WindowTests.cs +++ b/ThScoreFileConverter.Tests/Interactivity/Win32WindowTests.cs @@ -9,7 +9,7 @@ namespace ThScoreFileConverter.Tests.Interactivity; [TestClass] public class Win32WindowTests { - [STATestMethod] + [SkipOrSTATestMethod] public void Win32WindowTest() { var window = new Window(); @@ -21,7 +21,7 @@ public void Win32WindowTest() Assert.AreEqual(handle, win32window.Handle); } - [STATestMethod] + [SkipOrSTATestMethod] public void Win32WindowTestDefault() { var window = new Window(); diff --git a/ThScoreFileConverter.Tests/UnitTesting/STATestMethodAttribute.cs b/ThScoreFileConverter.Tests/UnitTesting/SkipOrSTATestMethodAttribute.cs similarity index 93% rename from ThScoreFileConverter.Tests/UnitTesting/STATestMethodAttribute.cs rename to ThScoreFileConverter.Tests/UnitTesting/SkipOrSTATestMethodAttribute.cs index c6169fd9..aac0ea05 100644 --- a/ThScoreFileConverter.Tests/UnitTesting/STATestMethodAttribute.cs +++ b/ThScoreFileConverter.Tests/UnitTesting/SkipOrSTATestMethodAttribute.cs @@ -2,7 +2,7 @@ namespace ThScoreFileConverter.Tests.UnitTesting; -public sealed class STATestMethodAttribute : TestMethodAttribute +public sealed class SkipOrSTATestMethodAttribute : TestMethodAttribute { public override TestResult[] Execute(ITestMethod testMethod) { From 104f7d19618d5bbce323b87c028eded25b4d12fc Mon Sep 17 00:00:00 2001 From: IIHOSHI Yoshinori Date: Sun, 15 Sep 2024 00:44:47 +0900 Subject: [PATCH 5/5] Fix to use STATestMethodAttribute of MSTest --- .../UnitTesting/SkipOrSTATestMethodAttribute.cs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/ThScoreFileConverter.Tests/UnitTesting/SkipOrSTATestMethodAttribute.cs b/ThScoreFileConverter.Tests/UnitTesting/SkipOrSTATestMethodAttribute.cs index aac0ea05..cbf89077 100644 --- a/ThScoreFileConverter.Tests/UnitTesting/SkipOrSTATestMethodAttribute.cs +++ b/ThScoreFileConverter.Tests/UnitTesting/SkipOrSTATestMethodAttribute.cs @@ -1,8 +1,6 @@ -using System.Threading; +namespace ThScoreFileConverter.Tests.UnitTesting; -namespace ThScoreFileConverter.Tests.UnitTesting; - -public sealed class SkipOrSTATestMethodAttribute : TestMethodAttribute +public sealed class SkipOrSTATestMethodAttribute : STATestMethodAttribute { public override TestResult[] Execute(ITestMethod testMethod) { @@ -18,15 +16,7 @@ public override TestResult[] Execute(ITestMethod testMethod) new TestResult { Outcome = UnitTestOutcome.Inconclusive } ]; #else - if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) - return base.Execute(testMethod); - - TestResult[]? result = null; - var thread = new Thread(() => result = base.Execute(testMethod)); - thread.SetApartmentState(ApartmentState.STA); - thread.Start(); - thread.Join(); - return result!; + return base.Execute(testMethod); #endif } }