diff --git a/Directory.Build.props b/Directory.Build.props index 37e8a9c..11fcda5 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -61,10 +61,9 @@ true - + - <_Parameter1>Workers = 0 <_Parameter1_IsLiteral>true <_Parameter2>Scope = Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope.MethodLevel diff --git a/dotnet.config b/dotnet.config new file mode 100644 index 0000000..b87edde --- /dev/null +++ b/dotnet.config @@ -0,0 +1,2 @@ +[dotnet.test.runner] +name = "Microsoft.Testing.Platform" \ No newline at end of file diff --git a/global.json b/global.json index 0e48bd3..3cacc5e 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "msbuild-sdks": { - "MSTest.Sdk": "3.9.1" + "MSTest.Sdk": "4.0.1" } } diff --git a/src/Common.Tests/Hashing/DirectoryFileHasherTests.cs b/src/Common.Tests/Hashing/DirectoryFileHasherTests.cs index 37f1dd4..341c143 100644 --- a/src/Common.Tests/Hashing/DirectoryFileHasherTests.cs +++ b/src/Common.Tests/Hashing/DirectoryFileHasherTests.cs @@ -19,7 +19,7 @@ public class DirectoryFileHasherTests public TestContext TestContext { get; set; } #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. - [DataTestMethod] + [TestMethod] [DataRow(@"X:\Dir\Foo\1.0.0\lib\Foo.dll", true)] [DataRow(@"x:\dIR\Foo\1.0.0\lib\Foo.dll", true)] [DataRow(@"x:\OtherDir\foo.txt", false)] @@ -30,7 +30,7 @@ public void ContainsPath(string path, bool expectedResult) Assert.AreEqual(expectedResult, hasher.ContainsPath(path)); } - [DataTestMethod] + [TestMethod] [DataRow(@"Dir\Foo\1.0.0\lib\Foo.dll", true)] [DataRow(@"dIR\Foo\2.0.0\lib\Foo.dll", true)] [DataRow(@"OtherDir\foo.txt", false)] diff --git a/src/Common.Tests/Hashing/OutputHasherTests.cs b/src/Common.Tests/Hashing/OutputHasherTests.cs index b112dcf..ed046b2 100644 --- a/src/Common.Tests/Hashing/OutputHasherTests.cs +++ b/src/Common.Tests/Hashing/OutputHasherTests.cs @@ -50,7 +50,7 @@ public async Task ComputeHashFileNotFound() string file = Path.Combine(dir, "file.txt"); // Ensure exceptions are propagated correctly. - await Assert.ThrowsExceptionAsync(async () => await hasher.ComputeHashAsync(file, CancellationToken.None)); + await Assert.ThrowsExactlyAsync(async () => await hasher.ComputeHashAsync(file, CancellationToken.None)); } [TestMethod] diff --git a/src/Common.Tests/HexUtilitiesTests.cs b/src/Common.Tests/HexUtilitiesTests.cs index 72e04b4..029fdc8 100644 --- a/src/Common.Tests/HexUtilitiesTests.cs +++ b/src/Common.Tests/HexUtilitiesTests.cs @@ -10,7 +10,7 @@ namespace Microsoft.MSBuildCache.Tests; [TestClass] public class HexUtilitiesTests { - [DataTestMethod] + [TestMethod] [DataRow("0123456789ABCDEFabcdef", new byte[] { 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 0xAB, 0xCD, 0xEF, })] [DataRow("", null)] [DataRow(null, null)] @@ -26,15 +26,15 @@ public void HexToBytes(string hex, byte[]? expectedBytes) expectedBytes ??= Array.Empty(); - Assert.AreEqual(expectedBytes.Length, bytes.Length); + Assert.HasCount(expectedBytes.Length, bytes); for (int i = 0; i < expectedBytes.Length; i++) { - Assert.AreEqual(expectedBytes[i], bytes[i], "Index {0}", i); + Assert.AreEqual(expectedBytes[i], bytes[i], $"Index {i}"); } } [TestMethod] - public void HexToBytesOddChars() => Assert.ThrowsException(() => HexUtilities.HexToBytes("fAbCd")); + public void HexToBytesOddChars() => Assert.ThrowsExactly(() => HexUtilities.HexToBytes("fAbCd")); [TestMethod] public void HexToBytesBadChars() @@ -64,6 +64,6 @@ public void HexToBytesBadChars() } } - Assert.AreEqual(0, badCharactersMistakenlyAllowed.Count, "Bad characters were allowed that should not have been: " + string.Concat(badCharactersMistakenlyAllowed)); + Assert.IsEmpty(badCharactersMistakenlyAllowed, "Bad characters were allowed that should not have been: " + string.Concat(badCharactersMistakenlyAllowed)); } } \ No newline at end of file diff --git a/src/Common.Tests/NodeTargetResultTaskItemTests.cs b/src/Common.Tests/NodeTargetResultTaskItemTests.cs index 5bb6e45..6a79b62 100644 --- a/src/Common.Tests/NodeTargetResultTaskItemTests.cs +++ b/src/Common.Tests/NodeTargetResultTaskItemTests.cs @@ -34,7 +34,7 @@ public void FromTaskItem() Assert.IsNotNull(nodeTargetResultTaskItem); Assert.AreEqual(@"{RepoRoot}src\HelloWorld\bin\x64\Release\HelloWorld.dll", nodeTargetResultTaskItem.ItemSpec); - Assert.AreEqual(taskItem.CloneCustomMetadata().Count, nodeTargetResultTaskItem.Metadata.Count); + Assert.HasCount(taskItem.CloneCustomMetadata().Count, nodeTargetResultTaskItem.Metadata); Assert.AreEqual(".NETStandard", nodeTargetResultTaskItem.Metadata["TargetFrameworkIdentifier"]); Assert.AreEqual("Windows,Version=7.0", nodeTargetResultTaskItem.Metadata["TargetPlatformMoniker"]); Assert.AreEqual(@"{RepoRoot}src\HelloWorld\bin\x64\Release\HelloWorld.csproj.CopyComplete", nodeTargetResultTaskItem.Metadata["CopyUpToDateMarker"]); @@ -62,7 +62,7 @@ public void ToTaskItem() Assert.IsNotNull(taskItem); Assert.AreEqual(RepoRoot + @"\src\HelloWorld\bin\x64\Release\HelloWorld.dll", taskItem.ItemSpec); - Assert.AreEqual(nodeTargetResultTaskItem.Metadata.Count, taskItem.CloneCustomMetadata().Count); + Assert.HasCount(nodeTargetResultTaskItem.Metadata.Count, taskItem.CloneCustomMetadata()); Assert.AreEqual(".NETStandard", taskItem.GetMetadata("TargetFrameworkIdentifier")); Assert.AreEqual("Windows,Version=7.0", taskItem.GetMetadata("TargetPlatformMoniker")); Assert.AreEqual(RepoRoot + @"\src\HelloWorld\bin\x64\Release\HelloWorld.csproj.CopyComplete", taskItem.GetMetadata("CopyUpToDateMarker")); diff --git a/src/Common.Tests/PathHelperTests.cs b/src/Common.Tests/PathHelperTests.cs index bf4c008..e5f4601 100644 --- a/src/Common.Tests/PathHelperTests.cs +++ b/src/Common.Tests/PathHelperTests.cs @@ -8,7 +8,7 @@ namespace Microsoft.MSBuildCache.Tests; [TestClass] public class PathHelperTests { - [DataTestMethod] + [TestMethod] [DataRow(@"X:\A\B\C", @"X:\A", @"B\C")] // Lots of .. and . [DataRow(@"X:\Z\..\A\B\.\C", @"X:\Y\..\D\..\A\.\.", @"B\C")] @@ -27,7 +27,7 @@ public class PathHelperTests public void MakePathRelative(string path, string basePath, string? expectedResult) => Assert.AreEqual(expectedResult, path.MakePathRelativeTo(basePath)); - [DataTestMethod] + [TestMethod] [DataRow(@"X:\A\B\C\file.txt", @"X:\A", true)] // Lots of .. and . [DataRow(@"X:\Z\..\A\B\.\C\file.txt", @"X:\Y\..\D\..\A\.\.", true)] diff --git a/src/Common.Tests/PluginInterfaceTypeCheckTests.cs b/src/Common.Tests/PluginInterfaceTypeCheckTests.cs index 2f5ff17..e68e43b 100644 --- a/src/Common.Tests/PluginInterfaceTypeCheckTests.cs +++ b/src/Common.Tests/PluginInterfaceTypeCheckTests.cs @@ -39,15 +39,15 @@ public void ProjectCachePluginBase() private static void AssertAssembly(Type t) { - Assert.IsTrue(PluginInterfaceAssemblies.Contains(Path.GetFileName(t.Assembly.Location)), - $"Type {t.FullName} is in assembly {t.Assembly.Location} which is not expected"); + Assert.Contains(Path.GetFileName(t.Assembly.Location), +PluginInterfaceAssemblies, $"Type {t.FullName} is in assembly {t.Assembly.Location} which is not expected"); } private static void CheckAssembliesForType(Type t) { var alreadyChecked = new HashSet(); CheckAssemblies(t, alreadyChecked, 5); - Assert.IsTrue(alreadyChecked.Count > 10, "Failed to find types."); + Assert.IsGreaterThan(10, alreadyChecked.Count, "Failed to find types."); } private static void CheckAssemblies(Type t, HashSet alreadyChecked, int depth) diff --git a/src/Common.Tests/PluginSettingsExtensibilityTests.cs b/src/Common.Tests/PluginSettingsExtensibilityTests.cs index 0d3cfde..5887045 100644 --- a/src/Common.Tests/PluginSettingsExtensibilityTests.cs +++ b/src/Common.Tests/PluginSettingsExtensibilityTests.cs @@ -25,7 +25,7 @@ public void EffectiveSettingsLogging() MockPluginLogger logger = new(); _ = PluginSettings.Create(settings, logger, RepoRoot); - Assert.AreEqual(1, logger.LogEntries.Count); + Assert.HasCount(1, logger.LogEntries); // Ensure effective value of all properties are logged and that all properties are correctly defined. foreach (PropertyInfo property in typeof(MockPluginSettings).GetProperties()) @@ -202,7 +202,7 @@ public void ExplicitValues() Assert.AreEqual(MockEnum.C, pluginSettings.EnumSetting); - Assert.AreEqual(false, pluginSettings.BoolSetting); + Assert.IsFalse(pluginSettings.BoolSetting); Assert.AreEqual((byte)2, pluginSettings.ByteSetting); Assert.AreEqual((sbyte)2, pluginSettings.SbyteSetting); Assert.AreEqual('B', pluginSettings.CharSetting); diff --git a/src/Common.Tests/PluginSettingsTests.cs b/src/Common.Tests/PluginSettingsTests.cs index 3606e7f..d7024fa 100644 --- a/src/Common.Tests/PluginSettingsTests.cs +++ b/src/Common.Tests/PluginSettingsTests.cs @@ -25,7 +25,7 @@ public void EffectiveSettingsLogging() MockPluginLogger logger = new(); _ = PluginSettings.Create(settings, logger, RepoRoot); - Assert.AreEqual(1, logger.LogEntries.Count); + Assert.HasCount(1, logger.LogEntries); PluginLogEntry effectiveSettingsLogEntry = logger.LogEntries[0]; Assert.AreEqual(PluginLogLevel.Message, effectiveSettingsLogEntry.LogLevel); diff --git a/src/Common.Tests/SourceControl/GitFileHashProviderTest.cs b/src/Common.Tests/SourceControl/GitFileHashProviderTest.cs index 09e3955..30798bc 100644 Binary files a/src/Common.Tests/SourceControl/GitFileHashProviderTest.cs and b/src/Common.Tests/SourceControl/GitFileHashProviderTest.cs differ diff --git a/src/Repack.Tests/RepackTests.cs b/src/Repack.Tests/RepackTests.cs index b2e2504..4df3ea0 100644 --- a/src/Repack.Tests/RepackTests.cs +++ b/src/Repack.Tests/RepackTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.MSBuildCache.Repack.Tests; [TestClass] public class RepackTests { - [DataTestMethod] + [TestMethod] [DataRow(typeof(MSBuildCacheAzureBlobStoragePlugin))] [DataRow(typeof(MSBuildCacheAzurePipelinesPlugin))] [DataRow(typeof(MSBuildCacheLocalPlugin))] @@ -38,7 +38,7 @@ public void PluginInterfaceAssembliesNotMerged(Type typeToCheck) foreach (string expectedRefFileName in PluginInterfaceTypeCheckTests.PluginInterfaceNuGetAssemblies) { string expectedRef = Path.GetFileNameWithoutExtension(expectedRefFileName); - Assert.IsTrue(references.Contains(expectedRef)); + Assert.Contains(expectedRef, references); } } }