From 72de02fd983c6d6d2e4369a0b9c6e12556034fab Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Wed, 1 Apr 2026 17:49:30 +0200 Subject: [PATCH 1/3] Update Mono.Linker.Tests to MSTest --- .../test/Mono.Linker.Tests/AssemblyInfo.cs | 6 +- .../Mono.Linker.Tests.csproj | 3 +- .../TestCases/IndividualTests.cs | 71 +++--- .../TestCases/TestDatabase.cs | 205 +++++++++--------- .../Mono.Linker.Tests/TestCases/TestSuites.cs | 149 ++++++++----- .../TestCasesRunner/AssemblyChecker.cs | 2 +- .../TestCasesRunner/ILCompiler.cs | 2 +- .../ILVerification/ILChecker.cs | 2 +- .../ILVerification/ILVerifier.cs | 2 +- .../MemberAssertionsCollector.cs | 9 +- .../TestCasesRunner/ResultChecker.cs | 27 ++- .../TestCasesRunner/TestCaseCollector.cs | 2 +- .../TestCasesRunner/TestCaseCompiler.cs | 2 +- .../TestCasesRunner/TestRunner.cs | 9 +- .../Tests/AnnotationStoreTest.cs | 7 +- .../Tests/CodeOptimizationsSettingsTests.cs | 50 ++--- .../DocumentationSignatureParserTests.cs | 15 +- .../Tests/GetDisplayNameTests.cs | 18 +- .../Tests/MessageContainerTests.cs | 6 +- .../Tests/ParseResponseFileLinesTests.cs | 38 ++-- .../Tests/PreserveActionComparisonTests.cs | 39 ++-- .../Tests/TestFrameworkRulesAndConventions.cs | 12 +- .../Trimming.Tests.Shared/TestCaseSandbox.cs | 2 +- 23 files changed, 366 insertions(+), 312 deletions(-) diff --git a/src/tools/illink/test/Mono.Linker.Tests/AssemblyInfo.cs b/src/tools/illink/test/Mono.Linker.Tests/AssemblyInfo.cs index 695b33bcda67d8..c82a5fe452ee70 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/AssemblyInfo.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/AssemblyInfo.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using NUnit.Framework; +using Microsoft.VisualStudio.TestTools.UnitTesting; -[assembly: Parallelizable(ParallelScope.All)] +using ExecutionScope = Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope; + +[assembly: Parallelize(Scope = ExecutionScope.MethodLevel, Workers = 0)] diff --git a/src/tools/illink/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj b/src/tools/illink/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj index a9e38faf5d09b5..6acda1d8aa28dd 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj +++ b/src/tools/illink/test/Mono.Linker.Tests/Mono.Linker.Tests.csproj @@ -2,8 +2,7 @@ true - - NUnit + MSTest diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCases/IndividualTests.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCases/IndividualTests.cs index 7ab1fb7522446e..cbe4d2efd0a70b 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCases/IndividualTests.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCases/IndividualTests.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Runtime.Serialization.Json; using System.Xml; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Cecil; using Mono.Linker.Tests.Cases.CommandLine.Mvid; using Mono.Linker.Tests.Cases.CommandLine.Mvid.Individual; @@ -16,16 +17,15 @@ using Mono.Linker.Tests.Cases.Warnings.Individual; using Mono.Linker.Tests.Extensions; using Mono.Linker.Tests.TestCasesRunner; -using NUnit.Framework; namespace Mono.Linker.Tests.TestCases { - [TestFixture] + [TestClass] public class IndividualTests { private static NPath TestsDirectory => TestDatabase.TestCasesRootDirectory.Parent.Combine("Mono.Linker.Tests"); - [Test] + [TestMethod] public void CanSkipUnresolved() { var testcase = CreateIndividualCase(typeof(CanSkipUnresolved)); @@ -38,7 +38,7 @@ public void CanSkipUnresolved() Assert.Fail($"The linked assembly is missing. Should have existed at {result.OutputAssemblyPath}"); } - [Test] + [TestMethod] public void CanOutputPInvokes() { var testcase = CreateIndividualCase(typeof(CanOutputPInvokes)); @@ -57,12 +57,12 @@ public void CanOutputPInvokes() var expected = jsonSerializer.ReadObject(fsExpected) as List; foreach (var pinvokePair in Enumerable.Zip(actual, expected, (fst, snd) => Tuple.Create(fst, snd))) { - Assert.That(pinvokePair.Item1.CompareTo(pinvokePair.Item2), Is.EqualTo(0)); + Assert.AreEqual(0, pinvokePair.Item1.CompareTo(pinvokePair.Item2)); } } } - [Test] + [TestMethod] public void CanGenerateWarningSuppressionFileCSharp() { var testcase = CreateIndividualCase(typeof(CanGenerateWarningSuppressionFileCSharp)); @@ -75,12 +75,13 @@ public void CanGenerateWarningSuppressionFileCSharp() if (!outputPath.Exists()) Assert.Fail($"A cs file with a list of UnconditionalSuppressMessage attributes was expected to exist at {outputPath}"); - Assert.That(File.ReadAllLines(outputPath), Is.EquivalentTo( - File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/WarningSuppressionExpectations{i + 1}.cs")))); + CollectionAssert.AreEquivalent( + File.ReadAllLines(outputPath), + File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/WarningSuppressionExpectations{i + 1}.cs"))); } } - [Test] + [TestMethod] public void CanGenerateWarningSuppressionFileXml() { var testcase = CreateIndividualCase(typeof(CanGenerateWarningSuppressionFileXml)); @@ -89,11 +90,12 @@ public void CanGenerateWarningSuppressionFileXml() if (!outputPath.Exists()) Assert.Fail($"An XML file with a list of UnconditionalSuppressMessage attributes was expected to exist at {outputPath}"); - Assert.That(File.ReadAllLines(outputPath), Is.EquivalentTo( - File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/WarningSuppressionExpectations3.xml")))); + CollectionAssert.AreEquivalent( + File.ReadAllLines(outputPath), + File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/WarningSuppressionExpectations3.xml"))); } - [Test] + [TestMethod] public void WarningsAreSorted() { var testcase = CreateIndividualCase(typeof(WarningsAreSorted)); @@ -102,11 +104,12 @@ public void WarningsAreSorted() .Where(lm => lm.Category != MessageCategory.Info && lm.Category != MessageCategory.Diagnostic).ToList(); loggedMessages.Sort(); - Assert.That(loggedMessages.Select(m => m.ToString()), Is.EquivalentTo( - File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/SortedWarnings.txt")))); + CollectionAssert.AreEquivalent( + loggedMessages.Select(m => m.ToString()).ToArray(), + File.ReadAllLines(TestsDirectory.Combine($"TestCases/Dependencies/SortedWarnings.txt"))); } - [Test] + [TestMethod] public void InvalidWarningCodeThrows() { var testcase = CreateIndividualCase(typeof(CustomStepWithWarnings)); @@ -121,7 +124,7 @@ public void InvalidWarningCodeThrows() } } - [Test] + [TestMethod] public void CanEnableDependenciesDump() { var testcase = CreateIndividualCase(typeof(CanEnableDependenciesDump)); @@ -132,7 +135,7 @@ public void CanEnableDependenciesDump() Assert.Fail($"The dependency dump file is missing. Expected it to exist at {outputPath}"); } - [Test] + [TestMethod] public void CanDumpDependenciesToUncompressedXml() { var testcase = CreateIndividualCase(typeof(CanDumpDependenciesToUncompressedXml)); @@ -148,11 +151,11 @@ public void CanDumpDependenciesToUncompressedXml() reader.Read(); reader.Read(); reader.Read(); - Assert.That(reader.Name, Is.EqualTo("dependencies"), $"Expected to be at the dependencies element, but the current node name is `{reader.Name}`"); + Assert.AreEqual("dependencies", reader.Name, $"Expected to be at the dependencies element, but the current node name is `{reader.Name}`"); } } - [Test] + [TestMethod] public void CandumpDependenciesToUncompressedDgml() { var testcase = CreateIndividualCase(typeof(CanDumpDependenciesToUncompressedDgml)); @@ -167,11 +170,11 @@ public void CandumpDependenciesToUncompressedDgml() reader.Read(); reader.Read(); reader.Read(); - Assert.That(reader.Name, Is.EqualTo("DirectedGraph"), $"Expected to be at the DirectedGraph element, but the current node name is `{reader.Name}`"); + Assert.AreEqual("DirectedGraph", reader.Name, $"Expected to be at the DirectedGraph element, but the current node name is `{reader.Name}`"); } } - [Test] + [TestMethod] public void CanEnableReducedTracing() { var testcase = CreateIndividualCase(typeof(CanEnableReducedTracing)); @@ -192,10 +195,10 @@ public void CanEnableReducedTracing() // With reduced tracing there should be less than 65, but to be safe, we'll check for less than 200. // Reduced tracing on System.Private.CoreLib.dll produces about 130 lines just for NullableAttribute usages. const int expectedMaxLines = 200; - Assert.That(lineCount, Is.LessThan(expectedMaxLines), $"There were `{lineCount}` lines in the dump file. This is more than expected max of {expectedMaxLines} and likely indicates reduced tracing was not enabled. Dump file can be found at: {outputPath}"); + Assert.IsLessThan(expectedMaxLines, lineCount, $"There were `{lineCount}` lines in the dump file. This is more than expected max of {expectedMaxLines} and likely indicates reduced tracing was not enabled. Dump file can be found at: {outputPath}"); } - [Test] + [TestMethod] public void DeterministicMvidWorks() { var testCase = CreateIndividualCase(typeof(DeterministicMvidWorks)); @@ -204,17 +207,17 @@ public void DeterministicMvidWorks() var originalMvid = GetMvid(result.InputAssemblyPath); var firstOutputMvid = GetMvid(result.OutputAssemblyPath); - Assert.That(firstOutputMvid, Is.Not.EqualTo(originalMvid)); + Assert.AreNotEqual(firstOutputMvid, originalMvid); var result2 = runner.Relink(result); var secondOutputMvid = GetMvid(result2.OutputAssemblyPath); - Assert.That(secondOutputMvid, Is.Not.EqualTo(originalMvid)); + Assert.AreNotEqual(secondOutputMvid, originalMvid); // The id should match the first output since we relinked the same assembly - Assert.That(secondOutputMvid, Is.EqualTo(firstOutputMvid)); + Assert.AreEqual(secondOutputMvid, firstOutputMvid); } - [Test] + [TestMethod] public void NewMvidWorks() { var testCase = CreateIndividualCase(typeof(NewMvidWorks)); @@ -223,16 +226,16 @@ public void NewMvidWorks() var originalMvid = GetMvid(result.InputAssemblyPath); var firstOutputMvid = GetMvid(result.OutputAssemblyPath); - Assert.That(firstOutputMvid, Is.Not.EqualTo(originalMvid)); + Assert.AreNotEqual(firstOutputMvid, originalMvid); var result2 = runner.Relink(result); var secondOutputMvid = GetMvid(result2.OutputAssemblyPath); - Assert.That(secondOutputMvid, Is.Not.EqualTo(originalMvid)); - Assert.That(secondOutputMvid, Is.Not.EqualTo(firstOutputMvid)); + Assert.AreNotEqual(secondOutputMvid, originalMvid); + Assert.AreNotEqual(secondOutputMvid, firstOutputMvid); } - [Test] + [TestMethod] public void RetainMvidWorks() { var testCase = CreateIndividualCase(typeof(RetainMvid)); @@ -241,13 +244,13 @@ public void RetainMvidWorks() var originalMvid = GetMvid(result.InputAssemblyPath); var firstOutputMvid = GetMvid(result.OutputAssemblyPath); - Assert.That(firstOutputMvid, Is.EqualTo(originalMvid)); + Assert.AreEqual(firstOutputMvid, originalMvid); var result2 = runner.Relink(result); var secondOutputMvid = GetMvid(result2.OutputAssemblyPath); - Assert.That(secondOutputMvid, Is.EqualTo(originalMvid)); - Assert.That(secondOutputMvid, Is.EqualTo(firstOutputMvid)); + Assert.AreEqual(secondOutputMvid, originalMvid); + Assert.AreEqual(secondOutputMvid, firstOutputMvid); } protected static Guid GetMvid(NPath assemblyPath) diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCases/TestDatabase.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCases/TestDatabase.cs index 3e005cdb830798..8bd5dab6a5d28f 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCases/TestDatabase.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCases/TestDatabase.cs @@ -4,9 +4,9 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Linker.Tests.Extensions; using Mono.Linker.Tests.TestCasesRunner; -using NUnit.Framework; namespace Mono.Linker.Tests.TestCases { @@ -14,239 +14,239 @@ public static class TestDatabase { private static TestCase[] _cachedAllCases; - public static IEnumerable AdvancedTests() + public static IEnumerable> AdvancedTests() { - return NUnitCasesBySuiteName("Advanced"); + return MSTestCasesBySuiteName("Advanced"); } - public static IEnumerable AttributeDebuggerTests() + public static IEnumerable> AttributeDebuggerTests() { - return NUnitCasesBySuiteName("Attributes.Debugger"); + return MSTestCasesBySuiteName("Attributes.Debugger"); } - public static IEnumerable AttributeTests() + public static IEnumerable> AttributeTests() { - return NUnitCasesBySuiteName("Attributes"); + return MSTestCasesBySuiteName("Attributes"); } - public static IEnumerable AttributesStructLayoutTests() + public static IEnumerable> AttributesStructLayoutTests() { - return NUnitCasesBySuiteName("Attributes.StructLayout"); + return MSTestCasesBySuiteName("Attributes.StructLayout"); } - public static IEnumerable BCLFeaturesTests() + public static IEnumerable> BCLFeaturesTests() { - return NUnitCasesBySuiteName("BCLFeatures"); + return MSTestCasesBySuiteName("BCLFeatures"); } - public static IEnumerable BasicTests() + public static IEnumerable> BasicTests() { - return NUnitCasesBySuiteName("Basic"); + return MSTestCasesBySuiteName("Basic"); } - public static IEnumerable CodegenAnnotationTests() + public static IEnumerable> CodegenAnnotationTests() { - return NUnitCasesBySuiteName("CodegenAnnotation"); + return MSTestCasesBySuiteName("CodegenAnnotation"); } - public static IEnumerable CommandLineTests() + public static IEnumerable> CommandLineTests() { - return NUnitCasesBySuiteName("CommandLine"); + return MSTestCasesBySuiteName("CommandLine"); } - public static IEnumerable ComponentModelTests() + public static IEnumerable> ComponentModelTests() { - return NUnitCasesBySuiteName("ComponentModel"); + return MSTestCasesBySuiteName("ComponentModel"); } - public static IEnumerable CoreLinkTests() + public static IEnumerable> CoreLinkTests() { - return NUnitCasesBySuiteName("CoreLink"); + return MSTestCasesBySuiteName("CoreLink"); } - public static IEnumerable CppCLITests() + public static IEnumerable> CppCLITests() { - return NUnitCasesBySuiteName("CppCLI"); + return MSTestCasesBySuiteName("CppCLI"); } - public static IEnumerable DataFlowTests() + public static IEnumerable> DataFlowTests() { - return NUnitCasesBySuiteName("DataFlow"); + return MSTestCasesBySuiteName("DataFlow"); } - public static IEnumerable DynamicDependenciesTests() + public static IEnumerable> DynamicDependenciesTests() { - return NUnitCasesBySuiteName("DynamicDependencies"); + return MSTestCasesBySuiteName("DynamicDependencies"); } - public static IEnumerable ExtensibilityTests() + public static IEnumerable> ExtensibilityTests() { - return NUnitCasesBySuiteName("Extensibility"); + return MSTestCasesBySuiteName("Extensibility"); } - public static IEnumerable FeatureSettingsTests() + public static IEnumerable> FeatureSettingsTests() { - return NUnitCasesBySuiteName("FeatureSettings"); + return MSTestCasesBySuiteName("FeatureSettings"); } - public static IEnumerable FunctionPointersTests() + public static IEnumerable> FunctionPointersTests() { - return NUnitCasesBySuiteName("FunctionPointers"); + return MSTestCasesBySuiteName("FunctionPointers"); } - public static IEnumerable GenericsTests() + public static IEnumerable> GenericsTests() { - return NUnitCasesBySuiteName("Generics"); + return MSTestCasesBySuiteName("Generics"); } - public static IEnumerable InheritanceAbstractClassTests() + public static IEnumerable> InheritanceAbstractClassTests() { - return NUnitCasesBySuiteName("Inheritance.AbstractClasses"); + return MSTestCasesBySuiteName("Inheritance.AbstractClasses"); } - public static IEnumerable InheritanceComplexTests() + public static IEnumerable> InheritanceComplexTests() { - return NUnitCasesBySuiteName("Inheritance.Complex"); + return MSTestCasesBySuiteName("Inheritance.Complex"); } - public static IEnumerable InheritanceInterfaceTests() + public static IEnumerable> InheritanceInterfaceTests() { - return NUnitCasesBySuiteName("Inheritance.Interfaces"); + return MSTestCasesBySuiteName("Inheritance.Interfaces"); } - public static IEnumerable InheritanceVirtualMethodsTests() + public static IEnumerable> InheritanceVirtualMethodsTests() { - return NUnitCasesBySuiteName("Inheritance.VirtualMethods"); + return MSTestCasesBySuiteName("Inheritance.VirtualMethods"); } - public static IEnumerable InlineArrayTests() + public static IEnumerable> InlineArrayTests() { - return NUnitCasesBySuiteName("InlineArrays"); + return MSTestCasesBySuiteName("InlineArrays"); } - public static IEnumerable InteropTests() + public static IEnumerable> InteropTests() { - return NUnitCasesBySuiteName("Interop"); + return MSTestCasesBySuiteName("Interop"); } - public static IEnumerable LibrariesTests() + public static IEnumerable> LibrariesTests() { - return NUnitCasesBySuiteName("Libraries"); + return MSTestCasesBySuiteName("Libraries"); } - public static IEnumerable LinkAttributesTests() + public static IEnumerable> LinkAttributesTests() { - return NUnitCasesBySuiteName("LinkAttributes"); + return MSTestCasesBySuiteName("LinkAttributes"); } - public static IEnumerable LoggingTests() + public static IEnumerable> LoggingTests() { - return NUnitCasesBySuiteName("Logging"); + return MSTestCasesBySuiteName("Logging"); } - public static IEnumerable PreserveDependenciesTests() + public static IEnumerable> PreserveDependenciesTests() { - return NUnitCasesBySuiteName("PreserveDependencies"); + return MSTestCasesBySuiteName("PreserveDependencies"); } - public static IEnumerable ReferencesTests() + public static IEnumerable> ReferencesTests() { - return NUnitCasesBySuiteName("References"); + return MSTestCasesBySuiteName("References"); } - public static IEnumerable ReflectionTests() + public static IEnumerable> ReflectionTests() { - return NUnitCasesBySuiteName("Reflection"); + return MSTestCasesBySuiteName("Reflection"); } - public static IEnumerable RequiresCapabilityTests() + public static IEnumerable> RequiresCapabilityTests() { - return NUnitCasesBySuiteName("RequiresCapability"); + return MSTestCasesBySuiteName("RequiresCapability"); } - public static IEnumerable ResourcesTests() + public static IEnumerable> ResourcesTests() { - return NUnitCasesBySuiteName("Resources"); + return MSTestCasesBySuiteName("Resources"); } - public static IEnumerable SealerTests() + public static IEnumerable> SealerTests() { - return NUnitCasesBySuiteName("Sealer"); + return MSTestCasesBySuiteName("Sealer"); } - public static IEnumerable SerializationTests() + public static IEnumerable> SerializationTests() { - return NUnitCasesBySuiteName("Serialization"); + return MSTestCasesBySuiteName("Serialization"); } - public static IEnumerable SingleFileTests() + public static IEnumerable> SingleFileTests() { - return NUnitCasesBySuiteName("SingleFile"); + return MSTestCasesBySuiteName("SingleFile"); } - public static IEnumerable StaticsTests() + public static IEnumerable> StaticsTests() { - return NUnitCasesBySuiteName("Statics"); + return MSTestCasesBySuiteName("Statics"); } - public static IEnumerable SubstitutionsTests() + public static IEnumerable> SubstitutionsTests() { - return NUnitCasesBySuiteName("Substitutions"); + return MSTestCasesBySuiteName("Substitutions"); } - public static IEnumerable SymbolsTests() + public static IEnumerable> SymbolsTests() { - return NUnitCasesBySuiteName("Symbols"); + return MSTestCasesBySuiteName("Symbols"); } - public static IEnumerable TestFrameworkTests() + public static IEnumerable> TestFrameworkTests() { - return NUnitCasesBySuiteName("TestFramework"); + return MSTestCasesBySuiteName("TestFramework"); } - public static IEnumerable TopLevelStatementsTests() + public static IEnumerable> TopLevelStatementsTests() { - return NUnitCasesBySuiteName("TopLevelStatements"); + return MSTestCasesBySuiteName("TopLevelStatements"); } - public static IEnumerable TracingTests() + public static IEnumerable> TracingTests() { - return NUnitCasesBySuiteName("Tracing"); + return MSTestCasesBySuiteName("Tracing"); } - public static IEnumerable TypeForwardingTests() + public static IEnumerable> TypeForwardingTests() { - return NUnitCasesBySuiteName("TypeForwarding"); + return MSTestCasesBySuiteName("TypeForwarding"); } - public static IEnumerable UnreachableBlockTests() + public static IEnumerable> UnreachableBlockTests() { - return NUnitCasesBySuiteName("UnreachableBlock"); + return MSTestCasesBySuiteName("UnreachableBlock"); } - public static IEnumerable UnreachableBodyTests() + public static IEnumerable> UnreachableBodyTests() { - return NUnitCasesBySuiteName("UnreachableBody"); + return MSTestCasesBySuiteName("UnreachableBody"); } - public static IEnumerable WarningsTests() + public static IEnumerable> WarningsTests() { - return NUnitCasesBySuiteName("Warnings"); + return MSTestCasesBySuiteName("Warnings"); } - public static IEnumerable XmlTests() + public static IEnumerable> XmlTests() { - return NUnitCasesBySuiteName("LinkXml"); + return MSTestCasesBySuiteName("LinkXml"); } - public static IEnumerable LinqExpressionsTests() + public static IEnumerable> LinqExpressionsTests() { - return NUnitCasesBySuiteName("LinqExpressions"); + return MSTestCasesBySuiteName("LinqExpressions"); } - public static IEnumerable MetadataTests() + public static IEnumerable> MetadataTests() { - return NUnitCasesBySuiteName("Metadata"); + return MSTestCasesBySuiteName("Metadata"); } public static TestCaseCollector CreateCollector() @@ -274,19 +274,20 @@ static IEnumerable AllCases() return _cachedAllCases; } - static IEnumerable NUnitCasesBySuiteName(string suiteName) + static IEnumerable> MSTestCasesBySuiteName(string suiteName) { return AllCases() .Where(c => c.TestSuiteDirectory.FileName == suiteName) - .Select(c => CreateNUnitTestCase(c, c.DisplayName)) - .OrderBy(c => c.TestName); + .Select(c => CreateMSTestTestCase(c, c.DisplayName)) + .OrderBy(c => c.DisplayName); } - static TestCaseData CreateNUnitTestCase(TestCase testCase, string displayName) + static TestDataRow CreateMSTestTestCase(TestCase testCase, string displayName) { - var data = new TestCaseData(testCase); - data.SetName(displayName); - return data; + return new TestDataRow(testCase) + { + DisplayName = displayName, + }; } static void GetDirectoryPaths(out string rootSourceDirectory, out string testCaseAssemblyRoot) diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCases/TestSuites.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCases/TestSuites.cs index 7d1aaf869a5c88..664ce77cb32d63 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCases/TestSuites.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCases/TestSuites.cs @@ -2,297 +2,344 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Linker.Tests.TestCasesRunner; -using NUnit.Framework; namespace Mono.Linker.Tests.TestCases { - [TestFixture] + [TestClass] public class All { - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.AdvancedTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.AdvancedTests), typeof(TestDatabase))] public void AdvancedTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.AttributeDebuggerTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.AttributeDebuggerTests), typeof(TestDatabase))] public void AttributesDebuggerTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.AttributesStructLayoutTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.AttributesStructLayoutTests), typeof(TestDatabase))] public void AttributesStructLayoutTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.AttributeTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.AttributeTests), typeof(TestDatabase))] public void AttributesTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.BCLFeaturesTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.BCLFeaturesTests), typeof(TestDatabase))] public void BCLFeaturesTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.BasicTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.BasicTests), typeof(TestDatabase))] public void BasicTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.CodegenAnnotationTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.CodegenAnnotationTests), typeof(TestDatabase))] public void CodegenAnnotationTests(TestCase testCase) { if (Environment.OSVersion.Platform == PlatformID.Win32NT) - Assert.Ignore("These tests are not valid when trimming .NET Framework"); + Assert.Inconclusive("These tests are not valid when trimming .NET Framework"); #if NET - Assert.Ignore("These tests are not valid when trimming .NET Core"); + Assert.Inconclusive("These tests are not valid when trimming .NET Core"); #endif Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.CommandLineTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.CommandLineTests), typeof(TestDatabase))] public void CommandLineTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.ComponentModelTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.ComponentModelTests), typeof(TestDatabase))] public void ComponentModelTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.CoreLinkTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.CoreLinkTests), typeof(TestDatabase))] public void CoreLinkTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.CppCLITests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.CppCLITests), typeof(TestDatabase))] public void CppCLITests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.DataFlowTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.DataFlowTests), typeof(TestDatabase))] public void DataFlowTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.DynamicDependenciesTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.DynamicDependenciesTests), typeof(TestDatabase))] public void DynamicDependenciesTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.ExtensibilityTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.ExtensibilityTests), typeof(TestDatabase))] public void ExtensibilityTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.FeatureSettingsTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.FeatureSettingsTests), typeof(TestDatabase))] public void FeatureSettingsTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.FunctionPointersTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.FunctionPointersTests), typeof(TestDatabase))] public void FunctionPointerTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.GenericsTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.GenericsTests), typeof(TestDatabase))] public void GenericsTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.InheritanceAbstractClassTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.InheritanceAbstractClassTests), typeof(TestDatabase))] public void InheritanceAbstractClassTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.InheritanceComplexTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.InheritanceComplexTests), typeof(TestDatabase))] public void InheritanceComplexTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.InheritanceInterfaceTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.InheritanceInterfaceTests), typeof(TestDatabase))] public void InheritanceInterfaceTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.InheritanceVirtualMethodsTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.InheritanceVirtualMethodsTests), typeof(TestDatabase))] public void InheritanceVirtualMethodsTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.InlineArrayTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.InlineArrayTests), typeof(TestDatabase))] public void InlineArrayTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.InteropTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.InteropTests), typeof(TestDatabase))] public void InteropTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.LibrariesTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.LibrariesTests), typeof(TestDatabase))] public void LibrariesTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.LinkAttributesTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.LinkAttributesTests), typeof(TestDatabase))] public void LinkAttributesTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.LoggingTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.LoggingTests), typeof(TestDatabase))] public void LoggingTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.PreserveDependenciesTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.PreserveDependenciesTests), typeof(TestDatabase))] public void PreserveDependenciesTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.ReferencesTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.ReferencesTests), typeof(TestDatabase))] public void ReferencesTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.ReflectionTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.ReflectionTests), typeof(TestDatabase))] public void ReflectionTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.RequiresCapabilityTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.RequiresCapabilityTests), typeof(TestDatabase))] public void RequiresCapabilityTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.ResourcesTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.ResourcesTests), typeof(TestDatabase))] public void ResourcesTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.SealerTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.SealerTests), typeof(TestDatabase))] public void SealerTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.SerializationTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.SerializationTests), typeof(TestDatabase))] public void SerializationTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.SingleFileTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.SingleFileTests), typeof(TestDatabase))] public void SingleFileTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.StaticsTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.StaticsTests), typeof(TestDatabase))] public void StaticsTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.SubstitutionsTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.SubstitutionsTests), typeof(TestDatabase))] public void SubstitutionsTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.SymbolsTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.SymbolsTests), typeof(TestDatabase))] public void SymbolsTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.TestFrameworkTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.TestFrameworkTests), typeof(TestDatabase))] public void TestFrameworkTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.TopLevelStatementsTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.TopLevelStatementsTests), typeof(TestDatabase))] public void TopLevelStatementsTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.TracingTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.TracingTests), typeof(TestDatabase))] public void TracingTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.TypeForwardingTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.TypeForwardingTests), typeof(TestDatabase))] public void TypeForwardingTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.UnreachableBlockTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.UnreachableBlockTests), typeof(TestDatabase))] public void UnreachableBlockTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.UnreachableBodyTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.UnreachableBodyTests), typeof(TestDatabase))] public void UnreachableBodyTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.WarningsTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.WarningsTests), typeof(TestDatabase))] public void WarningsTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.XmlTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.XmlTests), typeof(TestDatabase))] public void XmlTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.LinqExpressionsTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.LinqExpressionsTests), typeof(TestDatabase))] public void LinqExpressionsTests(TestCase testCase) { Run(testCase); } - [TestCaseSource(typeof(TestDatabase), nameof(TestDatabase.MetadataTests))] + [TestMethod] + [DynamicData(nameof(TestDatabase.MetadataTests), typeof(TestDatabase))] public void MetadataTests(TestCase testCase) { Run(testCase); diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs index 28efa01c1d88a0..e6dd87c35fb081 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/AssemblyChecker.cs @@ -7,11 +7,11 @@ using System.Globalization; using System.Linq; using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Extensions; -using NUnit.Framework; namespace Mono.Linker.Tests.TestCasesRunner { diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILCompiler.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILCompiler.cs index 84760a8cf5d8fa..56490ad00c766b 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILCompiler.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILCompiler.cs @@ -8,8 +8,8 @@ using System.Linq; using System.Runtime.InteropServices; using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Linker.Tests.Extensions; -using NUnit.Framework; namespace Mono.Linker.Tests.TestCasesRunner { diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerification/ILChecker.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerification/ILChecker.cs index 06f6ee523feabb..8d6e56e13bd819 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerification/ILChecker.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerification/ILChecker.cs @@ -6,10 +6,10 @@ using System.Linq; using System.Text; using ILVerify; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Cecil; using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Extensions; -using NUnit.Framework; namespace Mono.Linker.Tests.TestCasesRunner.ILVerification; diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerification/ILVerifier.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerification/ILVerifier.cs index 34cac32c7eaf38..058990bc51671c 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerification/ILVerifier.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ILVerification/ILVerifier.cs @@ -10,8 +10,8 @@ using System.Reflection.Metadata; using System.Reflection.PortableExecutable; using ILVerify; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Linker.Tests.Extensions; -using NUnit.Framework; namespace Mono.Linker.Tests.TestCasesRunner.ILVerification; diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/MemberAssertionsCollector.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/MemberAssertionsCollector.cs index 74a2b592823d3a..cca468e8ed8d11 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/MemberAssertionsCollector.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/MemberAssertionsCollector.cs @@ -6,9 +6,9 @@ using System.IO; using System.Linq; using Mono.Cecil; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.Extensions; -using NUnit.Framework; namespace Mono.Linker.Tests.TestCasesRunner { @@ -27,14 +27,11 @@ public static class MemberAssertionsCollector return results; } - public static IEnumerable GetMemberAssertionsData(Type type) + public static IEnumerable> GetMemberAssertionsData(Type type) { return GetMemberAssertions(type).Select(v => { - var testCaseData = new TestCaseData(v.member, v.ca); - // Sanitize test names to work around https://github.com/nunit/nunit3-vs-adapter/issues/691. - testCaseData.SetName($"{{m}}({v.member.Name},{v.ca.AttributeType.Name})"); - return testCaseData; + return new TestDataRow<(IMemberDefinition, CustomAttribute)>(v.member, v.ca); }); } diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs index c185f0654e9b15..50cc7f96c7a69d 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs @@ -12,6 +12,7 @@ using System.Text; using System.Text.RegularExpressions; using ILLink.Shared.TrimAnalysis; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Linker; @@ -20,7 +21,6 @@ using Mono.Linker.Tests.Cases.Expectations.Metadata; using Mono.Linker.Tests.Extensions; using Mono.Linker.Tests.TestCasesRunner.ILVerification; -using NUnit.Framework; namespace Mono.Linker.Tests.TestCasesRunner { @@ -427,7 +427,7 @@ void VerifyLinkingOfOtherAssemblies(AssemblyDefinition original) break; case nameof(RemovedAssemblyReferenceAttribute): - Assert.False(linkedAssembly.MainModule.AssemblyReferences.Any(l => l.Name == expectedTypeName), + Assert.IsFalse(linkedAssembly.MainModule.AssemblyReferences.Any(l => l.Name == expectedTypeName), $"AssemblyRef '{expectedTypeName}' should have been removed from assembly {assemblyName}"); break; @@ -628,7 +628,7 @@ void VerifyKeptBaseOnTypeInAssembly(CustomAttribute inAssemblyAttribute, TypeDef if (originalType.BaseType.Resolve() != originalBase) Assert.Fail("Invalid assertion. Original type's base does not match the expected base"); - Assert.That(originalBase.FullName, Is.EqualTo(linkedType.BaseType.FullName), + Assert.AreEqual(originalBase.FullName, linkedType.BaseType.FullName, $"Incorrect base on `{linkedType.FullName}`. Expected `{originalBase.FullName}` but was `{linkedType.BaseType.FullName}`"); } @@ -828,7 +828,9 @@ void VerifyKeptReferencesInAssembly(CustomAttribute inAssemblyAttribute) if (expectedReferenceNames[i].EndsWith(".dll")) expectedReferenceNames[i] = expectedReferenceNames[i].Substring(0, expectedReferenceNames[i].LastIndexOf(".")); - Assert.That(assembly.MainModule.AssemblyReferences.Select(asm => asm.Name), Is.EquivalentTo(expectedReferenceNames)); + CollectionAssert.AreEquivalent( + assembly.MainModule.AssemblyReferences.Select(asm => asm.Name).ToArray(), + expectedReferenceNames); } void VerifyKeptResourceInAssembly(CustomAttribute inAssemblyAttribute) @@ -836,7 +838,7 @@ void VerifyKeptResourceInAssembly(CustomAttribute inAssemblyAttribute) var assembly = ResolveLinkedAssembly(inAssemblyAttribute.ConstructorArguments[0].Value.ToString()); var resourceName = inAssemblyAttribute.ConstructorArguments[1].Value.ToString(); - Assert.That(assembly.MainModule.Resources.Select(r => r.Name), Has.Member(resourceName)); + Assert.Contains(resourceName, assembly.MainModule.Resources.Select(r => r.Name)); } void VerifyRemovedResourceInAssembly(CustomAttribute inAssemblyAttribute) @@ -844,7 +846,7 @@ void VerifyRemovedResourceInAssembly(CustomAttribute inAssemblyAttribute) var assembly = ResolveLinkedAssembly(inAssemblyAttribute.ConstructorArguments[0].Value.ToString()); var resourceName = inAssemblyAttribute.ConstructorArguments[1].Value.ToString(); - Assert.That(assembly.MainModule.Resources.Select(r => r.Name), Has.No.Member(resourceName)); + Assert.DoesNotContain(resourceName, assembly.MainModule.Resources.Select(r => r.Name)); } void VerifyKeptAllTypesAndMembersInAssembly(AssemblyDefinition linked) @@ -859,7 +861,7 @@ void VerifyKeptAllTypesAndMembersInAssembly(AssemblyDefinition linked) var missingInLinked = originalTypes.Keys.Except(linkedTypes.Keys); - Assert.That(missingInLinked, Is.Empty, $"Expected all types to exist in the linked assembly {linked.Name}, but one or more were missing"); + Assert.IsEmpty(missingInLinked, $"Expected all types to exist in the linked assembly {linked.Name}, but one or more were missing"); foreach (var originalKvp in originalTypes) { @@ -870,7 +872,7 @@ void VerifyKeptAllTypesAndMembersInAssembly(AssemblyDefinition linked) var missingMembersInLinked = originalMembers.Except(linkedMembers); - Assert.That(missingMembersInLinked, Is.Empty, $"Expected all members of `{originalKvp.Key}`to exist in the linked assembly, but one or more were missing"); + Assert.IsEmpty(missingMembersInLinked, $"Expected all members of `{originalKvp.Key}`to exist in the linked assembly, but one or more were missing"); } } @@ -1283,8 +1285,9 @@ void VerifyExpectedDependencyTrace(TestCaseMetadataProvider testCaseMetadata, NP var tracePath = outputAssemblyPath.Parent.Combine("linker-dependencies.xml"); Assert.IsTrue(tracePath.FileExists(), $"Dependency trace file '{tracePath}' does not exist."); - Assert.That(File.ReadAllLines(tracePath), Is.EquivalentTo( - File.ReadAllLines(expectedTracePath))); + CollectionAssert.AreEquivalent( + File.ReadAllLines(tracePath), + File.ReadAllLines(expectedTracePath)); } void VerifyExpectedInstructionSequenceOnMemberInAssembly(CustomAttribute inAssemblyAttribute, TypeDefinition linkedType) @@ -1299,9 +1302,9 @@ void VerifyExpectedInstructionSequenceOnMemberInAssembly(CustomAttribute inAssem var srcValues = valueCollector(originalMethod); var expected = ((CustomAttributeArgument[])inAssemblyAttribute.ConstructorArguments[3].Value)?.Select(arg => arg.Value.ToString()).ToArray(); - Assert.That( + CollectionAssert.AreEquivalent( linkedValues, - Is.EquivalentTo(expected), + expected, $"Expected method `{originalMethod} to have its {nameof(ExpectedInstructionSequenceOnMemberInAssemblyAttribute)} modified, however, the sequence does not match the expected value\n{FormattingUtils.FormatSequenceCompareFailureMessage2(linkedValues, expected, srcValues)}"); return; diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCollector.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCollector.cs index 7c21fc703594d0..a2f4bb5a842381 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCollector.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCollector.cs @@ -101,7 +101,7 @@ public IEnumerable AllSourceFiles() if (relativeParents.RecursiveParents.Any(p => p.Elements.Any() && p.FileName == "Dependencies")) continue; - // Magic: Anything in a directory named Individual is expected to be ran by it's own [Test] rather than as part of [TestCaseSource] + // Magic: Anything in a directory named Individual is expected to be ran by it's own [TestMethod] rather than as part of [DynamicData] if (relativeParents.RecursiveParents.Any(p => p.Elements.Any() && p.FileName == "Individual")) continue; diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs index 285fe2a37f6b26..6cea58e7e74c39 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseCompiler.cs @@ -6,8 +6,8 @@ using System.IO; using System.Linq; using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Linker.Tests.Extensions; -using NUnit.Framework; #if NET using System.Runtime.InteropServices; using Microsoft.CodeAnalysis; diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs index 1e45b9694c65e6..d0d1e14c9057a2 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestRunner.cs @@ -5,8 +5,8 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Linker.Tests.Extensions; -using NUnit.Framework; namespace Mono.Linker.Tests.TestCasesRunner { @@ -14,7 +14,7 @@ partial class TestRunner { partial void IgnoreTest(string reason) { - Assert.Ignore(reason); + Assert.Inconclusive(reason); } private partial IEnumerable? GetAdditionalDefines() => null; @@ -29,10 +29,7 @@ private static T GetResultOfTaskThatMakesAssertions(Task task) { if (e.InnerException != null) { - if (e.InnerException is AssertionException - || e.InnerException is SuccessException - || e.InnerException is IgnoreException - || e.InnerException is InconclusiveException) + if (e.InnerException is UnitTestAssertException) throw e.InnerException; } diff --git a/src/tools/illink/test/Mono.Linker.Tests/Tests/AnnotationStoreTest.cs b/src/tools/illink/test/Mono.Linker.Tests/Tests/AnnotationStoreTest.cs index 1d0c7d6bf57c63..e0948fac6bdcc8 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/Tests/AnnotationStoreTest.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/Tests/AnnotationStoreTest.cs @@ -1,23 +1,24 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Cecil; -using NUnit.Framework; namespace Mono.Linker.Tests.Tests { + [TestClass] public class AnnotationStoreTest { AnnotationStore store; - [SetUp] + [TestInitialize] public void Setup() { var ctx = new LinkContext(null, new ConsoleLogger(), string.Empty); store = new AnnotationStore(ctx); } - [Test] + [TestMethod] public void CustomAnnotations() { var td = new TypeDefinition("ns", "name", TypeAttributes.Public); diff --git a/src/tools/illink/test/Mono.Linker.Tests/Tests/CodeOptimizationsSettingsTests.cs b/src/tools/illink/test/Mono.Linker.Tests/Tests/CodeOptimizationsSettingsTests.cs index 4b01220d7b5f9b..3b16df3272679d 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/Tests/CodeOptimizationsSettingsTests.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/Tests/CodeOptimizationsSettingsTests.cs @@ -1,35 +1,35 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using NUnit.Framework; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Mono.Linker.Tests { - [TestFixture] + [TestClass] public class CodeOptimizationsSettingsTests { - [Test] + [TestMethod] public void GlobalSettingsOnly() { CodeOptimizationsSettings cos = new CodeOptimizationsSettings(CodeOptimizations.BeforeFieldInit); Assert.AreEqual(CodeOptimizations.BeforeFieldInit, cos.Global); - Assert.That(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "any")); - Assert.False(cos.IsEnabled(CodeOptimizations.Sealer, "any")); + Assert.IsTrue(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "any")); + Assert.IsFalse(cos.IsEnabled(CodeOptimizations.Sealer, "any")); } - [Test] + [TestMethod] public void OneAssemblyIsExcluded() { CodeOptimizationsSettings cos = new CodeOptimizationsSettings(CodeOptimizations.BeforeFieldInit); cos.Disable(CodeOptimizations.BeforeFieldInit, "testasm.dll"); Assert.AreEqual(CodeOptimizations.BeforeFieldInit, cos.Global); - Assert.That(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "any")); - Assert.False(cos.IsEnabled(CodeOptimizations.Sealer, "any")); - Assert.False(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "testasm.dll")); + Assert.IsTrue(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "any")); + Assert.IsFalse(cos.IsEnabled(CodeOptimizations.Sealer, "any")); + Assert.IsFalse(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "testasm.dll")); } - [Test] + [TestMethod] public void ExcludedThenIncluded() { CodeOptimizationsSettings cos = new CodeOptimizationsSettings(CodeOptimizations.BeforeFieldInit); @@ -37,38 +37,38 @@ public void ExcludedThenIncluded() cos.Enable(CodeOptimizations.OverrideRemoval | CodeOptimizations.BeforeFieldInit, "testasm.dll"); Assert.AreEqual(CodeOptimizations.BeforeFieldInit, cos.Global); - Assert.That(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "any")); - Assert.False(cos.IsEnabled(CodeOptimizations.OverrideRemoval, "any")); + Assert.IsTrue(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "any")); + Assert.IsFalse(cos.IsEnabled(CodeOptimizations.OverrideRemoval, "any")); - Assert.False(cos.IsEnabled(CodeOptimizations.Sealer, "any")); - Assert.That(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "testasm.dll")); + Assert.IsFalse(cos.IsEnabled(CodeOptimizations.Sealer, "any")); + Assert.IsTrue(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "testasm.dll")); } - [Test] + [TestMethod] public void OnlyOneOptIsDisabled() { CodeOptimizationsSettings cos = new CodeOptimizationsSettings(CodeOptimizations.OverrideRemoval); cos.Disable(CodeOptimizations.BeforeFieldInit, "testasm.dll"); - Assert.False(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "testasm.dll")); - Assert.False(cos.IsEnabled(CodeOptimizations.Sealer, "testasm.dll")); - Assert.False(cos.IsEnabled(CodeOptimizations.UnreachableBodies, "testasm.dll")); + Assert.IsFalse(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "testasm.dll")); + Assert.IsFalse(cos.IsEnabled(CodeOptimizations.Sealer, "testasm.dll")); + Assert.IsFalse(cos.IsEnabled(CodeOptimizations.UnreachableBodies, "testasm.dll")); } - [Test] + [TestMethod] public void PropagateFromGlobal() { CodeOptimizationsSettings cos = new CodeOptimizationsSettings(CodeOptimizations.BeforeFieldInit); cos.Disable(CodeOptimizations.IPConstantPropagation | CodeOptimizations.OverrideRemoval, "testasm.dll"); - Assert.False(cos.IsEnabled(CodeOptimizations.IPConstantPropagation, "testasm.dll")); - Assert.False(cos.IsEnabled(CodeOptimizations.IPConstantPropagation, "any")); + Assert.IsFalse(cos.IsEnabled(CodeOptimizations.IPConstantPropagation, "testasm.dll")); + Assert.IsFalse(cos.IsEnabled(CodeOptimizations.IPConstantPropagation, "any")); - Assert.False(cos.IsEnabled(CodeOptimizations.OverrideRemoval, "testasm.dll")); - Assert.False(cos.IsEnabled(CodeOptimizations.OverrideRemoval, "any")); + Assert.IsFalse(cos.IsEnabled(CodeOptimizations.OverrideRemoval, "testasm.dll")); + Assert.IsFalse(cos.IsEnabled(CodeOptimizations.OverrideRemoval, "any")); - Assert.True(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "testasm.dll")); - Assert.True(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "any")); + Assert.IsTrue(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "testasm.dll")); + Assert.IsTrue(cos.IsEnabled(CodeOptimizations.BeforeFieldInit, "any")); } } } diff --git a/src/tools/illink/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs b/src/tools/illink/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs index c126c9504b002c..3faa975da9cc1a 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs @@ -5,17 +5,18 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Cecil; using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.TestCasesRunner; -using NUnit.Framework; namespace Mono.Linker.Tests { - [TestFixture] + [TestClass] public class DocumentationSignatureParserTests { - [TestCaseSource(nameof(GetMemberAssertions), new object[] { typeof(DocumentationSignatureParserTests) })] + [TestMethod] + [DynamicData(nameof(GetMemberAssertions), new object[] { typeof(DocumentationSignatureParserTests) })] public void TestSignatureParsing(IMemberDefinition member, CustomAttribute customAttribute) { var attributeString = (string)customAttribute.ConstructorArguments[0].Value; @@ -38,12 +39,12 @@ public void TestSignatureParsing(IMemberDefinition member, CustomAttribute custo } } - public static IEnumerable GetMemberAssertions(Type type) => MemberAssertionsCollector.GetMemberAssertionsData(type); + public static IEnumerable> GetMemberAssertions(Type type) => MemberAssertionsCollector.GetMemberAssertionsData(type); public static void CheckUniqueParsedString(IMemberDefinition member, string input) { var module = (member as TypeDefinition)?.Module ?? member.DeclaringType?.Module; - Assert.NotNull(module); + Assert.IsNotNull(module); var parseResults = DocumentationSignatureParser.GetMembersForDocumentationSignature(input, module, new TestResolver()); Assert.AreEqual(1, parseResults.Count()); Assert.AreEqual(member, parseResults.First()); @@ -59,7 +60,7 @@ public static void CheckGeneratedString(IMemberDefinition member, string expecte public static void CheckParsedString(IMemberDefinition member, string input) { var module = (member as TypeDefinition)?.Module ?? member.DeclaringType?.Module; - Assert.NotNull(module); + Assert.IsNotNull(module); var parseResults = DocumentationSignatureParser.GetMembersForDocumentationSignature(input, module, new TestResolver()); CollectionAssert.Contains(parseResults, member); } @@ -67,7 +68,7 @@ public static void CheckParsedString(IMemberDefinition member, string input) public static void CheckUnresolvedDocumentationSignature(IMemberDefinition member, string input) { var module = (member as TypeDefinition)?.Module ?? member.DeclaringType?.Module; - Assert.NotNull(module); + Assert.IsNotNull(module); var parseResults = DocumentationSignatureParser.GetMembersForDocumentationSignature(input, module, new TestResolver()); CollectionAssert.DoesNotContain(parseResults, member); } diff --git a/src/tools/illink/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs b/src/tools/illink/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs index 67f1935223877d..8f53dc3f2cbc91 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/Tests/GetDisplayNameTests.cs @@ -3,19 +3,20 @@ using System; using System.Collections.Generic; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Cecil; using Mono.Linker; using Mono.Linker.Tests.Cases.Expectations.Assertions; using Mono.Linker.Tests.TestCasesRunner; -using NUnit.Framework; namespace Mono.Linker.Tests { - [NonParallelizable] - [TestFixture] + [DoNotParallelize] + [TestClass] public class GetDisplayNameTests { - [TestCaseSource(nameof(GetMemberAssertions), new object[] { typeof(GetDisplayNameTests) })] + [TestMethod] + [DynamicData(nameof(GetMemberAssertions), new object[] { typeof(GetDisplayNameTests) })] public void TestGetDisplayName(IMemberDefinition member, CustomAttribute customAttribute) { // The only intention with these tests is to check that the language elements that could @@ -42,7 +43,7 @@ public void TestGetDisplayName(IMemberDefinition member, CustomAttribute customA } } - public static IEnumerable GetMemberAssertions(Type type) => MemberAssertionsCollector.GetMemberAssertionsData(type); + public static IEnumerable> GetMemberAssertions(Type type) => MemberAssertionsCollector.GetMemberAssertionsData(type); [DisplayName("Mono.Linker.Tests.GetDisplayNameTests.Field")] public int Field; @@ -216,17 +217,18 @@ public static void MethodWithPartiallyInstantiatedNestedGenericTypeArguments GetMemberAssertions(Type type) => MemberAssertionsCollector.GetMemberAssertionsData(type); + public static IEnumerable> GetMemberAssertions(Type type) => MemberAssertionsCollector.GetMemberAssertionsData(type); [DisplayName("GetDisplayNameTestsGlobalScope.TypeInGlobalScope")] public class TypeInGlobalScope diff --git a/src/tools/illink/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs b/src/tools/illink/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs index f9e6a663abbd7e..d607faeaf51794 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs @@ -1,14 +1,14 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using NUnit.Framework; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Mono.Linker.Tests { - [TestFixture] + [TestClass] public class MessageContainerTests { - [Test] + [TestMethod] public void MSBuildFormat() { LinkContext context = new LinkContext(new Pipeline(), new ConsoleLogger(), string.Empty); diff --git a/src/tools/illink/test/Mono.Linker.Tests/Tests/ParseResponseFileLinesTests.cs b/src/tools/illink/test/Mono.Linker.Tests/Tests/ParseResponseFileLinesTests.cs index 54584f661758fc..11bbac5d9e7bda 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/Tests/ParseResponseFileLinesTests.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/Tests/ParseResponseFileLinesTests.cs @@ -3,105 +3,105 @@ using System.Collections.Generic; using System.IO; -using NUnit.Framework; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Mono.Linker.Tests { - [TestFixture] + [TestClass] public class ParseResponseFileLinesTests { - [Test] + [TestMethod] public void TestOneArg() { TestParseResponseFileLines(@"abc", new string[] { @"abc" }); } - [Test] + [TestMethod] public void TestTwoArgsOnOneLine() { TestParseResponseFileLines(@"abc def", new string[] { @"abc", @"def" }); } - [Test] + [TestMethod] public void TestTwoArgsOnTwoLine() { TestParseResponseFileLines(@"abc def", new string[] { @"abc", @"def" }); } - [Test] + [TestMethod] public void TestOneSlashWithoutQuote() { TestParseResponseFileLines(@"\", new string[] { @"\" }); } - [Test] + [TestMethod] public void TestTwoSlashesWithoutQuote() { TestParseResponseFileLines(@"\\", new string[] { @"\\" }); } - [Test] + [TestMethod] public void TestOneSlashWithQuote() { TestParseResponseFileLines(@"""x \"" y""", new string[] { @"x "" y" }); } - [Test] + [TestMethod] public void TestTwoSlashesWithQuote() { TestParseResponseFileLines(@"""Slashes \\ In Quote""", new string[] { @"Slashes \\ In Quote" }); } - [Test] + [TestMethod] public void TestTwoSlashesAtEndOfQuote() { TestParseResponseFileLines(@"""Trailing Slash\\""", new string[] { @"Trailing Slash\" }); } - [Test] + [TestMethod] public void TestWindowsPath() { TestParseResponseFileLines(@"C:\temp\test.txt", new string[] { @"C:\temp\test.txt" }); } - [Test] + [TestMethod] public void TestLinuxPath() { TestParseResponseFileLines(@"/tmp/test.txt", new string[] { @"/tmp/test.txt" }); } - [Test] + [TestMethod] public void TestEqualsArguments() { TestParseResponseFileLines(@"a=b", new string[] { @"a=b" }); } - [Test] + [TestMethod] public void TestEqualsArgumentsSpaces() { TestParseResponseFileLines(@"a=""b c""", new string[] { @"a=b c" }); } - [Test] + [TestMethod] public void TestEqualsKeySpaces() { TestParseResponseFileLines(@"""a b""=c", new string[] { @"a b=c" }); } - [Test] + [TestMethod] public void TestEscapedQuoteWithBackslash() { TestParseResponseFileLines(@"""a \"" b""", new string[] { @"a "" b" }); } - [Test] + [TestMethod] public void TestEscapedQuoteSequence() { TestParseResponseFileLines(@"""a """" b""", new string[] { @"a "" b" }); } - [Test] + [TestMethod] public void TestQuotedNewline() { TestParseResponseFileLines(@"""a @@ -114,7 +114,7 @@ private static void TestParseResponseFileLines(string v1, string[] v2) var result = new Queue(); using (var reader = new StringReader(v1)) Driver.ParseResponseFile(reader, result); - Assert.That(result, Is.EquivalentTo(v2)); + CollectionAssert.AreEquivalent(result.ToArray(), v2); } } } diff --git a/src/tools/illink/test/Mono.Linker.Tests/Tests/PreserveActionComparisonTests.cs b/src/tools/illink/test/Mono.Linker.Tests/Tests/PreserveActionComparisonTests.cs index c3467a6ab79418..4c3a3ed103952c 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/Tests/PreserveActionComparisonTests.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/Tests/PreserveActionComparisonTests.cs @@ -1,32 +1,33 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using NUnit.Framework; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Mono.Linker.Tests { - [TestFixture] + [TestClass] public class PreserveActionComparisonTests { - [TestCase(TypePreserve.All, TypePreserve.All, TypePreserve.All)] - [TestCase(TypePreserve.All, TypePreserve.Methods, TypePreserve.All)] - [TestCase(TypePreserve.All, TypePreserve.Fields, TypePreserve.All)] - [TestCase(TypePreserve.All, TypePreserve.Nothing, TypePreserve.All)] - [TestCase(TypePreserve.Methods, TypePreserve.All, TypePreserve.All)] - [TestCase(TypePreserve.Methods, TypePreserve.Methods, TypePreserve.Methods)] - [TestCase(TypePreserve.Methods, TypePreserve.Fields, TypePreserve.All)] - [TestCase(TypePreserve.Methods, TypePreserve.Nothing, TypePreserve.Methods)] - [TestCase(TypePreserve.Fields, TypePreserve.All, TypePreserve.All)] - [TestCase(TypePreserve.Fields, TypePreserve.Methods, TypePreserve.All)] - [TestCase(TypePreserve.Fields, TypePreserve.Fields, TypePreserve.Fields)] - [TestCase(TypePreserve.Fields, TypePreserve.Nothing, TypePreserve.Fields)] - [TestCase(TypePreserve.Nothing, TypePreserve.All, TypePreserve.All)] - [TestCase(TypePreserve.Nothing, TypePreserve.Methods, TypePreserve.Methods)] - [TestCase(TypePreserve.Nothing, TypePreserve.Fields, TypePreserve.Fields)] + [TestMethod] + [DataRow(TypePreserve.All, TypePreserve.All, TypePreserve.All)] + [DataRow(TypePreserve.All, TypePreserve.Methods, TypePreserve.All)] + [DataRow(TypePreserve.All, TypePreserve.Fields, TypePreserve.All)] + [DataRow(TypePreserve.All, TypePreserve.Nothing, TypePreserve.All)] + [DataRow(TypePreserve.Methods, TypePreserve.All, TypePreserve.All)] + [DataRow(TypePreserve.Methods, TypePreserve.Methods, TypePreserve.Methods)] + [DataRow(TypePreserve.Methods, TypePreserve.Fields, TypePreserve.All)] + [DataRow(TypePreserve.Methods, TypePreserve.Nothing, TypePreserve.Methods)] + [DataRow(TypePreserve.Fields, TypePreserve.All, TypePreserve.All)] + [DataRow(TypePreserve.Fields, TypePreserve.Methods, TypePreserve.All)] + [DataRow(TypePreserve.Fields, TypePreserve.Fields, TypePreserve.Fields)] + [DataRow(TypePreserve.Fields, TypePreserve.Nothing, TypePreserve.Fields)] + [DataRow(TypePreserve.Nothing, TypePreserve.All, TypePreserve.All)] + [DataRow(TypePreserve.Nothing, TypePreserve.Methods, TypePreserve.Methods)] + [DataRow(TypePreserve.Nothing, TypePreserve.Fields, TypePreserve.Fields)] public void VerifyBehaviorOfChoosePreserveActionWhichPreservesTheMost(TypePreserve left, TypePreserve right, TypePreserve expected) { - Assert.That(expected, Is.EqualTo(AnnotationStore.ChoosePreserveActionWhichPreservesTheMost(left, right))); - Assert.That(expected, Is.EqualTo(AnnotationStore.ChoosePreserveActionWhichPreservesTheMost(right, left))); + Assert.AreEqual(expected, AnnotationStore.ChoosePreserveActionWhichPreservesTheMost(left, right)); + Assert.AreEqual(expected, AnnotationStore.ChoosePreserveActionWhichPreservesTheMost(right, left)); } } } diff --git a/src/tools/illink/test/Mono.Linker.Tests/Tests/TestFrameworkRulesAndConventions.cs b/src/tools/illink/test/Mono.Linker.Tests/Tests/TestFrameworkRulesAndConventions.cs index 0a381082709e09..184b149647dc2b 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/Tests/TestFrameworkRulesAndConventions.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/Tests/TestFrameworkRulesAndConventions.cs @@ -4,18 +4,18 @@ using System.Collections.Generic; using System.Linq; using ILLink.Shared.TypeSystemProxy; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Mono.Cecil; using Mono.Linker.Tests.Extensions; using Mono.Linker.Tests.TestCases; using Mono.Linker.Tests.TestCasesRunner; -using NUnit.Framework; namespace Mono.Linker.Tests.Tests { - [TestFixture] + [TestClass] public class TestFrameworkRulesAndConventions { - [Test] + [TestMethod] public void OnlyAttributeTypesInExpectations() { foreach (var expectationsAssemblyPath in ExpectationAssemblies()) @@ -24,12 +24,12 @@ public void OnlyAttributeTypesInExpectations() { var nonAttributeTypes = assembly.MainModule.AllDefinedTypes().Where(t => !IsAcceptableExpectationsAssemblyType(t)).ToArray(); - Assert.That(nonAttributeTypes, Is.Empty); + Assert.IsEmpty(nonAttributeTypes); } } } - [Test] + [TestMethod] public void CanFindATypeForAllCsFiles() { var collector = CreateCollector(); @@ -40,7 +40,7 @@ public void CanFindATypeForAllCsFiles() }) .ToArray(); - Assert.That(missing, Is.Empty, $"Could not locate a type for the following files. Verify the type name and file name match and that the type is not excluded by a #if"); + Assert.IsEmpty(missing, $"Could not locate a type for the following files. Verify the type name and file name match and that the type is not excluded by a #if"); } /// diff --git a/src/tools/illink/test/Trimming.Tests.Shared/TestCaseSandbox.cs b/src/tools/illink/test/Trimming.Tests.Shared/TestCaseSandbox.cs index d4e5e26b398d1f..40722a8592d934 100644 --- a/src/tools/illink/test/Trimming.Tests.Shared/TestCaseSandbox.cs +++ b/src/tools/illink/test/Trimming.Tests.Shared/TestCaseSandbox.cs @@ -138,7 +138,7 @@ public virtual void Populate(TestCaseCompilationMetadataProvider metadataProvide /// /// Any files that are needed for linking should come from the expectations assembly so that these values - /// can be controlled using #ifs regardless of the framework the NUnit test project is compiled against + /// can be controlled using #ifs regardless of the framework the MSTest test project is compiled against /// /// public virtual void PopulateFromExpectations(TestCaseMetadataProvider metadataProvider) From 8360dfae4989a4d5adef982f6fc271ad3062ce7c Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 1 Apr 2026 19:27:46 +0200 Subject: [PATCH 2/3] Update DocumentationSignatureParserTests.cs --- .../Tests/DocumentationSignatureParserTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tools/illink/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs b/src/tools/illink/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs index 3faa975da9cc1a..777a2475317b84 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/Tests/DocumentationSignatureParserTests.cs @@ -62,7 +62,7 @@ public static void CheckParsedString(IMemberDefinition member, string input) var module = (member as TypeDefinition)?.Module ?? member.DeclaringType?.Module; Assert.IsNotNull(module); var parseResults = DocumentationSignatureParser.GetMembersForDocumentationSignature(input, module, new TestResolver()); - CollectionAssert.Contains(parseResults, member); + Assert.Contains(member, parseResults); } public static void CheckUnresolvedDocumentationSignature(IMemberDefinition member, string input) @@ -70,7 +70,7 @@ public static void CheckUnresolvedDocumentationSignature(IMemberDefinition membe var module = (member as TypeDefinition)?.Module ?? member.DeclaringType?.Module; Assert.IsNotNull(module); var parseResults = DocumentationSignatureParser.GetMembersForDocumentationSignature(input, module, new TestResolver()); - CollectionAssert.DoesNotContain(parseResults, member); + Assert.DoesNotContain(member, parseResults); } // testcases From 17f88f2942cbecb796086cadd73b9b0266b6c7bd Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 1 Apr 2026 19:28:26 +0200 Subject: [PATCH 3/3] Update MemberAssertionsCollector.cs --- .../TestCasesRunner/MemberAssertionsCollector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/MemberAssertionsCollector.cs b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/MemberAssertionsCollector.cs index cca468e8ed8d11..beb7b4485d69cb 100644 --- a/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/MemberAssertionsCollector.cs +++ b/src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/MemberAssertionsCollector.cs @@ -31,7 +31,7 @@ public static class MemberAssertionsCollector { return GetMemberAssertions(type).Select(v => { - return new TestDataRow<(IMemberDefinition, CustomAttribute)>(v.member, v.ca); + return new TestDataRow<(IMemberDefinition, CustomAttribute)>((v.member, v.ca)); }); }