From b4ad39079a2872f9c6714d3738ae74b285b4cc71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 13 Dec 2024 16:00:48 +0100 Subject: [PATCH] Fixes --- Directory.Packages.props | 2 -- ...rosoft.Testing.Extensions.CrashDump.csproj | 1 - ...rosoft.Testing.Extensions.TrxReport.csproj | 1 - ...oft.Testing.Extensions.VSTestBridge.csproj | 2 -- .../Microsoft.Testing.Platform.csproj | 2 -- .../MSBuild.KnownExtensionRegistration.cs | 2 +- .../MSBuildTests.ConfigurationFile.cs | 4 +-- .../MSBuildTests.GenerateEntryPoint.cs | 8 +++--- .../MSBuildTests.Solution.cs | 9 +++---- .../MSBuildTests.Test.cs | 27 +++++++++---------- .../TestHostProcessLifetimeHandlerTests.cs | 6 ++--- .../UseAttributeOnTestMethodAnalyzerTests.cs | 14 +++++----- .../Verifiers/CSharpCodeFixVerifier`2+Test.cs | 1 - ...arameterCommandLineOptionsProviderTests.cs | 1 - .../CommandLine/CommandLineHandlerTests.cs | 4 +-- .../CommandLine/CommandLineTests.cs | 10 +++---- .../ConfigurationManagerTests.cs | 2 +- .../Helpers/CountDownEventTests.cs | 2 +- .../Helpers/TaskExtensionsTests.cs | 6 ++--- .../IPC/IPCTests.cs | 23 +++++++++------- .../Logging/LogTestHelpers.cs | 3 +++ .../Logging/NopLoggerTests.cs | 6 ++--- .../Terminal/TerminalTestReporterTests.cs | 4 +-- .../ServerMode/FormatterUtilitiesTests.cs | 8 +++--- .../ServerDataConsumerServiceTests.cs | 6 ++--- 25 files changed, 76 insertions(+), 78 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index cef7620acb..02cef5e9d1 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -66,8 +66,6 @@ - - diff --git a/src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csproj b/src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csproj index f711a190c2..6d7d59466d 100644 --- a/src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csproj +++ b/src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csproj @@ -42,7 +42,6 @@ This package extends Microsoft Testing Platform to provide a crash dump function - diff --git a/src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj b/src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj index 336a3f8003..0cfd477f7f 100644 --- a/src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj +++ b/src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj @@ -50,7 +50,6 @@ This package extends Microsoft Testing Platform to provide TRX test reports.]]> - diff --git a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj index 64a5152e66..a3d08254e9 100644 --- a/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj +++ b/src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj @@ -5,8 +5,6 @@ - - diff --git a/src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj b/src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj index 20f935bb6b..65d829e792 100644 --- a/src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj +++ b/src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj @@ -63,8 +63,6 @@ This package provides the core platform and the .NET implementation of the proto - - diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuild.KnownExtensionRegistration.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuild.KnownExtensionRegistration.cs index bf54182d62..682089895a 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuild.KnownExtensionRegistration.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuild.KnownExtensionRegistration.cs @@ -12,7 +12,7 @@ public class MSBuildTests_KnownExtensionRegistration : AcceptanceTestBase), DynamicDataSourceType.Method)] [TestMethod] public async Task Microsoft_Testing_Platform_Extensions_ShouldBe_Correctly_Registered(string tfm, BuildConfiguration compilationMode, Verb verb) { diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.ConfigurationFile.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.ConfigurationFile.cs index 94369e268c..361af7f4c2 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.ConfigurationFile.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.ConfigurationFile.cs @@ -8,7 +8,7 @@ namespace Microsoft.Testing.Platform.Acceptance.IntegrationTests; [TestClass] public class MSBuildTests : AcceptanceTestBase { - [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), DynamicDataSourceType.Method)] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] [TestMethod] public async Task ConfigFileGeneration_CorrectlyCreateAndCacheAndCleaned(string tfm, BuildConfiguration compilationMode, Verb verb) { @@ -48,7 +48,7 @@ public async Task ConfigFileGeneration_CorrectlyCreateAndCacheAndCleaned(string } } - [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), DynamicDataSourceType.Method)] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] [TestMethod] public async Task ConfigFileGeneration_NoConfigurationFile_TaskWontRun(string tfm, BuildConfiguration compilationMode, Verb verb) { diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.GenerateEntryPoint.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.GenerateEntryPoint.cs index 348808de86..5b7d2c36bf 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.GenerateEntryPoint.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.GenerateEntryPoint.cs @@ -13,7 +13,7 @@ public class MSBuildTests_EntryPoint : AcceptanceTestBase { private const string AssetName = "MSBuildTests"; - [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] [TestMethod] public async Task When_GenerateTestingPlatformEntryPoint_IsFalse_NoEntryPointInjected(string tfm, BuildConfiguration compilationMode, Verb verb) { @@ -35,7 +35,7 @@ public async Task When_GenerateTestingPlatformEntryPoint_IsFalse_NoEntryPointInj Assert.AreNotEqual(0, compilationResult.ExitCode); } - [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] [TestMethod] public async Task GenerateCSharpEntryPointAndVerifyTheCacheUsage(string tfm, BuildConfiguration compilationMode, Verb verb) => await GenerateAndVerifyLanguageSpecificEntryPoint(nameof(GenerateCSharpEntryPointAndVerifyTheCacheUsage), CSharpSourceCode, "cs", tfm, compilationMode, verb, @@ -60,7 +60,7 @@ internal sealed class TestingPlatformEntryPoint } }'", "Csc"); - [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] [TestMethod] public async Task GenerateVBEntryPointAndVerifyTheCacheUsage(string tfm, BuildConfiguration compilationMode, Verb verb) => await GenerateAndVerifyLanguageSpecificEntryPoint(nameof(GenerateVBEntryPointAndVerifyTheCacheUsage), VBSourceCode, "vb", tfm, compilationMode, verb, @@ -88,7 +88,7 @@ End Function End Module'", "Vbc"); - [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration))] + [DynamicData(nameof(GetBuildMatrixTfmBuildVerbConfiguration), typeof(AcceptanceTestBase), DynamicDataSourceType.Method)] [TestMethod] public async Task GenerateFSharpEntryPointAndVerifyTheCacheUsage(string tfm, BuildConfiguration compilationMode, Verb verb) => await GenerateAndVerifyLanguageSpecificEntryPoint(nameof(GenerateFSharpEntryPointAndVerifyTheCacheUsage), FSharpSourceCode, "fs", tfm, compilationMode, verb, diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Solution.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Solution.cs index f2699ae872..6aca719ef8 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Solution.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Solution.cs @@ -10,9 +10,9 @@ public class MSBuildTests_Solution : AcceptanceTestBase { private const string AssetName = "MSTestProject"; - internal static IEnumerable> GetBuildMatrix() + internal static IEnumerable<(string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm, string Command)> GetBuildMatrix() { - foreach (TestArgumentsEntry<(string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm)> entry in GetBuildMatrixSingleAndMultiTfmBuildConfiguration()) + foreach ((string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm) entry in GetBuildMatrixSingleAndMultiTfmBuildConfiguration()) { foreach (string command in new string[] { @@ -20,13 +20,12 @@ public class MSBuildTests_Solution : AcceptanceTestBase "test --no-restore", }) { - yield return new TestArgumentsEntry<(string SingleTfmOrMultiTfm, BuildConfiguration BuildConfiguration, bool IsMultiTfm, string Command)>( - (entry.Arguments.SingleTfmOrMultiTfm, entry.Arguments.BuildConfiguration, entry.Arguments.IsMultiTfm, command), $"{(entry.Arguments.IsMultiTfm ? "multitfm" : entry.Arguments.SingleTfmOrMultiTfm)},{entry.Arguments.BuildConfiguration},{command}"); + yield return new(entry.SingleTfmOrMultiTfm, entry.BuildConfiguration, entry.IsMultiTfm, command); } } } - [DynamicData(nameof(GetBuildMatrix))] + [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method)] [TestMethod] public async Task MSBuildTests_UseMSBuildTestInfrastructure_Should_Run_Solution_Tests(string singleTfmOrMultiTfm, BuildConfiguration _, bool isMultiTfm, string command) { diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs index ab82af9e98..daf7cf5b6e 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/MSBuildTests.Test.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System.Reflection; using System.Runtime.InteropServices; using System.Text.RegularExpressions; @@ -13,15 +14,12 @@ public class MSBuildTests_Test : AcceptanceTestBase { private const string AssetName = "MSBuildTests"; - internal static TestArgumentsEntry<(string BuildCommand, string TargetFramework, BuildConfiguration BuildConfiguration, bool TestSucceeded)> FormatBuildMatrixEntry(TestArgumentsContext ctx) - { - var entry = ((string, string, BuildConfiguration, bool))ctx.Arguments; - return new TestArgumentsEntry<(string, string, BuildConfiguration, bool)>(entry, $"{entry.Item1},{(TargetFrameworks.All.ToMSBuildTargetFrameworks() == entry.Item2 ? "multitfm" : entry.Item2)},{entry.Item3},{(entry.Item4 ? "Succeeded" : "Failed")}"); - } + public static string? FormatBuildMatrixEntry(MethodInfo method, object?[]? data) + => $"{data![0]},{(string.Equals(TargetFrameworks.All.ToMSBuildTargetFrameworks(), data[1]) ? "multitfm" : data[1])},{data[2]},{((bool)data[3]! ? "Succeeded" : "Failed")}"; internal static IEnumerable<(string BuildCommand, string TargetFramework, BuildConfiguration BuildConfiguration, bool TestSucceeded)> GetBuildMatrix() { - foreach (TestArgumentsEntry tfm in TargetFrameworks.All) + foreach (string tfm in TargetFrameworks.All) { foreach (BuildConfiguration compilationMode in Enum.GetValues()) { @@ -33,7 +31,7 @@ public class MSBuildTests_Test : AcceptanceTestBase "test -p:TestingPlatformDotnetTestSupport=True", }) { - yield return (buildCommand, tfm.Arguments, compilationMode, testSucceeded); + yield return (buildCommand, tfm, compilationMode, testSucceeded); } } } @@ -58,15 +56,15 @@ public class MSBuildTests_Test : AcceptanceTestBase } } - [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method, TestArgumentsEntryProviderMethodName = nameof(FormatBuildMatrixEntry))] + [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(FormatBuildMatrixEntry))] [TestMethod] public async Task InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Showing_Error_Detail_SingleTfm(string testCommand, string tfm, BuildConfiguration compilationMode, bool testSucceeded) => await InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Showing_Error_Detail(testCommand, tfm, false, [tfm], compilationMode, testSucceeded); - [DynamicData(nameof(GetBuildMatrixMultiTfm), DynamicDataSourceType.Method, TestArgumentsEntryProviderMethodName = nameof(FormatBuildMatrixEntry))] + [DynamicData(nameof(GetBuildMatrixMultiTfm), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(FormatBuildMatrixEntry))] [TestMethod] public async Task InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Showing_Error_Detail_MultiTfm(string testCommand, string multiTfm, BuildConfiguration compilationMode, bool testSucceeded) - => await InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Showing_Error_Detail(testCommand, multiTfm, true, TargetFrameworks.All.Select(x => x.Arguments).ToArray(), compilationMode, testSucceeded); + => await InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Showing_Error_Detail(testCommand, multiTfm, true, TargetFrameworks.All, compilationMode, testSucceeded); private async Task InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Showing_Error_Detail(string testCommand, string tfm, bool isMultiTfm, string[] tfmsToAssert, BuildConfiguration compilationMode, bool testSucceeded) { @@ -89,12 +87,12 @@ private async Task InvokeTestingPlatform_Target_Should_Execute_Tests_Without_Sho } } - [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method, TestArgumentsEntryProviderMethodName = nameof(FormatBuildMatrixEntry))] + [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(FormatBuildMatrixEntry))] [TestMethod] public async Task InvokeTestingPlatform_Target_Should_Build_Without_Warnings_And_Execute_Passing_Test_And_Pass_TheRun_SingleTfm(string testCommand, string tfm, BuildConfiguration compilationMode, bool testSucceeded) => await InvokeTestingPlatform_Target_Should_Build_Without_Warnings_And_Execute_Passing_Test_And_Pass_TheRun_Detail(testCommand, tfm, false, [tfm], compilationMode, testSucceeded); - [DynamicData(nameof(GetBuildMatrixMultiTfm), DynamicDataSourceType.Method, TestArgumentsEntryProviderMethodName = nameof(FormatBuildMatrixEntry))] + [DynamicData(nameof(GetBuildMatrixMultiTfm), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(FormatBuildMatrixEntry))] [TestMethod] public async Task InvokeTestingPlatform_Target_Should_Build_Without_Warnings_And_Execute_Passing_Test_And_Pass_TheRun_MultiTfm(string testCommand, string multiTfm, BuildConfiguration compilationMode, bool testSucceeded) => await InvokeTestingPlatform_Target_Should_Build_Without_Warnings_And_Execute_Passing_Test_And_Pass_TheRun_Detail(testCommand, multiTfm, true, TargetFrameworks.All, compilationMode, testSucceeded); @@ -258,9 +256,10 @@ private static void CommonAssert(DotnetMuxerResult compilationResult, string tfm Assert.IsFalse(string.IsNullOrEmpty(File.ReadAllText(outputFileLog)), $"Content of file '{File.ReadAllText(outputFileLog)}'"); } - // We avoid to test the multi-tfm because it's already tested with the above tests and we don't want to have too heavy testing, msbuild is pretty heavy (a lot of processes started due to the no 'nodereuse') and makes tests flaky. + // We avoid to test the multi-tfm because it's already tested with the above tests and we don't want to have too heavy testing, + // msbuild is pretty heavy (a lot of processes started due to the no 'nodereuse') and makes tests flaky. // We test two functionality for the same reason, we don't want to load too much the CI only for UX reasons. - [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method, TestArgumentsEntryProviderMethodName = nameof(FormatBuildMatrixEntry))] + [DynamicData(nameof(GetBuildMatrix), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(FormatBuildMatrixEntry))] [TestMethod] public async Task InvokeTestingPlatform_Target_Showing_Error_And_Do_Not_Capture_The_Output_SingleTfm(string testCommand, string tfm, BuildConfiguration compilationMode, bool testSucceeded) { diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TestHostProcessLifetimeHandlerTests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TestHostProcessLifetimeHandlerTests.cs index 03d6580080..96b8561142 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TestHostProcessLifetimeHandlerTests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/TestHostProcessLifetimeHandlerTests.cs @@ -18,9 +18,9 @@ public async Task All_Interface_Methods_ShouldBe_Invoked(string currentTfm) var testHost = TestInfrastructure.TestHost.LocateFrom(AssetFixture.TargetAssetPath, AssetName, currentTfm); TestHostResult testHostResult = await testHost.ExecuteAsync(); testHostResult.AssertExitCodeIs(ExitCodes.Success); - Assert.AreEqual(File.ReadAllText(Path.Combine(testHost.DirectoryName, "BeforeTestHostProcessStartAsync.txt")), "TestHostProcessLifetimeHandler.BeforeTestHostProcessStartAsync"); - Assert.AreEqual(File.ReadAllText(Path.Combine(testHost.DirectoryName, "OnTestHostProcessStartedAsync.txt")), "TestHostProcessLifetimeHandler.OnTestHostProcessStartedAsync"); - Assert.AreEqual(File.ReadAllText(Path.Combine(testHost.DirectoryName, "OnTestHostProcessExitedAsync.txt")), "TestHostProcessLifetimeHandler.OnTestHostProcessExitedAsync"); + Assert.AreEqual("TestHostProcessLifetimeHandler.BeforeTestHostProcessStartAsync", File.ReadAllText(Path.Combine(testHost.DirectoryName, "BeforeTestHostProcessStartAsync.txt"))); + Assert.AreEqual("TestHostProcessLifetimeHandler.OnTestHostProcessStartedAsync", File.ReadAllText(Path.Combine(testHost.DirectoryName, "OnTestHostProcessStartedAsync.txt"))); + Assert.AreEqual("TestHostProcessLifetimeHandler.OnTestHostProcessExitedAsync", File.ReadAllText(Path.Combine(testHost.DirectoryName, "OnTestHostProcessExitedAsync.txt"))); } public sealed class TestAssetFixture() : TestAssetFixtureBase(AcceptanceFixture.NuGetGlobalPackagesFolder) diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/UseAttributeOnTestMethodAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/UseAttributeOnTestMethodAnalyzerTests.cs index b7fc180c4f..f7353183ad 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/UseAttributeOnTestMethodAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/UseAttributeOnTestMethodAnalyzerTests.cs @@ -35,11 +35,11 @@ protected override void Verify(System.Exception exception) { } internal static IEnumerable<(DiagnosticDescriptor Rule, string AttributeUsageExample)> GetAttributeUsageExampleAndRuleTuples() => RuleUsageExamples.Select(tuple => (tuple.Rule, tuple.AttributeUsageExample)); - internal static IEnumerable GetAttributeUsageExamples() - => RuleUsageExamples.Select(tuple => tuple.AttributeUsageExample); + internal static IEnumerable GetAttributeUsageExamples() + => RuleUsageExamples.Select(tuple => new object[] { tuple.AttributeUsageExample }); // This generates all possible combinations of any two tuples (Rule, AttributeUsageExample) with the exception of the - // combaination where the two tuples are equal. The result is flattened in a new tuple created from the elements of the + // combination where the two tuples are equal. The result is flattened in a new tuple created from the elements of the // previous two tuples. internal static IEnumerable<(DiagnosticDescriptor Rule1, string AttributeUsageExample1, DiagnosticDescriptor Rule2, string AttributeUsageExample2)> GetAttributeUsageExampleAndRuleTuplesForTwoAttributes() => RuleUsageExamples @@ -47,7 +47,7 @@ internal static IEnumerable GetAttributeUsageExamples() .Where(tuples => !tuples.tuple1.AttributeUsageExample.Equals(tuples.tuple2.AttributeUsageExample, StringComparison.Ordinal)) .Select(tuples => (tuples.tuple1.Rule, tuples.tuple1.AttributeUsageExample, tuples.tuple2.Rule, tuples.tuple2.AttributeUsageExample)); - [DynamicData(nameof(GetAttributeUsageExamples))] + [DynamicData(nameof(GetAttributeUsageExamples), DynamicDataSourceType.Method)] [TestMethod] public async Task WhenMethodIsMarkedWithTestMethodAndTestAttributes_NoDiagnosticAsync(string attributeUsageExample) { @@ -70,7 +70,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, code); } - [DynamicData(nameof(GetAttributeUsageExampleAndRuleTuples))] + [DynamicData(nameof(GetAttributeUsageExampleAndRuleTuples), DynamicDataSourceType.Method)] [TestMethod] public async Task WhenMethodIsMarkedWithTestAttributeButNotWithTestMethod_DiagnosticAsync(DiagnosticDescriptor rule, string attributeUsageExample) { @@ -108,7 +108,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, VerifyCS.Diagnostic(rule).WithLocation(0), fixedCode); } - [DynamicData(nameof(GetAttributeUsageExampleAndRuleTuplesForTwoAttributes))] + [DynamicData(nameof(GetAttributeUsageExampleAndRuleTuplesForTwoAttributes), DynamicDataSourceType.Method)] [TestMethod] public async Task WhenMethodIsMarkedWithMultipleTestAttributesButNotWithTestMethod_DiagnosticOnEachAttributeAsync( DiagnosticDescriptor rule1, @@ -152,7 +152,7 @@ public void TestMethod() await VerifyCS.VerifyCodeFixAsync(code, new[] { VerifyCS.Diagnostic(rule1).WithLocation(0), VerifyCS.Diagnostic(rule2).WithLocation(1) }, fixedCode); } - [DynamicData(nameof(GetAttributeUsageExamples))] + [DynamicData(nameof(GetAttributeUsageExamples), DynamicDataSourceType.Method)] [TestMethod] public async Task WhenMethodIsMarkedWithTestAttributeAndCustomTestMethod_NoDiagnosticAsync(string attributeUsageExample) { diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/Verifiers/CSharpCodeFixVerifier`2+Test.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/Verifiers/CSharpCodeFixVerifier`2+Test.cs index 9db21ba08b..3fc45b7658 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/Verifiers/CSharpCodeFixVerifier`2+Test.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/Verifiers/CSharpCodeFixVerifier`2+Test.cs @@ -6,7 +6,6 @@ using Microsoft.CodeAnalysis.CSharp.Testing; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Testing; -using Microsoft.VisualStudio.TestTools.UnitTesting; using TestContext = Microsoft.VisualStudio.TestTools.UnitTesting.TestContext; diff --git a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/CommandLine/TestRunParameterCommandLineOptionsProviderTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/CommandLine/TestRunParameterCommandLineOptionsProviderTests.cs index a316bd9531..06225f002d 100644 --- a/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/CommandLine/TestRunParameterCommandLineOptionsProviderTests.cs +++ b/test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/CommandLine/TestRunParameterCommandLineOptionsProviderTests.cs @@ -12,7 +12,6 @@ namespace Microsoft.Testing.Extensions.VSTestBridge.UnitTests.CommandLine; [TestClass] public sealed class TestRunParameterCommandLineOptionsProviderTests - { [TestMethod] public async Task TestRunParameterOption_WhenArgumentDoesNotContainEqual_IsNotValid() diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs index 6017779e96..eaeb65e207 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineHandlerTests.cs @@ -38,8 +38,8 @@ public async Task ParseAndValidateAsync_InvalidCommandLineArguments_ReturnsFalse // Assert Assert.IsFalse(result.IsValid); - StringAssert.Contains("Invalid command line arguments:", result.ErrorMessage); - StringAssert.Contains("Unexpected argument 'a'", result.ErrorMessage); + StringAssert.Contains(result.ErrorMessage, "Invalid command line arguments:"); + StringAssert.Contains(result.ErrorMessage, "Unexpected argument 'a'"); } [TestMethod] diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineTests.cs index f9bafdcd3e..7f426c4ef5 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/CommandLine/CommandLineTests.cs @@ -52,13 +52,13 @@ public void ParserTests(int testNum, string[] args, (string RspFileName, string } } - internal static string ParserTestDataFormat(MethodInfo methodInfo, object?[]? data) + public static string ParserTestDataFormat(MethodInfo methodInfo, object?[]? data) { - (int TestNum, string[] Args, (string RspFileName, string RspFileContent)[]? RspFiles, CommandLineParseResultWrapper ParseResult) item = ((int)data![0]!, (string[])data[1]!, ((string, string)[])data[2]!, (CommandLineParseResultWrapper)data[3]!); + (int testNum, string[] args, (string RspFileName, string RspFileContent)[]? rspFiles, CommandLineParseResultWrapper parseResult) = ((int)data![0]!, (string[])data[1]!, ((string, string)[])data[2]!, (CommandLineParseResultWrapper)data[3]!); - return item.TestNum == 13 - ? $"\"--option1\", $@\" \"\" \\{{Environment.NewLine}} \"\" \" {item.TestNum}" - : $"{item.Args.Aggregate((a, b) => $"{a} {b}")} {item.TestNum}"; + return testNum == 13 + ? $"\"--option1\", $@\" \"\" \\{{Environment.NewLine}} \"\" \" {testNum}" + : $"{args.Aggregate((a, b) => $"{a} {b}")} {testNum}"; } internal static IEnumerable<(int TestNum, string[] Args, (string RspFileName, string RspFileContent)[]? RspFiles, CommandLineParseResultWrapper ParseResult)> ParserTestsData() diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/ConfigurationManagerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/ConfigurationManagerTests.cs index a28469251a..d6f98d8c1b 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/ConfigurationManagerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Configuration/ConfigurationManagerTests.cs @@ -66,7 +66,7 @@ public async ValueTask InvalidJson_Fail() ConfigurationManager configurationManager = new(fileSystem.Object, testApplicationModuleInfo); configurationManager.AddConfigurationSource(() => new JsonConfigurationSource(testApplicationModuleInfo, fileSystem.Object, null)); - await Assert.ThrowsExceptionAsync(() => configurationManager.BuildAsync(null, new CommandLineParseResult(null, new List(), Array.Empty()))); + await Assert.ThrowsExceptionAsync(() => configurationManager.BuildAsync(null, new CommandLineParseResult(null, new List(), Array.Empty()))); } [TestMethod] diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/CountDownEventTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/CountDownEventTests.cs index 494e7b6ba9..03493e2ee9 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/CountDownEventTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/CountDownEventTests.cs @@ -40,7 +40,7 @@ public async Task CountDownEvent_WaitAsyncCanceled_Succeeded() CancellationToken cancelToken = cts.Token; var waiter = Task.Run(() => countdownEvent.WaitAsync(cancelToken), cancelToken); await cts.CancelAsync(); - await Assert.ThrowsExceptionAsync(async () => await waiter); + await Assert.ThrowsExceptionAsync(async () => await waiter); } [TestMethod] diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs index a670e0d1cf..b293df1015 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs @@ -36,7 +36,7 @@ public async Task CancellationAsync_Cancellation_Succeeds() #pragma warning disable VSTHRD103 // Call async methods when in an async method cancellationTokenSource.Cancel(); #pragma warning restore VSTHRD103 // Call async methods when in an async method - OperationCanceledException exception = await Assert.ThrowsExceptionAsync(async () => await task); + OperationCanceledException exception = await Assert.ThrowsExceptionAsync(async () => await task); Assert.AreEqual(cancelToken, exception.CancellationToken); } @@ -49,7 +49,7 @@ public async Task CancellationAsync_CancellationWithArgument_Succeeds() #pragma warning disable VSTHRD103 // Call async methods when in an async method cancellationTokenSource.Cancel(); #pragma warning restore VSTHRD103 // Call async methods when in an async method - OperationCanceledException exception = await Assert.ThrowsExceptionAsync(async () => await task); + OperationCanceledException exception = await Assert.ThrowsExceptionAsync(async () => await task); Assert.AreEqual(cancelToken, exception.CancellationToken); } @@ -74,7 +74,7 @@ public async Task CancellationAsync_ObserveException_Succeeds() async () => { ManualResetEvent waitException = new(false); - await Assert.ThrowsExceptionAsync(async () + await Assert.ThrowsExceptionAsync(async () => await Task.Run(async () => { await Task.Delay(TimeSpan.FromSeconds(10)); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/IPCTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/IPCTests.cs index 6ce2f3f0b0..ac8fe2bc84 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/IPCTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/IPC/IPCTests.cs @@ -12,8 +12,13 @@ namespace Microsoft.Testing.Platform.UnitTests; [TestClass] -public sealed class IPCTests(TestContext testContext) +public sealed class IPCTests { + private readonly TestContext _testContext; + + public IPCTests(TestContext testContext) + => _testContext = testContext; + [TestMethod] public async Task SingleConnectionNamedPipeServer_MultipleConnection_Fails() { @@ -35,9 +40,9 @@ public async Task SingleConnectionNamedPipeServer_MultipleConnection_Fails() new SystemEnvironment(), new Mock().Object, new SystemTask(), - testContext.CancellationTokenSource.Token); + _testContext.CancellationTokenSource.Token); - await singleConnectionNamedPipeServer.WaitConnectionAsync(testContext.CancellationTokenSource.Token); + await singleConnectionNamedPipeServer.WaitConnectionAsync(_testContext.CancellationTokenSource.Token); openedPipe.Add(singleConnectionNamedPipeServer); } } @@ -49,7 +54,7 @@ public async Task SingleConnectionNamedPipeServer_MultipleConnection_Fails() }); NamedPipeClient namedPipeClient1 = new(pipeNameDescription.Name); - await namedPipeClient1.ConnectAsync(testContext.CancellationTokenSource.Token); + await namedPipeClient1.ConnectAsync(_testContext.CancellationTokenSource.Token); waitException.Wait(); Assert.AreEqual(1, openedPipe.Count); @@ -100,7 +105,7 @@ public async Task SingleConnectionNamedPipeServer_RequestReplySerialization_Succ manualResetEventSlim.Set(); break; } - catch (OperationCanceledException ct) when (ct.CancellationToken == testContext.CancellationTokenSource.Token) + catch (OperationCanceledException ct) when (ct.CancellationToken == _testContext.CancellationTokenSource.Token) { throw new OperationCanceledException("SingleConnectionNamedPipeServer_RequestReplySerialization_Succeeded cancellation during connect, testContext.CancellationTokenSource.Token"); } @@ -178,7 +183,7 @@ public async Task ConnectionNamedPipeServer_MultipleConnection_Succeded() new Mock().Object, new SystemTask(), maxNumberOfServerInstances: 3, - testContext.CancellationTokenSource.Token)); + _testContext.CancellationTokenSource.Token)); } #pragma warning disable CA1806 // Do not ignore method results @@ -190,7 +195,7 @@ public async Task ConnectionNamedPipeServer_MultipleConnection_Succeded() new Mock().Object, new SystemTask(), maxNumberOfServerInstances: 3, - testContext.CancellationTokenSource.Token)); + _testContext.CancellationTokenSource.Token)); StringAssert.Contains("All pipe instances are busy.", exception.Message); #pragma warning restore CA1806 // Do not ignore method results @@ -200,7 +205,7 @@ public async Task ConnectionNamedPipeServer_MultipleConnection_Succeded() { waitConnectionTask.Add(Task.Run(async () => { - await namedPipeServer.WaitConnectionAsync(testContext.CancellationTokenSource.Token); + await namedPipeServer.WaitConnectionAsync(_testContext.CancellationTokenSource.Token); Interlocked.Increment(ref connectionCompleted); })); } @@ -210,7 +215,7 @@ public async Task ConnectionNamedPipeServer_MultipleConnection_Succeded() { NamedPipeClient namedPipeClient = new(pipeNameDescription.Name); connectedClients.Add(namedPipeClient); - await namedPipeClient.ConnectAsync(testContext.CancellationTokenSource.Token); + await namedPipeClient.ConnectAsync(_testContext.CancellationTokenSource.Token); } await Task.WhenAll(waitConnectionTask.ToArray()); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LogTestHelpers.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LogTestHelpers.cs index e0dc034294..571f312dff 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LogTestHelpers.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LogTestHelpers.cs @@ -16,6 +16,9 @@ public static IEnumerable GetLogLevels() => typeof(LogLevel).GetEnumValues().Cast(); #endif + public static IEnumerable GetLogLevelsForDynamicData() + => GetLogLevels().Select(x => new object[] { x }); + public static IEnumerable<(LogLevel DefaultLevel, LogLevel CurrentLevel)> GetLogLevelCombinations() { List<(LogLevel, LogLevel)> logLevelCombinations = new(); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/NopLoggerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/NopLoggerTests.cs index 5014619872..687b8fcfe8 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/NopLoggerTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/NopLoggerTests.cs @@ -21,12 +21,12 @@ public sealed class NopLoggerTests private static int s_formatterCalls; - [DynamicData(nameof(LogTestHelpers.GetLogLevels), typeof(LogTestHelpers), DynamicDataSourceType.Method)] + [DynamicData(nameof(LogTestHelpers.GetLogLevelsForDynamicData), typeof(LogTestHelpers), DynamicDataSourceType.Method)] [TestMethod] public void NopLogger_CheckDisabled(LogLevel logLevel) => Assert.IsFalse(_nopLogger.IsEnabled(logLevel)); - [DynamicData(nameof(LogTestHelpers.GetLogLevels), typeof(LogTestHelpers), DynamicDataSourceType.Method)] + [DynamicData(nameof(LogTestHelpers.GetLogLevelsForDynamicData), typeof(LogTestHelpers), DynamicDataSourceType.Method)] [TestMethod] public void NopLogger_Log_NoFormatterCalls(LogLevel logLevel) { @@ -34,7 +34,7 @@ public void NopLogger_Log_NoFormatterCalls(LogLevel logLevel) Assert.AreEqual(0, s_formatterCalls); } - [DynamicData(nameof(LogTestHelpers.GetLogLevels), typeof(LogTestHelpers), DynamicDataSourceType.Method)] + [DynamicData(nameof(LogTestHelpers.GetLogLevelsForDynamicData), typeof(LogTestHelpers), DynamicDataSourceType.Method)] [TestMethod] public async ValueTask NopLogger_LogAsync_NoFormatterCalls(LogLevel logLevel) { diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs index 655a11a28c..221fb03524 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/OutputDevice/Terminal/TerminalTestReporterTests.cs @@ -30,9 +30,9 @@ public void AppendStackFrameFormatsStackTraceLineCorrectly() TerminalTestReporter.AppendStackFrame(terminal, firstStackTraceLine); #if NETCOREAPP - StringAssert.Contains(" at Microsoft.Testing.Platform.UnitTests.TerminalTestReporterTests.AppendStackFrameFormatsStackTraceLineCorrectly() in ", terminal.Output); + StringAssert.Contains(terminal.Output, " at Microsoft.Testing.Platform.UnitTests.TerminalTestReporterTests.AppendStackFrameFormatsStackTraceLineCorrectly() in "); #else - StringAssert.Contains(" at Microsoft.Testing.Platform.UnitTests.TerminalTestReporterTests.AppendStackFrameFormatsStackTraceLineCorrectly()", terminal.Output); + StringAssert.Contains(terminal.Output, " at Microsoft.Testing.Platform.UnitTests.TerminalTestReporterTests.AppendStackFrameFormatsStackTraceLineCorrectly()"); #endif // Line number without the respective file Assert.IsFalse(terminal.Output.ToString().Contains(" :0")); diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/FormatterUtilitiesTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/FormatterUtilitiesTests.cs index 72a576c161..5f7440bc80 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/FormatterUtilitiesTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/FormatterUtilitiesTests.cs @@ -18,6 +18,9 @@ public sealed class FormatterUtilitiesTests { private readonly IMessageFormatter _formatter = FormatterUtilities.CreateFormatter(); + public static IEnumerable SerializerTypesForDynamicData + => SerializerUtilities.SerializerTypes.Select(x => new object[] { x }); + public FormatterUtilitiesTests() => #if NETCOREAPP @@ -50,8 +53,7 @@ public void CanDeserializeTaskResponse() Assert.IsNull(response.Result); } - [DynamicData(nameof(SerializerUtilities.SerializerTypes), typeof(SerializerUtilities), - DynamicDataDisplayName = nameof(FormatSerializerTypes))] + [DynamicData(nameof(SerializerTypesForDynamicData), DynamicDataDisplayName = nameof(FormatSerializerTypes))] [TestMethod] public async Task SerializeDeserialize_Succeed(Type type) { @@ -132,7 +134,7 @@ private static void CustomAssert(Type type, object instanceDeserialized, object } } - internal static string? FormatSerializerTypes(MethodInfo methodInfo, object?[]? data) + public static string? FormatSerializerTypes(MethodInfo methodInfo, object?[]? data) => data is not null ? (data[0] as Type)?.Name : null; diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerDataConsumerServiceTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerDataConsumerServiceTests.cs index 2933789003..e1703f6e8d 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerDataConsumerServiceTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/ServerMode/ServerDataConsumerServiceTests.cs @@ -16,7 +16,7 @@ namespace Microsoft.Testing.Platform.UnitTests; [TestClass] -public sealed class ServerDataConsumerServiceTests +public sealed class ServerDataConsumerServiceTests : IDisposable { private readonly PerRequestServerDataConsumer _service; private readonly ServiceProvider _serviceProvider = new(); @@ -192,10 +192,10 @@ public async Task CleanupAsync() { await idleUpdateTaskAsync.TimeoutAfterAsync(TimeoutHelper.DefaultHangTimeSpanTimeout); } - - _service.Dispose(); } + void IDisposable.Dispose() => _service.Dispose(); + private sealed class DataProducer : IDataProducer { public string Uid => nameof(DataProducer);