From 00619abdc915bb6d32a506f82f6a49d5f46027cc Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 29 Oct 2025 21:03:49 +0000 Subject: [PATCH 1/2] Update mstest monorepo to v4 --- Directory.Packages.props | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 29c6c385f..d8f1995e6 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -21,9 +21,9 @@ - - - + + + From 32f7c1e5651241fc343b14f4e334cb36c808c689 Mon Sep 17 00:00:00 2001 From: Jamie Magee Date: Thu, 30 Oct 2025 07:35:25 -0700 Subject: [PATCH 2/2] Resolve MSTest v4 breaking changes https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-mstest-migration-v3-v4 --- .../AssemblyInfo.cs | 3 +++ .../AssemblyInfo.cs | 3 +++ .../AssemblyInfo.cs | 3 +++ .../GoComponentTests.cs | 25 ++++++++----------- .../AssemblyInfo.cs | 3 +++ .../SkipTestIfNotWindowsAttribute.cs | 22 ++++++++++++---- .../Attributes/SkipTestOnWindowsAttribute.cs | 22 ++++++++++++---- .../AssemblyInfo.cs | 3 +++ 8 files changed, 59 insertions(+), 25 deletions(-) create mode 100644 test/Microsoft.ComponentDetection.Common.Tests/AssemblyInfo.cs create mode 100644 test/Microsoft.ComponentDetection.Contracts.Tests/AssemblyInfo.cs create mode 100644 test/Microsoft.ComponentDetection.Detectors.Tests/AssemblyInfo.cs create mode 100644 test/Microsoft.ComponentDetection.Orchestrator.Tests/AssemblyInfo.cs create mode 100644 test/Microsoft.ComponentDetection.VerificationTests/AssemblyInfo.cs diff --git a/test/Microsoft.ComponentDetection.Common.Tests/AssemblyInfo.cs b/test/Microsoft.ComponentDetection.Common.Tests/AssemblyInfo.cs new file mode 100644 index 000000000..be2dce49a --- /dev/null +++ b/test/Microsoft.ComponentDetection.Common.Tests/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +[assembly: Parallelize(Scope = ExecutionScope.ClassLevel)] diff --git a/test/Microsoft.ComponentDetection.Contracts.Tests/AssemblyInfo.cs b/test/Microsoft.ComponentDetection.Contracts.Tests/AssemblyInfo.cs new file mode 100644 index 000000000..be2dce49a --- /dev/null +++ b/test/Microsoft.ComponentDetection.Contracts.Tests/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +[assembly: Parallelize(Scope = ExecutionScope.ClassLevel)] diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/AssemblyInfo.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/AssemblyInfo.cs new file mode 100644 index 000000000..be2dce49a --- /dev/null +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +[assembly: Parallelize(Scope = ExecutionScope.ClassLevel)] diff --git a/test/Microsoft.ComponentDetection.Detectors.Tests/GoComponentTests.cs b/test/Microsoft.ComponentDetection.Detectors.Tests/GoComponentTests.cs index 2075ae463..fe1c3377a 100644 --- a/test/Microsoft.ComponentDetection.Detectors.Tests/GoComponentTests.cs +++ b/test/Microsoft.ComponentDetection.Detectors.Tests/GoComponentTests.cs @@ -30,19 +30,17 @@ public void ConstructorTest_NameVersion() } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")] public void ConstructorTest_NameVersion_NullVersion() { - var goComponent = new GoComponent(TestName, null); + var action = () => new GoComponent(TestName, null); + action.Should().ThrowExactly(); } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")] public void ConstructorTest_NameVersion_NullName() { - var goComponent = new GoComponent(null, TestVersion); + var action = () => new GoComponent(null, TestVersion); + action.Should().ThrowExactly(); } [TestMethod] @@ -56,27 +54,24 @@ public void ConstructorTest_NameVersionHash() } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")] public void ConstructorTest_NameVersionHash_NullVersion() { - var goComponent = new GoComponent(TestName, null, TestHash); + var action = () => new GoComponent(TestName, null, TestHash); + action.Should().ThrowExactly(); } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")] public void ConstructorTest_NameVersionHash_NullName() { - var goComponent = new GoComponent(null, TestVersion, TestHash); + var action = () => new GoComponent(null, TestVersion, TestHash); + action.Should().ThrowExactly(); } [TestMethod] - [ExpectedException(typeof(ArgumentNullException))] - [System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "MSTEST0006:Avoid '[ExpectedException]'", Justification = "Single-line test case")] public void ConstructorTest_NameVersionHash_NullHash() { - var goComponent = new GoComponent(TestName, TestVersion, null); + var action = () => new GoComponent(TestName, TestVersion, null); + action.Should().ThrowExactly(); } [TestMethod] diff --git a/test/Microsoft.ComponentDetection.Orchestrator.Tests/AssemblyInfo.cs b/test/Microsoft.ComponentDetection.Orchestrator.Tests/AssemblyInfo.cs new file mode 100644 index 000000000..be2dce49a --- /dev/null +++ b/test/Microsoft.ComponentDetection.Orchestrator.Tests/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +[assembly: Parallelize(Scope = ExecutionScope.ClassLevel)] diff --git a/test/Microsoft.ComponentDetection.TestsUtilities/Attributes/SkipTestIfNotWindowsAttribute.cs b/test/Microsoft.ComponentDetection.TestsUtilities/Attributes/SkipTestIfNotWindowsAttribute.cs index 26289d9b2..7930749f3 100644 --- a/test/Microsoft.ComponentDetection.TestsUtilities/Attributes/SkipTestIfNotWindowsAttribute.cs +++ b/test/Microsoft.ComponentDetection.TestsUtilities/Attributes/SkipTestIfNotWindowsAttribute.cs @@ -1,24 +1,36 @@ namespace Microsoft.ComponentDetection.TestsUtilities; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; public sealed class SkipTestIfNotWindowsAttribute : TestMethodAttribute { - public override TestResult[] Execute(ITestMethod testMethod) + public SkipTestIfNotWindowsAttribute([CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1) + : base(callerFilePath, callerLineNumber) + { + this.CallerFilePath = callerFilePath; + this.CallerLineNumber = callerLineNumber; + } + + public string CallerFilePath { get; } + + public int CallerLineNumber { get; } + + public override Task ExecuteAsync(ITestMethod testMethod) { if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - return - [ + return Task.FromResult([ new TestResult { Outcome = UnitTestOutcome.Inconclusive, TestFailureException = new AssertInconclusiveException($"Skipped on {RuntimeInformation.OSDescription}."), }, - ]; + ]); } - return base.Execute(testMethod); + return base.ExecuteAsync(testMethod); } } diff --git a/test/Microsoft.ComponentDetection.TestsUtilities/Attributes/SkipTestOnWindowsAttribute.cs b/test/Microsoft.ComponentDetection.TestsUtilities/Attributes/SkipTestOnWindowsAttribute.cs index 5a335a938..c21fc8c3c 100644 --- a/test/Microsoft.ComponentDetection.TestsUtilities/Attributes/SkipTestOnWindowsAttribute.cs +++ b/test/Microsoft.ComponentDetection.TestsUtilities/Attributes/SkipTestOnWindowsAttribute.cs @@ -1,24 +1,36 @@ namespace Microsoft.ComponentDetection.TestsUtilities; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Threading.Tasks; using Microsoft.VisualStudio.TestTools.UnitTesting; public sealed class SkipTestOnWindowsAttribute : TestMethodAttribute { - public override TestResult[] Execute(ITestMethod testMethod) + public SkipTestOnWindowsAttribute([CallerFilePath] string callerFilePath = "", [CallerLineNumber] int callerLineNumber = -1) + : base(callerFilePath, callerLineNumber) + { + this.CallerFilePath = callerFilePath; + this.CallerLineNumber = callerLineNumber; + } + + public string CallerFilePath { get; } + + public int CallerLineNumber { get; } + + public override Task ExecuteAsync(ITestMethod testMethod) { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - return - [ + return Task.FromResult([ new TestResult { Outcome = UnitTestOutcome.Inconclusive, TestFailureException = new AssertInconclusiveException("Skipped on Windows."), }, - ]; + ]); } - return base.Execute(testMethod); + return base.ExecuteAsync(testMethod); } } diff --git a/test/Microsoft.ComponentDetection.VerificationTests/AssemblyInfo.cs b/test/Microsoft.ComponentDetection.VerificationTests/AssemblyInfo.cs new file mode 100644 index 000000000..be2dce49a --- /dev/null +++ b/test/Microsoft.ComponentDetection.VerificationTests/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +[assembly: Parallelize(Scope = ExecutionScope.ClassLevel)]