Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
</PropertyGroup>

<ItemGroup Condition="'$(TestProject)'=='true'">
<ItemGroup Condition="'$(IsTestingPlatformApplication)'=='true'">
<!-- https://github.com/microsoft/testfx/issues/4116 -->
<AssemblyAttribute Include="Microsoft.VisualStudio.TestTools.UnitTesting.Parallelize">

<_Parameter1>Workers = 0</_Parameter1>
<_Parameter1_IsLiteral>true</_Parameter1_IsLiteral>
<_Parameter2>Scope = Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope.MethodLevel</_Parameter2>
Expand Down
2 changes: 2 additions & 0 deletions dotnet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[dotnet.test.runner]
name = "Microsoft.Testing.Platform"
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"msbuild-sdks": {
"MSTest.Sdk": "3.9.1"
"MSTest.Sdk": "4.0.1"
}
}
4 changes: 2 additions & 2 deletions src/Common.Tests/Hashing/DirectoryFileHasherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/Common.Tests/Hashing/OutputHasherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task ComputeHashFileNotFound()
string file = Path.Combine(dir, "file.txt");

// Ensure exceptions are propagated correctly.
await Assert.ThrowsExceptionAsync<FileNotFoundException>(async () => await hasher.ComputeHashAsync(file, CancellationToken.None));
await Assert.ThrowsExactlyAsync<FileNotFoundException>(async () => await hasher.ComputeHashAsync(file, CancellationToken.None));
}

[TestMethod]
Expand Down
10 changes: 5 additions & 5 deletions src/Common.Tests/HexUtilitiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -26,15 +26,15 @@ public void HexToBytes(string hex, byte[]? expectedBytes)

expectedBytes ??= Array.Empty<byte>();

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<ArgumentException>(() => HexUtilities.HexToBytes("fAbCd"));
public void HexToBytesOddChars() => Assert.ThrowsExactly<ArgumentException>(() => HexUtilities.HexToBytes("fAbCd"));

[TestMethod]
public void HexToBytesBadChars()
Expand Down Expand Up @@ -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));
}
}
4 changes: 2 additions & 2 deletions src/Common.Tests/NodeTargetResultTaskItemTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand Down Expand Up @@ -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"));
Expand Down
4 changes: 2 additions & 2 deletions src/Common.Tests/PathHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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)]
Expand Down
6 changes: 3 additions & 3 deletions src/Common.Tests/PluginInterfaceTypeCheckTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type>();
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<Type> alreadyChecked, int depth)
Expand Down
4 changes: 2 additions & 2 deletions src/Common.Tests/PluginSettingsExtensibilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void EffectiveSettingsLogging()
MockPluginLogger logger = new();
_ = PluginSettings.Create<MockPluginSettings>(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())
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Common.Tests/PluginSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void EffectiveSettingsLogging()
MockPluginLogger logger = new();
_ = PluginSettings.Create<PluginSettings>(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);
Expand Down
Binary file modified src/Common.Tests/SourceControl/GitFileHashProviderTest.cs
Binary file not shown.
4 changes: 2 additions & 2 deletions src/Repack.Tests/RepackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.MSBuildCache.Repack.Tests;
[TestClass]
public class RepackTests
{
[DataTestMethod]
[TestMethod]
[DataRow(typeof(MSBuildCacheAzureBlobStoragePlugin))]
[DataRow(typeof(MSBuildCacheAzurePipelinesPlugin))]
[DataRow(typeof(MSBuildCacheLocalPlugin))]
Expand All @@ -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);
}
}
}