From 8f8595cc556e7481ba1443f202b0b9d7e01eec40 Mon Sep 17 00:00:00 2001 From: Amaury Leveugle Date: Sat, 13 Jun 2026 17:07:26 +0200 Subject: [PATCH 1/4] Migrate Microsoft.TemplateEngine.Utils.UnitTests to MSTest.Sdk on MTP Switches the project SDK to MSTest.Sdk so it picks up MSTest 4.x + Microsoft.Testing.Platform (MTP) defaults instead of xUnit v3 + VSTest. - csproj: , IsTestProject=true, ImplicitUsings=enable. Drop the explicit xunit.v3.extensibility.core and AwesomeAssertions PackageReferences (the latter is now added by test/Directory.Build.targets for MSTest.Sdk projects). - Convert xUnit attributes/assertions to MSTest equivalents: [Fact]/[Fact(DisplayName=...)] -> [TestMethod] [Theory] [InlineData] -> [TestMethod] [DataRow] [MemberData(nameof(X))] -> [DynamicData(nameof(X))] Assert.True/False -> Assert.IsTrue/IsFalse Assert.Equal/NotEqual -> Assert.AreEqual/AreNotEqual Assert.Null/NotNull -> Assert.IsNull/IsNotNull Assert.Single(coll, pred) -> Assert.AreEqual(1, coll.Count(pred)) TestContext.Current.CancellationToken -> TestContext.CancellationTokenSource.Token DirectedGraphTests keeps its existing FluentAssertions (AwesomeAssertions) usage; the global "using FluentAssertions" is provided by the repo Directory.Build.targets. - IClassFixture replacement: MSTest has no IClassFixture equivalent. DefaultTemplatePackageProviderTests and InstallRequestPathResolutionTests now hold a lazily-initialized static EnvironmentSettingsHelper per class (matching the per-class lifetime xUnit's IClassFixture provided) and dispose it in [ClassCleanup]. Tests still call CreateEnvironment from a [TestInitialize] hook to preserve per-test virtualization. - Add a small NullMessageSink : Xunit.Sdk.IMessageSink so EnvironmentSettingsHelper's constructor (which requires an xUnit IMessageSink) can be satisfied without a running xUnit host. The xUnit types are still reachable transitively through the Microsoft.TemplateEngine.TestHelper project reference, which is consumed by other in-tree xUnit projects and intentionally left untouched as part of this migration. - Add a minimal GlobalUsings.cs that aliases Xunit.Sdk.IMessageSink / IMessageSinkMessage so NullMessageSink compiles without dragging in xUnit's full global using set (which would conflict with MSTest's global Assert). Verification: - build.cmd -projects ...Microsoft.TemplateEngine.Utils.UnitTests.csproj succeeds with 0 warnings / 0 errors on net11.0 and net481. - The produced executable is an MTP host; Microsoft.TemplateEngine.Utils.UnitTests.dll --list-tests discovers all 120 tests (theory rows expanded). --- .../CombinedListTests.cs | 32 ++--- .../DefaultTemplatePackageProviderTests.cs | 43 ++++-- .../DirectedGraphTests.cs | 23 ++-- .../EqualityExtensionsTests.cs | 19 ++- .../GlobTests.cs | 129 +++++++++--------- .../GlobalUsings.cs | 10 ++ .../InMemoryFileSystemTests.cs | 12 +- .../InstallRequestPathResolutionTests.cs | 77 +++++++---- .../ListExtensionsTests.cs | 15 +- ...soft.TemplateEngine.Utils.UnitTests.csproj | 9 +- .../NullMessageSink.cs | 20 +++ .../VersionStringTests.cs | 107 +++++++-------- .../WellKnownSearchFiltersTests.cs | 24 ++-- 13 files changed, 287 insertions(+), 233 deletions(-) create mode 100644 test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/GlobalUsings.cs create mode 100644 test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/NullMessageSink.cs diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/CombinedListTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/CombinedListTests.cs index 4897b5af2f8a..904ddb9ba705 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/CombinedListTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/CombinedListTests.cs @@ -1,24 +1,22 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Xunit; - namespace Microsoft.TemplateEngine.Utils.UnitTests { + [TestClass] public class CombinedListTests { - [Theory(DisplayName = nameof(VerifyCombinedListCombinesCorrectly))] - [InlineData(new int[] { }, new int[] { })] - [InlineData(new int[] { 5 }, new int[] { })] - [InlineData(new int[] { }, new int[] { 3 })] - [InlineData(new int[] { 1, 2 }, new int[] { })] - [InlineData(new int[] { }, new int[] { 1, 2 })] - [InlineData(new int[] { 1 }, new int[] { 1 })] - [InlineData(new int[] { 1 }, new int[] { 1, 2, 3 })] - [InlineData(new int[] { 1, 2, 3 }, new int[] { 1 })] - [InlineData(new int[] { 1, 2 }, new int[] { 1, 2, 3 })] - [InlineData(new int[] { 1, 2, 3, 4, 5 }, new int[] { 1, 2, 3 })] - + [TestMethod] + [DataRow(new int[] { }, new int[] { })] + [DataRow(new int[] { 5 }, new int[] { })] + [DataRow(new int[] { }, new int[] { 3 })] + [DataRow(new int[] { 1, 2 }, new int[] { })] + [DataRow(new int[] { }, new int[] { 1, 2 })] + [DataRow(new int[] { 1 }, new int[] { 1 })] + [DataRow(new int[] { 1 }, new int[] { 1, 2, 3 })] + [DataRow(new int[] { 1, 2, 3 }, new int[] { 1 })] + [DataRow(new int[] { 1, 2 }, new int[] { 1, 2, 3 })] + [DataRow(new int[] { 1, 2, 3, 4, 5 }, new int[] { 1, 2, 3 })] public void VerifyCombinedListCombinesCorrectly(IReadOnlyList listOne, IReadOnlyList listTwo) { CombinedList combined = new CombinedList(listOne, listTwo); @@ -27,7 +25,7 @@ public void VerifyCombinedListCombinesCorrectly(IReadOnlyList listOne, IRea manuallyAppended.AddRange(listOne); manuallyAppended.AddRange(listTwo); - Assert.Equal(combined.Count, manuallyAppended.Count); + Assert.AreEqual(combined.Count, manuallyAppended.Count); int enumerationCount = 0; foreach (int value in combined) @@ -35,7 +33,7 @@ public void VerifyCombinedListCombinesCorrectly(IReadOnlyList listOne, IRea enumerationCount++; } - Assert.Equal(enumerationCount, combined.Count); + Assert.AreEqual(enumerationCount, combined.Count); } } } diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DefaultTemplatePackageProviderTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DefaultTemplatePackageProviderTests.cs index 52b5ea99c741..c67fbd131d74 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DefaultTemplatePackageProviderTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DefaultTemplatePackageProviderTests.cs @@ -1,23 +1,42 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.NET.TestFramework; using Microsoft.TemplateEngine.Abstractions; using Microsoft.TemplateEngine.TestHelper; -using Xunit; namespace Microsoft.TemplateEngine.Utils.UnitTests { - public class DefaultTemplatePackageProviderTests : IClassFixture + [TestClass] + public class DefaultTemplatePackageProviderTests { - private readonly IEngineEnvironmentSettings _engineEnvironmentSettings; + // MSTest has no IClassFixture equivalent; a lazily-initialized static helper + // mirrors the per-class lifetime that xUnit's IClassFixture provides. + private static readonly Lazy s_environmentSettingsHelper = + new(() => new EnvironmentSettingsHelper(NullMessageSink.Instance)); - public DefaultTemplatePackageProviderTests(EnvironmentSettingsHelper environmentSettingsHelper) + private IEngineEnvironmentSettings _engineEnvironmentSettings = null!; + + public TestContext TestContext { get; set; } = null!; + + [TestInitialize] + public void TestInitialize() + { + _engineEnvironmentSettings = s_environmentSettingsHelper.Value.CreateEnvironment( + hostIdentifier: GetType().Name, + virtualize: true); + } + + [ClassCleanup] + public static void ClassCleanup() { - _engineEnvironmentSettings = environmentSettingsHelper.CreateEnvironment(hostIdentifier: this.GetType().Name, virtualize: true); + if (s_environmentSettingsHelper.IsValueCreated) + { + s_environmentSettingsHelper.Value.Dispose(); + } } - [Fact] + [TestMethod] public async Task ReturnsFoldersAndNuPkgs() { string testAssetsDir = SdkTestContext.Current.TestAssetsDirectory; @@ -29,14 +48,14 @@ public async Task ReturnsFoldersAndNuPkgs() var nupkgs = new[] { Path.Combine(templateEngineTestAssets, "nupkg_templates", "*.nupkg") }; var provider = new DefaultTemplatePackageProvider(null!, _engineEnvironmentSettings, nupkgs, folders); - var sources = await provider.GetAllTemplatePackagesAsync(TestContext.Current.CancellationToken); + var sources = await provider.GetAllTemplatePackagesAsync(TestContext.CancellationTokenSource.Token); //Total should be 7 - Assert.Equal(7, sources.Count); + Assert.AreEqual(7, sources.Count); - Assert.True(sources[0].LastChangeTime > new DateTime(2000, 1, 1)); - Assert.False(string.IsNullOrWhiteSpace(sources[0].MountPointUri)); - Assert.Equal(provider, sources[0].Provider); + Assert.IsTrue(sources[0].LastChangeTime > new DateTime(2000, 1, 1)); + Assert.IsFalse(string.IsNullOrWhiteSpace(sources[0].MountPointUri)); + Assert.AreEqual(provider, sources[0].Provider); } } } diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DirectedGraphTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DirectedGraphTests.cs index ad88af7039c1..e6bc3e210d5f 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DirectedGraphTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DirectedGraphTests.cs @@ -1,11 +1,11 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using FluentAssertions; -using Xunit; namespace Microsoft.TemplateEngine.Utils.UnitTests { + [TestClass] public class DirectedGraphTests { public static IEnumerable DirectedGraphHasCycleData() @@ -83,23 +83,20 @@ public class DirectedGraphTests }; } - [Theory] - [MemberData(nameof(DirectedGraphHasCycleData))] -#pragma warning disable xUnit1026 // Theory methods should use all of their parameters + [TestMethod] + [DynamicData(nameof(DirectedGraphHasCycleData))] public void HasCycleTests(Dictionary> dependencies, bool shouldHaveCycle, IReadOnlyList expectedCycle, IReadOnlyList unused) -#pragma warning restore xUnit1026 // Theory methods should use all of their parameters { + _ = unused; new DirectedGraph(dependencies).HasCycle(out IReadOnlyList cycle).Should().Be(shouldHaveCycle); cycle.Should().BeEquivalentTo(expectedCycle, options => options.WithStrictOrdering()); - //cycle.SequenceEqual(expectedCycle).Should().BeTrue(); } - [Theory] - [MemberData(nameof(DirectedGraphHasCycleData))] -#pragma warning disable xUnit1026 // Theory methods should use all of their parameters + [TestMethod] + [DynamicData(nameof(DirectedGraphHasCycleData))] public void EnumerateTopologicalSortTests(Dictionary> dependencies, bool shouldHaveCycle, IReadOnlyList unused, IReadOnlyList expectedOrder) -#pragma warning restore xUnit1026 // Theory methods should use all of their parameters { + _ = unused; new DirectedGraph(dependencies).TryGetTopologicalSort(out IReadOnlyList order).Should().Be(!shouldHaveCycle); if (!shouldHaveCycle) { @@ -211,8 +208,8 @@ public void EnumerateTopologicalSortTests(Dictionary> dependen yield return new object?[] { graphB, new List() { 20 }, false, new Dictionary>() { { 1, empty } } }; } - [Theory] - [MemberData(nameof(DirectedGraphSubgraphData))] + [TestMethod] + [DynamicData(nameof(DirectedGraphSubgraphData))] public void GetSubGraphDependandOnVerticesTests(Dictionary> dependencies, IReadOnlyList vertices, bool includeSeedVertices, Dictionary> expectedResult) { var result = new DirectedGraph(dependencies).GetSubGraphDependentOnVertices(vertices, includeSeedVertices); diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/EqualityExtensionsTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/EqualityExtensionsTests.cs index f1834ad648d4..508ce48dd1ae 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/EqualityExtensionsTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/EqualityExtensionsTests.cs @@ -1,13 +1,12 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Xunit; - namespace Microsoft.TemplateEngine.Utils.UnitTests { + [TestClass] public class EqualityExtensionsTests { - [Fact(DisplayName = "AllAreTheSameDefaultComparerTrueTest")] + [TestMethod] public void AllAreTheSameDefaultComparerTrueTest() { IDictionary items = new Dictionary() @@ -19,10 +18,10 @@ public void AllAreTheSameDefaultComparerTrueTest() }; static string Selector(KeyValuePair x) => x.Value; - Assert.True(items.AllAreTheSame(Selector)); + Assert.IsTrue(items.AllAreTheSame(Selector)); } - [Fact(DisplayName = "AllAreTheSameDefaultComparerFailsTest")] + [TestMethod] public void AllAreTheSameDefaultComparerFailsTest() { IDictionary items = new Dictionary() @@ -34,10 +33,10 @@ public void AllAreTheSameDefaultComparerFailsTest() }; static string Selector(KeyValuePair x) => x.Value; - Assert.False(items.AllAreTheSame(Selector)); + Assert.IsFalse(items.AllAreTheSame(Selector)); } - [Fact(DisplayName = "AllAreTheSameCustomComparerTest")] + [TestMethod] public void AllAreTheSameCustomComparerTest() { IDictionary items = new Dictionary() @@ -52,10 +51,10 @@ public void AllAreTheSameCustomComparerTest() static bool LengthComparer(string? x, string? y) => x!.Length == y!.Length; // they're all the same length - Assert.True(items.AllAreTheSame(Selector, LengthComparer)); + Assert.IsTrue(items.AllAreTheSame(Selector, LengthComparer)); static bool UpperComparer(string? x, string? y) => x!.ToUpper() == y!.ToUpper(); - Assert.False(items.AllAreTheSame(Selector, UpperComparer)); + Assert.IsFalse(items.AllAreTheSame(Selector, UpperComparer)); } } } diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/GlobTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/GlobTests.cs index cb5c07557ebf..4c633e58cf37 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/GlobTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/GlobTests.cs @@ -1,122 +1,121 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Xunit; - namespace Microsoft.TemplateEngine.Utils.UnitTests { + [TestClass] public class GlobTests { - [Fact(DisplayName = nameof(VerifyLeadGlobPathSpanning))] + [TestMethod] public void VerifyLeadGlobPathSpanning() { Glob g = Glob.Parse("**/file"); - Assert.True(g.IsMatch("file")); - Assert.True(g.IsMatch("a/file")); - Assert.True(g.IsMatch("a/b/file")); - Assert.True(g.IsMatch("a/b/c/file")); - Assert.False(g.IsMatch("other")); - Assert.False(g.IsMatch("a/other")); - Assert.False(g.IsMatch("a/b/other")); - Assert.False(g.IsMatch("a/b/c/other")); - Assert.False(g.IsMatch("file/stuff")); - Assert.False(g.IsMatch("file.txt")); - Assert.False(g.IsMatch("thefile")); + Assert.IsTrue(g.IsMatch("file")); + Assert.IsTrue(g.IsMatch("a/file")); + Assert.IsTrue(g.IsMatch("a/b/file")); + Assert.IsTrue(g.IsMatch("a/b/c/file")); + Assert.IsFalse(g.IsMatch("other")); + Assert.IsFalse(g.IsMatch("a/other")); + Assert.IsFalse(g.IsMatch("a/b/other")); + Assert.IsFalse(g.IsMatch("a/b/c/other")); + Assert.IsFalse(g.IsMatch("file/stuff")); + Assert.IsFalse(g.IsMatch("file.txt")); + Assert.IsFalse(g.IsMatch("thefile")); } - [Fact(DisplayName = nameof(VerifyGlobExactPathSpanning))] + [TestMethod] public void VerifyGlobExactPathSpanning() { Glob g = Glob.Parse("a/**/b"); - Assert.True(g.IsMatch("a/b")); - Assert.True(g.IsMatch("a/x/b")); - Assert.True(g.IsMatch("a/x/y/b")); - Assert.False(g.IsMatch("z/a/x/y/b")); - Assert.False(g.IsMatch("z/a/b")); + Assert.IsTrue(g.IsMatch("a/b")); + Assert.IsTrue(g.IsMatch("a/x/b")); + Assert.IsTrue(g.IsMatch("a/x/y/b")); + Assert.IsFalse(g.IsMatch("z/a/x/y/b")); + Assert.IsFalse(g.IsMatch("z/a/b")); } - [Fact(DisplayName = nameof(VerifyGlobPathSpanning))] + [TestMethod] public void VerifyGlobPathSpanning() { Glob g = Glob.Parse("a/**"); - Assert.True(g.IsMatch("a/b")); - Assert.True(g.IsMatch("a/x/b")); - Assert.True(g.IsMatch("a/x/y/b")); - Assert.False(g.IsMatch("z/a/x/y/b")); - Assert.False(g.IsMatch("z/a/b")); + Assert.IsTrue(g.IsMatch("a/b")); + Assert.IsTrue(g.IsMatch("a/x/b")); + Assert.IsTrue(g.IsMatch("a/x/y/b")); + Assert.IsFalse(g.IsMatch("z/a/x/y/b")); + Assert.IsFalse(g.IsMatch("z/a/b")); } - [Fact(DisplayName = nameof(VerifyGlobCharacterGroups))] + [TestMethod] public void VerifyGlobCharacterGroups() { Glob g = Glob.Parse("f[Oo]o"); - Assert.True(g.IsMatch("foo")); - Assert.True(g.IsMatch("fOo")); - Assert.True(g.IsMatch("a/foo")); - Assert.True(g.IsMatch("z/a/x/y/fOo")); - Assert.False(g.IsMatch("z/a/x/y/fOO")); + Assert.IsTrue(g.IsMatch("foo")); + Assert.IsTrue(g.IsMatch("fOo")); + Assert.IsTrue(g.IsMatch("a/foo")); + Assert.IsTrue(g.IsMatch("z/a/x/y/fOo")); + Assert.IsFalse(g.IsMatch("z/a/x/y/fOO")); } - [Fact(DisplayName = nameof(VerifyGlobWildcard))] + [TestMethod] public void VerifyGlobWildcard() { Glob g = Glob.Parse("f*o"); - Assert.True(g.IsMatch("foo")); - Assert.True(g.IsMatch("foooooooo")); - Assert.False(g.IsMatch("foot")); + Assert.IsTrue(g.IsMatch("foo")); + Assert.IsTrue(g.IsMatch("foooooooo")); + Assert.IsFalse(g.IsMatch("foot")); } - [Fact(DisplayName = nameof(VerifyGlobNegate))] + [TestMethod] public void VerifyGlobNegate() { Glob g = Glob.Parse("!f*o"); - Assert.False(g.IsMatch("foo")); - Assert.False(g.IsMatch("foooooooo")); - Assert.True(g.IsMatch("foot")); + Assert.IsFalse(g.IsMatch("foo")); + Assert.IsFalse(g.IsMatch("foooooooo")); + Assert.IsTrue(g.IsMatch("foot")); } - [Fact(DisplayName = nameof(VerifyGlobEscape))] + [TestMethod] public void VerifyGlobEscape() { Glob g = Glob.Parse(@"\[[\[\ \]]"); - Assert.True(g.IsMatch("[ ")); - Assert.True(g.IsMatch("[]")); - Assert.True(g.IsMatch("[[")); - Assert.False(g.IsMatch("]")); + Assert.IsTrue(g.IsMatch("[ ")); + Assert.IsTrue(g.IsMatch("[]")); + Assert.IsTrue(g.IsMatch("[[")); + Assert.IsFalse(g.IsMatch("]")); } - [Fact(DisplayName = nameof(VerifyGlobKitchenSink))] + [TestMethod] public void VerifyGlobKitchenSink() { Glob g = Glob.Parse("**/[Dd]ocuments/**/*.htm*"); - Assert.True(g.IsMatch("Documents/git.html")); - Assert.True(g.IsMatch("Documents/ppc/ppc.html")); - Assert.True(g.IsMatch("tools/perf/Documents/perf.html")); + Assert.IsTrue(g.IsMatch("Documents/git.html")); + Assert.IsTrue(g.IsMatch("Documents/ppc/ppc.html")); + Assert.IsTrue(g.IsMatch("tools/perf/Documents/perf.html")); g = Glob.Parse("**/[Dd]ocuments/**/*p*.htm*"); - Assert.False(g.IsMatch("Documents/git.html")); - Assert.True(g.IsMatch("Documents/ppc/ppc.html")); - Assert.True(g.IsMatch("tools/perf/Documents/perf.html")); + Assert.IsFalse(g.IsMatch("Documents/git.html")); + Assert.IsTrue(g.IsMatch("Documents/ppc/ppc.html")); + Assert.IsTrue(g.IsMatch("tools/perf/Documents/perf.html")); g = Glob.Parse("[Dd]ocuments/**/*.htm*"); - Assert.True(g.IsMatch("Documents/git.html")); - Assert.True(g.IsMatch("Documents/ppc/ppc.html")); - Assert.False(g.IsMatch("tools/perf/Documents/perf.html")); + Assert.IsTrue(g.IsMatch("Documents/git.html")); + Assert.IsTrue(g.IsMatch("Documents/ppc/ppc.html")); + Assert.IsFalse(g.IsMatch("tools/perf/Documents/perf.html")); g = Glob.Parse("[Dd]ocuments/**/*.h*"); - Assert.True(g.IsMatch("Documents/git.html")); - Assert.True(g.IsMatch("Documents/ppc/ppc.html")); - Assert.False(g.IsMatch("tools/perf/Documents/perf.html")); + Assert.IsTrue(g.IsMatch("Documents/git.html")); + Assert.IsTrue(g.IsMatch("Documents/ppc/ppc.html")); + Assert.IsFalse(g.IsMatch("tools/perf/Documents/perf.html")); g = Glob.Parse("[Dd]ocuments/**/*.html"); - Assert.True(g.IsMatch("Documents/git.html")); - Assert.True(g.IsMatch("Documents/ppc/ppc.html")); - Assert.False(g.IsMatch("tools/perf/Documents/perf.html")); + Assert.IsTrue(g.IsMatch("Documents/git.html")); + Assert.IsTrue(g.IsMatch("Documents/ppc/ppc.html")); + Assert.IsFalse(g.IsMatch("tools/perf/Documents/perf.html")); g = Glob.Parse("[Dd]ocuments/*.html"); - Assert.True(g.IsMatch("Documents/git.html")); - Assert.False(g.IsMatch("Documents/ppc/ppc.html")); - Assert.False(g.IsMatch("tools/perf/Documents/perf.html")); + Assert.IsTrue(g.IsMatch("Documents/git.html")); + Assert.IsFalse(g.IsMatch("Documents/ppc/ppc.html")); + Assert.IsFalse(g.IsMatch("tools/perf/Documents/perf.html")); } } } diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/GlobalUsings.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/GlobalUsings.cs new file mode 100644 index 000000000000..6203351f775a --- /dev/null +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/GlobalUsings.cs @@ -0,0 +1,10 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// Microsoft.TemplateEngine.TestHelper still references xunit.v3.extensibility.core +// (it is consumed by other in-tree xUnit projects and is not part of this migration). +// EnvironmentSettingsHelper's constructor takes an Xunit.Sdk.IMessageSink. We surface +// it here with a short alias so the tests below can construct a no-op sink without +// pulling in xUnit's global usings (which would conflict with MSTest's Assert). +global using IMessageSink = Xunit.Sdk.IMessageSink; +global using IMessageSinkMessage = Xunit.Sdk.IMessageSinkMessage; diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InMemoryFileSystemTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InMemoryFileSystemTests.cs index 7da80beb1b12..0db9db34e3e3 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InMemoryFileSystemTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InMemoryFileSystemTests.cs @@ -1,15 +1,15 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.TemplateEngine.Abstractions.PhysicalFileSystem; using Microsoft.TemplateEngine.Mocks; -using Xunit; namespace Microsoft.TemplateEngine.Utils.UnitTests { + [TestClass] public class InMemoryFileSystemTests { - [Fact(DisplayName = nameof(VerifyMultipleVirtualizationsAreHandled))] + [TestMethod] public void VerifyMultipleVirtualizationsAreHandled() { IPhysicalFileSystem mockFileSystem = new MockFileSystem(); @@ -18,9 +18,9 @@ public void VerifyMultipleVirtualizationsAreHandled() string testFilePath = Directory.GetCurrentDirectory().CombinePaths("test1", "test.txt"); virtualized2.CreateFile(testFilePath).Dispose(); - Assert.False(mockFileSystem.FileExists(testFilePath)); - Assert.True(virtualized1.FileExists(testFilePath)); - Assert.True(virtualized2.FileExists(testFilePath)); + Assert.IsFalse(mockFileSystem.FileExists(testFilePath)); + Assert.IsTrue(virtualized1.FileExists(testFilePath)); + Assert.IsTrue(virtualized2.FileExists(testFilePath)); } } } diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs index 00043a9c0304..ee030f4cfb37 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs @@ -1,51 +1,68 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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.InteropServices; using Microsoft.TemplateEngine.Abstractions; using Microsoft.TemplateEngine.TestHelper; -using Xunit; namespace Microsoft.TemplateEngine.Utils.UnitTests { - public class InstallRequestPathResolutionTests : IClassFixture + [TestClass] + public class InstallRequestPathResolutionTests { - private readonly IEngineEnvironmentSettings _engineEnvironmentSettings; + // MSTest has no IClassFixture equivalent; a lazily-initialized static helper + // mirrors the per-class lifetime that xUnit's IClassFixture provides. + private static readonly Lazy s_environmentSettingsHelper = + new(() => new EnvironmentSettingsHelper(NullMessageSink.Instance)); - public InstallRequestPathResolutionTests(EnvironmentSettingsHelper environmentSettingsHelper) + private IEngineEnvironmentSettings _engineEnvironmentSettings = null!; + + [TestInitialize] + public void TestInitialize() + { + _engineEnvironmentSettings = s_environmentSettingsHelper.Value.CreateEnvironment( + hostIdentifier: GetType().Name, + virtualize: true); + } + + [ClassCleanup] + public static void ClassCleanup() { - _engineEnvironmentSettings = environmentSettingsHelper.CreateEnvironment(hostIdentifier: this.GetType().Name, virtualize: true); + if (s_environmentSettingsHelper.IsValueCreated) + { + s_environmentSettingsHelper.Value.Dispose(); + } } - [Fact] + [TestMethod] public void CanResolvePath() { IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath(Directory.GetCurrentDirectory(), _engineEnvironmentSettings); - Assert.Equal(Directory.GetCurrentDirectory(), installPath.Single()); + Assert.AreEqual(Directory.GetCurrentDirectory(), installPath.Single()); } - [Fact] + [TestMethod] public void CanTrimTrailingSeparator() { IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath(Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar, _engineEnvironmentSettings); - Assert.Equal(Directory.GetCurrentDirectory(), installPath.Single()); + Assert.AreEqual(Directory.GetCurrentDirectory(), installPath.Single()); } - [Fact] + [TestMethod] public void CanResolveCurrentPath() { IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath(".", _engineEnvironmentSettings); - Assert.Equal(Directory.GetCurrentDirectory(), installPath.Single()); + Assert.AreEqual(Directory.GetCurrentDirectory(), installPath.Single()); } - [Fact] + [TestMethod] public void CanResolveParentPath() { IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath("..", _engineEnvironmentSettings); - Assert.Equal(Path.GetDirectoryName(Directory.GetCurrentDirectory()), installPath.Single()); + Assert.AreEqual(Path.GetDirectoryName(Directory.GetCurrentDirectory()), installPath.Single()); } - [Fact] + [TestMethod] public void CanResolveSubdirectories() { var testRootDir = TestUtils.CreateTemporaryFolder(); @@ -55,11 +72,11 @@ public void CanResolveSubdirectories() IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath(Path.Combine(testRootDir, "*"), _engineEnvironmentSettings); - Assert.Equal(3, installPath.Count()); + Assert.AreEqual(3, installPath.Count()); Assert.Contains(Path.Combine(testRootDir, "dir1"), installPath); } - [Fact] + [TestMethod] public void CanResolveMaskedSubdirectories() { var testRootDir = TestUtils.CreateTemporaryFolder(); @@ -69,12 +86,12 @@ public void CanResolveMaskedSubdirectories() IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath(Path.Combine(testRootDir, "dir*"), _engineEnvironmentSettings); - Assert.Equal(2, installPath.Count()); + Assert.AreEqual(2, installPath.Count()); Assert.Contains(Path.Combine(testRootDir, "dir1"), installPath); Assert.Contains(Path.Combine(testRootDir, "dir33"), installPath); } - [Fact] + [TestMethod] public void CanResolveMaskedFiles() { var testRootDir = TestUtils.CreateTemporaryFolder(); @@ -84,30 +101,30 @@ public void CanResolveMaskedFiles() IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath(Path.Combine(testRootDir, "*.nupkg"), _engineEnvironmentSettings); - Assert.Equal(2, installPath.Count()); + Assert.AreEqual(2, installPath.Count()); Assert.Contains(Path.Combine(testRootDir, "1.nupkg"), installPath); Assert.Contains(Path.Combine(testRootDir, "2.nupkg"), installPath); } - [Fact] + [TestMethod] public void CannotResolveInvalidPath() { IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath("|path|", _engineEnvironmentSettings); - Assert.Equal("|path|", installPath.Single()); + Assert.AreEqual("|path|", installPath.Single()); } - [Fact] + [TestMethod] public void CannotResolveNonExistingPath() { - Assert.False(File.Exists("path")); + Assert.IsFalse(File.Exists("path")); IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath("path", _engineEnvironmentSettings); - Assert.Equal("path", installPath.Single()); + Assert.AreEqual("path", installPath.Single()); installPath = InstallRequestPathResolution.ExpandMaskedPath("path\\", _engineEnvironmentSettings); - Assert.Equal("path\\", installPath.Single()); + Assert.AreEqual("path\\", installPath.Single()); } - [Fact] + [TestMethod] public void CannotResolveMaskedPathInFolder() { var testRootDir = TestUtils.CreateTemporaryFolder(); @@ -116,16 +133,16 @@ public void CannotResolveMaskedPathInFolder() File.Create(Path.Combine(testRootDir, "dir", "2.nupkg")); IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath(Path.Combine(testRootDir, "*", "*.nupkg"), _engineEnvironmentSettings); - Assert.Equal(Path.Combine(testRootDir, "*", "*.nupkg"), installPath.Single()); + Assert.AreEqual(Path.Combine(testRootDir, "*", "*.nupkg"), installPath.Single()); } - [Fact] + [TestMethod] public void CanResolveParentOfRootFolder() { string dir = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "C:\\" : "/"; IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath(dir + "..", _engineEnvironmentSettings); - Assert.Equal(dir, installPath.Single()); + Assert.AreEqual(dir, installPath.Single()); } } } diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/ListExtensionsTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/ListExtensionsTests.cs index c6eea96dd72d..e13316ff54c2 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/ListExtensionsTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/ListExtensionsTests.cs @@ -1,13 +1,12 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Xunit; - namespace Microsoft.TemplateEngine.Utils.UnitTests { + [TestClass] public class ListExtensionsTests { - [Fact(DisplayName = nameof(GroupByExtensionTest))] + [TestMethod] public void GroupByExtensionTest() { List templatesToGroup = new List @@ -60,12 +59,12 @@ public void GroupByExtensionTest() }; var templateGroups = templatesToGroup.GroupBy(x => x._groupIdentity, x => !string.IsNullOrEmpty(x._groupIdentity), StringComparer.OrdinalIgnoreCase); - Assert.Equal(7, templateGroups.Count()); + Assert.AreEqual(7, templateGroups.Count()); var groupWithExpectedMultipleElements = templateGroups.Single(g => g.Key?.Equals("TemplateGroup", StringComparison.OrdinalIgnoreCase) ?? false); - Assert.Equal(3, groupWithExpectedMultipleElements.Count()); - Assert.Single(groupWithExpectedMultipleElements, s => s._identity == "5"); - Assert.Single(groupWithExpectedMultipleElements, s => s._identity == "6"); - Assert.Single(groupWithExpectedMultipleElements, s => s._identity == "9"); + Assert.AreEqual(3, groupWithExpectedMultipleElements.Count()); + Assert.AreEqual(1, groupWithExpectedMultipleElements.Count(s => s._identity == "5")); + Assert.AreEqual(1, groupWithExpectedMultipleElements.Count(s => s._identity == "6")); + Assert.AreEqual(1, groupWithExpectedMultipleElements.Count(s => s._identity == "9")); } internal struct GroupByTestStruct diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/Microsoft.TemplateEngine.Utils.UnitTests.csproj b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/Microsoft.TemplateEngine.Utils.UnitTests.csproj index f98adba4e2f7..5ee2997deb66 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/Microsoft.TemplateEngine.Utils.UnitTests.csproj +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/Microsoft.TemplateEngine.Utils.UnitTests.csproj @@ -1,7 +1,9 @@ - + $(NetCurrent);$(NetFrameworkCurrent) + true + enable @@ -10,9 +12,4 @@ - - - - - diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/NullMessageSink.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/NullMessageSink.cs new file mode 100644 index 000000000000..35022b22fe52 --- /dev/null +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/NullMessageSink.cs @@ -0,0 +1,20 @@ +// 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.Utils.UnitTests; + +/// +/// A no-op used to satisfy +/// 's constructor +/// in an MSTest context (no xUnit runner is present to provide one). +/// +internal sealed class NullMessageSink : IMessageSink +{ + public static readonly IMessageSink Instance = new NullMessageSink(); + + private NullMessageSink() + { + } + + public bool OnMessage(IMessageSinkMessage message) => true; +} diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/VersionStringTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/VersionStringTests.cs index deb189ee15eb..eee39be40f33 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/VersionStringTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/VersionStringTests.cs @@ -1,74 +1,73 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using Xunit; - namespace Microsoft.TemplateEngine.Utils.UnitTests { + [TestClass] public class VersionStringTests { - [Theory(DisplayName = nameof(VerifyVersionIsWellFormedCheckerTest))] - [InlineData("1.0.0.0", true)] - [InlineData("1.0.0", true)] - [InlineData("1.0", true)] - [InlineData("1", false)] - [InlineData("1.0.0.0.", false)] - [InlineData("1.0.0.", false)] - [InlineData("1.0.", false)] - [InlineData("1.", false)] - [InlineData("MyVersion", false)] - [InlineData("1.0.0.A", false)] - [InlineData("A.0.0.0", false)] - [InlineData("", false)] - [InlineData(null, false)] + [TestMethod] + [DataRow("1.0.0.0", true)] + [DataRow("1.0.0", true)] + [DataRow("1.0", true)] + [DataRow("1", false)] + [DataRow("1.0.0.0.", false)] + [DataRow("1.0.0.", false)] + [DataRow("1.0.", false)] + [DataRow("1.", false)] + [DataRow("MyVersion", false)] + [DataRow("1.0.0.A", false)] + [DataRow("A.0.0.0", false)] + [DataRow("", false)] + [DataRow(null, false)] public void VerifyVersionIsWellFormedCheckerTest(string? versionString, bool expectedParseResult) { - Assert.Equal(expectedParseResult, VersionStringHelpers.IsVersionWellFormed(versionString)); + Assert.AreEqual(expectedParseResult, VersionStringHelpers.IsVersionWellFormed(versionString)); } - [Theory(DisplayName = nameof(VerifyVersionComparisonTest))] - [InlineData("", "", null)] - [InlineData(null, null, null)] - [InlineData("1.0.0.0", "1.0.0.0", 0)] - [InlineData("1.0.0.0", null, null)] - [InlineData(null, "1.0.0.0", null)] - [InlineData("1.0.0.0", "1.1.0.0", -1)] - [InlineData("1.1.0.0", "1.0.0.0", 1)] - [InlineData("1.0.0", "1.1", -1)] - [InlineData("1.1", "1.0.0", 1)] + [TestMethod] + [DataRow("", "", null)] + [DataRow(null, null, null)] + [DataRow("1.0.0.0", "1.0.0.0", 0)] + [DataRow("1.0.0.0", null, null)] + [DataRow(null, "1.0.0.0", null)] + [DataRow("1.0.0.0", "1.1.0.0", -1)] + [DataRow("1.1.0.0", "1.0.0.0", 1)] + [DataRow("1.0.0", "1.1", -1)] + [DataRow("1.1", "1.0.0", 1)] public void VerifyVersionComparisonTest(string? version1, string? version2, int? expectedComparison) { - Assert.Equal(expectedComparison, VersionStringHelpers.CompareVersions(version1, version2)); + Assert.AreEqual(expectedComparison, VersionStringHelpers.CompareVersions(version1, version2)); } - [Theory(DisplayName = nameof(VersionParseCompare))] - [InlineData("1.0.0.0", "1.0.0.0", true)] - [InlineData("1.0.0.0", "1.0.0", true)] - [InlineData("1.0.0.0", "1.0", true)] - [InlineData("1.0.0.0", "1.1", false)] - [InlineData("2.0.0.0", "1.1", false)] - [InlineData("[1.0.0.0-*)", "1.0.0.0", true)] - [InlineData("[1.0.0.0-*)", "1.1.0.0", true)] - [InlineData("[1.0.0.0-*)", "1.0.1.0", true)] - [InlineData("[1.0.0.0-*)", "1.0.0.1", true)] - [InlineData("(1.0.0.0-*)", "1.0.0.0", false)] - [InlineData("(*-2.0.0.0)", "1.0.0.0", true)] - [InlineData("(*-2.0.0.0)", "1.5.0.0", true)] - [InlineData("(*-2.0.0.0)", "2.0.0.0", false)] - [InlineData("(*-2.0.0.0]", "2.0.0.0", true)] - [InlineData("[1.1.0.0-1.2.0.0]", "1.0.0.0", false)] - [InlineData("[1.1.0.0-1.2.0.0]", "1.1.0.0", true)] - [InlineData("[1.1.0.0-1.2.0.0]", "1.2.0.0", true)] - [InlineData("[1.1.0.0-1.2.0.0]", "1.2.0.1", false)] - [InlineData("(1.1.0.0-1.2.0.0)", "1.1.0.0", false)] - [InlineData("(1.1.0.0-1.2.0.0)", "1.2.0.0", false)] - [InlineData("(1.1.0.0-1.2.0.0)", "1.1.1.0", true)] - [InlineData("(1.1.0.0-1.2.0.0)", "1.1.0.1", true)] + [TestMethod] + [DataRow("1.0.0.0", "1.0.0.0", true)] + [DataRow("1.0.0.0", "1.0.0", true)] + [DataRow("1.0.0.0", "1.0", true)] + [DataRow("1.0.0.0", "1.1", false)] + [DataRow("2.0.0.0", "1.1", false)] + [DataRow("[1.0.0.0-*)", "1.0.0.0", true)] + [DataRow("[1.0.0.0-*)", "1.1.0.0", true)] + [DataRow("[1.0.0.0-*)", "1.0.1.0", true)] + [DataRow("[1.0.0.0-*)", "1.0.0.1", true)] + [DataRow("(1.0.0.0-*)", "1.0.0.0", false)] + [DataRow("(*-2.0.0.0)", "1.0.0.0", true)] + [DataRow("(*-2.0.0.0)", "1.5.0.0", true)] + [DataRow("(*-2.0.0.0)", "2.0.0.0", false)] + [DataRow("(*-2.0.0.0]", "2.0.0.0", true)] + [DataRow("[1.1.0.0-1.2.0.0]", "1.0.0.0", false)] + [DataRow("[1.1.0.0-1.2.0.0]", "1.1.0.0", true)] + [DataRow("[1.1.0.0-1.2.0.0]", "1.2.0.0", true)] + [DataRow("[1.1.0.0-1.2.0.0]", "1.2.0.1", false)] + [DataRow("(1.1.0.0-1.2.0.0)", "1.1.0.0", false)] + [DataRow("(1.1.0.0-1.2.0.0)", "1.2.0.0", false)] + [DataRow("(1.1.0.0-1.2.0.0)", "1.1.1.0", true)] + [DataRow("(1.1.0.0-1.2.0.0)", "1.1.0.1", true)] public void VersionParseCompare(string allowed, string proposed, bool expected) { - Assert.True(VersionStringHelpers.TryParseVersionSpecification(allowed, out IVersionSpecification? checker)); - Assert.NotNull(checker); - Assert.Equal(expected, checker.CheckIfVersionIsValid(proposed)); + Assert.IsTrue(VersionStringHelpers.TryParseVersionSpecification(allowed, out IVersionSpecification? checker)); + Assert.IsNotNull(checker); + Assert.AreEqual(expected, checker.CheckIfVersionIsValid(proposed)); } } } diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/WellKnownSearchFiltersTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/WellKnownSearchFiltersTests.cs index 81333ab45a2f..9b04716418dc 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/WellKnownSearchFiltersTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/WellKnownSearchFiltersTests.cs @@ -1,19 +1,19 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using Microsoft.TemplateEngine.Abstractions.TemplateFiltering; using Microsoft.TemplateEngine.Mocks; -using Xunit; namespace Microsoft.TemplateEngine.Utils.UnitTests { + [TestClass] public class WellKnownSearchFiltersTests { - [Theory] - [InlineData("test", "test", MatchKind.Exact)] - [InlineData("test1||test2", "test1", MatchKind.Exact)] - [InlineData("test1||test2", "test", MatchKind.Mismatch)] - [InlineData("test1||test2", null, null)] + [TestMethod] + [DataRow("test", "test", MatchKind.Exact)] + [DataRow("test1||test2", "test1", MatchKind.Exact)] + [DataRow("test1||test2", "test", MatchKind.Mismatch)] + [DataRow("test1||test2", null, null)] public void TagFilterTests_TemplateWithTags(string templateTags, string? testTag, MatchKind? kind) { const string separator = "||"; @@ -27,12 +27,12 @@ public void TagFilterTests_TemplateWithTags(string templateTags, string? testTag var filter = WellKnownSearchFilters.ClassificationFilter(testTag); MatchInfo? result = filter(template); - Assert.Equal(kind, result?.Kind); + Assert.AreEqual(kind, result?.Kind); } - [Theory] - [InlineData("test", MatchKind.Mismatch)] - [InlineData(null, null)] + [TestMethod] + [DataRow("test", MatchKind.Mismatch)] + [DataRow(null, null)] public void TagFilterTests_TemplateWithoutTags(string? testTag, MatchKind? kind) { MockTemplateInfo template = new MockTemplateInfo("console", name: "Long name for Console App", identity: "Console.App.T1", groupIdentity: "Console.App.Test") @@ -42,7 +42,7 @@ public void TagFilterTests_TemplateWithoutTags(string? testTag, MatchKind? kind) var filter = WellKnownSearchFilters.ClassificationFilter(testTag); MatchInfo? result = filter(template); - Assert.Equal(kind, result?.Kind); + Assert.AreEqual(kind, result?.Kind); } } } From ab0b5dce2e3fd77a05ff96644693bf07b40bffd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Tue, 16 Jun 2026 05:34:38 +0200 Subject: [PATCH 2/4] Apply suggestion from @Evangelink --- .../DefaultTemplatePackageProviderTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DefaultTemplatePackageProviderTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DefaultTemplatePackageProviderTests.cs index c67fbd131d74..f2f25a7c8c7d 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DefaultTemplatePackageProviderTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/DefaultTemplatePackageProviderTests.cs @@ -48,7 +48,7 @@ public async Task ReturnsFoldersAndNuPkgs() var nupkgs = new[] { Path.Combine(templateEngineTestAssets, "nupkg_templates", "*.nupkg") }; var provider = new DefaultTemplatePackageProvider(null!, _engineEnvironmentSettings, nupkgs, folders); - var sources = await provider.GetAllTemplatePackagesAsync(TestContext.CancellationTokenSource.Token); + var sources = await provider.GetAllTemplatePackagesAsync(TestContext.CancellationToken); //Total should be 7 Assert.AreEqual(7, sources.Count); From 3439a2dc94a16dc981368c7f15d60131e6efea58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Tue, 16 Jun 2026 05:35:38 +0200 Subject: [PATCH 3/4] Apply suggestion from @Evangelink --- .../InstallRequestPathResolutionTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs index ee030f4cfb37..01a3e3cbf58a 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs @@ -130,7 +130,8 @@ public void CannotResolveMaskedPathInFolder() var testRootDir = TestUtils.CreateTemporaryFolder(); Directory.CreateDirectory(Path.Combine(testRootDir, "dir")); File.Create(Path.Combine(testRootDir, "dir", "1.nupkg")); - File.Create(Path.Combine(testRootDir, "dir", "2.nupkg")); +using _ = File.Create(Path.Combine(testRootDir, "dir", "1.nupkg")); +using _ = File.Create(Path.Combine(testRootDir, "dir", "2.nupkg")); IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath(Path.Combine(testRootDir, "*", "*.nupkg"), _engineEnvironmentSettings); Assert.AreEqual(Path.Combine(testRootDir, "*", "*.nupkg"), installPath.Single()); From ff76b5bfd22bcffdb4d8c5f09daaf228d8717212 Mon Sep 17 00:00:00 2001 From: Amaury Leveugle Date: Tue, 16 Jun 2026 13:01:38 +0200 Subject: [PATCH 4/4] Fix CS1001 build error in CannotResolveMaskedPathInFolder The migration accidentally duplicated the first File.Create line and prefixed both new lines with an invalid 'using _ =' (a using declaration cannot bind to the discard '_'), causing CS1001. Restore the two plain File.Create calls. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../InstallRequestPathResolutionTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs index 01a3e3cbf58a..ee030f4cfb37 100644 --- a/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs +++ b/test/TemplateEngine/Microsoft.TemplateEngine.Utils.UnitTests/InstallRequestPathResolutionTests.cs @@ -130,8 +130,7 @@ public void CannotResolveMaskedPathInFolder() var testRootDir = TestUtils.CreateTemporaryFolder(); Directory.CreateDirectory(Path.Combine(testRootDir, "dir")); File.Create(Path.Combine(testRootDir, "dir", "1.nupkg")); -using _ = File.Create(Path.Combine(testRootDir, "dir", "1.nupkg")); -using _ = File.Create(Path.Combine(testRootDir, "dir", "2.nupkg")); + File.Create(Path.Combine(testRootDir, "dir", "2.nupkg")); IEnumerable installPath = InstallRequestPathResolution.ExpandMaskedPath(Path.Combine(testRootDir, "*", "*.nupkg"), _engineEnvironmentSettings); Assert.AreEqual(Path.Combine(testRootDir, "*", "*.nupkg"), installPath.Single());