From e0953cc5599781e4b141a944c5cc4d18527d2541 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 13 Mar 2025 20:50:33 +1100 Subject: [PATCH 1/2] use module init instead of CollectionDefinition --- ...VerifySettingsFixture.cs => ModuleInit.cs} | 15 +++------ .../ValidateCommandTests.cs | 1 - .../VerifyTestCollection.cs | 13 -------- .../BasicTests.cs | 1 - .../End2EndTests.cs | 1 - .../ModuleInit.cs | 23 +++++++++++++ .../ModuleInitializerAttribute.cs | 9 ++++++ .../SnapshotTests.cs | 1 - .../VerifySettingsFixture.cs | 32 ------------------- .../VerifyTestCollection.cs | 13 -------- .../ModuleInit.cs | 23 +++++++++++++ .../ModuleInitializerAttribute.cs | 9 ++++++ .../SnapshotTests.cs | 1 - .../VerifySettingsFixture.cs | 31 ------------------ .../VerifyTestCollection.cs | 13 -------- 15 files changed, 68 insertions(+), 118 deletions(-) rename test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/{VerifySettingsFixture.cs => ModuleInit.cs} (68%) delete mode 100644 test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/VerifyTestCollection.cs create mode 100644 test/Microsoft.TemplateEngine.IDE.IntegrationTests/ModuleInit.cs create mode 100644 test/Microsoft.TemplateEngine.IDE.IntegrationTests/ModuleInitializerAttribute.cs delete mode 100644 test/Microsoft.TemplateEngine.IDE.IntegrationTests/VerifySettingsFixture.cs delete mode 100644 test/Microsoft.TemplateEngine.IDE.IntegrationTests/VerifyTestCollection.cs create mode 100644 test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/ModuleInit.cs create mode 100644 test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/ModuleInitializerAttribute.cs delete mode 100644 test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/VerifySettingsFixture.cs delete mode 100644 test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/VerifyTestCollection.cs diff --git a/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/VerifySettingsFixture.cs b/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/ModuleInit.cs similarity index 68% rename from test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/VerifySettingsFixture.cs rename to test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/ModuleInit.cs index 79757a88da5..6d145cb1e33 100644 --- a/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/VerifySettingsFixture.cs +++ b/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/ModuleInit.cs @@ -1,21 +1,16 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Runtime.CompilerServices; using VerifyTests.DiffPlex; namespace Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests { - public class VerifySettingsFixture : IDisposable + public static class ModuleInit { - private static bool s_called; - - public VerifySettingsFixture() + [ModuleInitializer] + public static void Init() { - if (s_called) - { - return; - } - s_called = true; DerivePathInfo( (_, _, type, method) => new( directory: "Snapshots", @@ -25,7 +20,5 @@ public VerifySettingsFixture() // Customize diff output of verifier VerifyDiffPlex.Initialize(OutputType.Compact); } - - public void Dispose() { } } } diff --git a/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/ValidateCommandTests.cs b/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/ValidateCommandTests.cs index 33309dd6982..ad8b0809569 100644 --- a/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/ValidateCommandTests.cs +++ b/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/ValidateCommandTests.cs @@ -9,7 +9,6 @@ namespace Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests { - [Collection("Verify Tests")] public class ValidateCommandTests : TestBase { private readonly ITestOutputHelper _log; diff --git a/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/VerifyTestCollection.cs b/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/VerifyTestCollection.cs deleted file mode 100644 index fb63227639d..00000000000 --- a/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/VerifyTestCollection.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests -{ - [CollectionDefinition("Verify Tests")] - public class VerifyTestCollection : IClassFixture - { - //intentionally empty - //defines test class collection to share the fixture - //usage [Collection("Verify Tests")] on the test class. - } -} diff --git a/test/Microsoft.TemplateEngine.IDE.IntegrationTests/BasicTests.cs b/test/Microsoft.TemplateEngine.IDE.IntegrationTests/BasicTests.cs index 377d5c86eca..70d5b6c303b 100644 --- a/test/Microsoft.TemplateEngine.IDE.IntegrationTests/BasicTests.cs +++ b/test/Microsoft.TemplateEngine.IDE.IntegrationTests/BasicTests.cs @@ -9,7 +9,6 @@ namespace Microsoft.TemplateEngine.IDE.IntegrationTests { - [Collection("Verify Tests")] public class BasicTests : BootstrapperTestBase, IClassFixture { private readonly PackageManager _packageManager; diff --git a/test/Microsoft.TemplateEngine.IDE.IntegrationTests/End2EndTests.cs b/test/Microsoft.TemplateEngine.IDE.IntegrationTests/End2EndTests.cs index 204228a61a7..d5521d71c2e 100644 --- a/test/Microsoft.TemplateEngine.IDE.IntegrationTests/End2EndTests.cs +++ b/test/Microsoft.TemplateEngine.IDE.IntegrationTests/End2EndTests.cs @@ -10,7 +10,6 @@ namespace Microsoft.TemplateEngine.IDE.IntegrationTests { - [Collection("Verify Tests")] public class End2EndTests : BootstrapperTestBase { [Fact] diff --git a/test/Microsoft.TemplateEngine.IDE.IntegrationTests/ModuleInit.cs b/test/Microsoft.TemplateEngine.IDE.IntegrationTests/ModuleInit.cs new file mode 100644 index 00000000000..12f26c3915d --- /dev/null +++ b/test/Microsoft.TemplateEngine.IDE.IntegrationTests/ModuleInit.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.CompilerServices; +using VerifyTests.DiffPlex; + +namespace Microsoft.TemplateEngine.IDE.IntegrationTests; + +public static class ModuleInit +{ + [ModuleInitializer] + public static void Init() + { + DerivePathInfo( + (_, _, type, method) => new( + directory: "Approvals", + typeName: type.Name, + methodName: method.Name)); + + // Customize diff output of verifier + VerifyDiffPlex.Initialize(OutputType.Compact); + } +} \ No newline at end of file diff --git a/test/Microsoft.TemplateEngine.IDE.IntegrationTests/ModuleInitializerAttribute.cs b/test/Microsoft.TemplateEngine.IDE.IntegrationTests/ModuleInitializerAttribute.cs new file mode 100644 index 00000000000..6d578b97c6d --- /dev/null +++ b/test/Microsoft.TemplateEngine.IDE.IntegrationTests/ModuleInitializerAttribute.cs @@ -0,0 +1,9 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#if !NET5_0_OR_GREATER +namespace System.Runtime.CompilerServices; + +[AttributeUsage(AttributeTargets.Method, Inherited = false)] +public sealed class ModuleInitializerAttribute : Attribute; +#endif \ No newline at end of file diff --git a/test/Microsoft.TemplateEngine.IDE.IntegrationTests/SnapshotTests.cs b/test/Microsoft.TemplateEngine.IDE.IntegrationTests/SnapshotTests.cs index f6fcb86504f..432801a353e 100644 --- a/test/Microsoft.TemplateEngine.IDE.IntegrationTests/SnapshotTests.cs +++ b/test/Microsoft.TemplateEngine.IDE.IntegrationTests/SnapshotTests.cs @@ -11,7 +11,6 @@ namespace Microsoft.TemplateEngine.IDE.IntegrationTests { - [Collection("Verify Tests")] public class SnapshotTests : TestBase { private readonly ILogger _log; diff --git a/test/Microsoft.TemplateEngine.IDE.IntegrationTests/VerifySettingsFixture.cs b/test/Microsoft.TemplateEngine.IDE.IntegrationTests/VerifySettingsFixture.cs deleted file mode 100644 index f44508b1159..00000000000 --- a/test/Microsoft.TemplateEngine.IDE.IntegrationTests/VerifySettingsFixture.cs +++ /dev/null @@ -1,32 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using VerifyTests.DiffPlex; - -namespace Microsoft.TemplateEngine.IDE.IntegrationTests -{ - public class VerifySettingsFixture : IDisposable - { - private static bool s_called; - - public VerifySettingsFixture() - { - if (s_called) - { - return; - } - s_called = true; - - DerivePathInfo( - (_, _, type, method) => new( - directory: "Approvals", - typeName: type.Name, - methodName: method.Name)); - - // Customize diff output of verifier - VerifyDiffPlex.Initialize(OutputType.Compact); - } - - public void Dispose() { } - } -} diff --git a/test/Microsoft.TemplateEngine.IDE.IntegrationTests/VerifyTestCollection.cs b/test/Microsoft.TemplateEngine.IDE.IntegrationTests/VerifyTestCollection.cs deleted file mode 100644 index 80db2339a2d..00000000000 --- a/test/Microsoft.TemplateEngine.IDE.IntegrationTests/VerifyTestCollection.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.TemplateEngine.IDE.IntegrationTests -{ - [CollectionDefinition("Verify Tests")] - public class VerifyTestCollection : IClassFixture - { - //intentionally empty - //defines test class collection to share the fixture - //usage [Collection("Verify Tests")] on the test class. - } -} diff --git a/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/ModuleInit.cs b/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/ModuleInit.cs new file mode 100644 index 00000000000..d0db771eea3 --- /dev/null +++ b/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/ModuleInit.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.CompilerServices; +using VerifyTests.DiffPlex; + +namespace Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests; + +public static class ModuleInit +{ + [ModuleInitializer] + public static void Init() + { + DerivePathInfo( + (_, _, type, method) => new( + directory: "Approvals", + typeName: type.Name, + methodName: method.Name)); + + // Customize diff output of verifier + VerifyDiffPlex.Initialize(OutputType.Compact); + } +} \ No newline at end of file diff --git a/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/ModuleInitializerAttribute.cs b/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/ModuleInitializerAttribute.cs new file mode 100644 index 00000000000..6d578b97c6d --- /dev/null +++ b/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/ModuleInitializerAttribute.cs @@ -0,0 +1,9 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#if !NET5_0_OR_GREATER +namespace System.Runtime.CompilerServices; + +[AttributeUsage(AttributeTargets.Method, Inherited = false)] +public sealed class ModuleInitializerAttribute : Attribute; +#endif \ No newline at end of file diff --git a/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/SnapshotTests.cs b/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/SnapshotTests.cs index 002150d8ab5..78294e4ebf0 100644 --- a/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/SnapshotTests.cs +++ b/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/SnapshotTests.cs @@ -12,7 +12,6 @@ namespace Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests { - [Collection("Verify Tests")] public class SnapshotTests : TestBase { private readonly ILogger _log; diff --git a/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/VerifySettingsFixture.cs b/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/VerifySettingsFixture.cs deleted file mode 100644 index 9c427764851..00000000000 --- a/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/VerifySettingsFixture.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using VerifyTests.DiffPlex; - -namespace Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests -{ - public class VerifySettingsFixture : IDisposable - { - private static bool s_called; - - public VerifySettingsFixture() - { - if (s_called) - { - return; - } - s_called = true; - DerivePathInfo( - (_, _, type, method) => new( - directory: "Approvals", - typeName: type.Name, - methodName: method.Name)); - - // Customize diff output of verifier - VerifyDiffPlex.Initialize(OutputType.Compact); - } - - public void Dispose() { } - } -} diff --git a/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/VerifyTestCollection.cs b/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/VerifyTestCollection.cs deleted file mode 100644 index d1d7bbea76c..00000000000 --- a/test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/VerifyTestCollection.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests -{ - [CollectionDefinition("Verify Tests")] - public class VerifyTestCollection : IClassFixture - { - //intentionally empty - //defines test class collection to share the fixture - //usage [Collection("Verify Tests")] on the test class. - } -} From bf8620372d851ef6b796425e9414bd7ae3477390 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Thu, 13 Mar 2025 21:09:38 +1100 Subject: [PATCH 2/2] Update ModuleInit.cs --- .../ModuleInit.cs | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/ModuleInit.cs b/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/ModuleInit.cs index 6d145cb1e33..fbb0fb64de5 100644 --- a/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/ModuleInit.cs +++ b/test/Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests/ModuleInit.cs @@ -4,21 +4,20 @@ using System.Runtime.CompilerServices; using VerifyTests.DiffPlex; -namespace Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests +namespace Microsoft.TemplateEngine.Authoring.CLI.IntegrationTests; + +public static class ModuleInit { - public static class ModuleInit + [ModuleInitializer] + public static void Init() { - [ModuleInitializer] - public static void Init() - { - DerivePathInfo( - (_, _, type, method) => new( - directory: "Snapshots", - typeName: type.Name, - methodName: method.Name)); + DerivePathInfo( + (_, _, type, method) => new( + directory: "Snapshots", + typeName: type.Name, + methodName: method.Name)); - // Customize diff output of verifier - VerifyDiffPlex.Initialize(OutputType.Compact); - } + // Customize diff output of verifier + VerifyDiffPlex.Initialize(OutputType.Compact); } }