From fec1df8b00764ceb831a1686d0e299eb5d780626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 17 Jul 2026 10:11:41 +0200 Subject: [PATCH 1/3] Add MSTEST0070 member name edge-case tests Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: fb77a624-ff12-4dda-849c-882199b9830e --- ...mberConditionShouldBeValidAnalyzerTests.cs | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/MemberConditionShouldBeValidAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/MemberConditionShouldBeValidAnalyzerTests.cs index 62bbf395ce9..7217f8e0475 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/MemberConditionShouldBeValidAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/MemberConditionShouldBeValidAnalyzerTests.cs @@ -690,4 +690,73 @@ await VerifyCS.VerifyAnalyzerAsync( .WithLocation(0) .WithArguments("Conditions", "Missing2")); } + + [TestMethod] + public async Task WhenMemberNameIsEmptyString_NoDiagnostic() + { + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + public static class Conditions + { + public static bool IsReady => true; + } + + [TestClass] + public class MyTestClass + { + [MemberCondition(typeof(Conditions), "")] + [TestMethod] + public void TestMethod() { } + } + """; + + await VerifyCS.VerifyAnalyzerAsync(code); + } + + [TestMethod] + public async Task WhenMemberNameIsWhitespace_NoDiagnostic() + { + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + public static class Conditions + { + public static bool IsReady => true; + } + + [TestClass] + public class MyTestClass + { + [MemberCondition(typeof(Conditions), " ")] + [TestMethod] + public void TestMethod() { } + } + """; + + await VerifyCS.VerifyAnalyzerAsync(code); + } + + [TestMethod] + public async Task WhenMemberNameIsEmptyInParamsArray_NoDiagnostic() + { + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + public static class Conditions + { + public static bool IsReady => true; + } + + [TestClass] + public class MyTestClass + { + [MemberCondition(typeof(Conditions), "IsReady", "")] + [TestMethod] + public void TestMethod() { } + } + """; + + await VerifyCS.VerifyAnalyzerAsync(code); + } } From 56d74af2518df4c55419c01bccb3cf2efdda0f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 17 Jul 2026 13:59:39 +0200 Subject: [PATCH 2/3] Stabilize task cancellation test Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: fb77a624-ff12-4dda-849c-882199b9830e --- .../Helpers/TaskExtensionsTests.cs | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs index 47e3ac747f4..9d34905293e 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs @@ -93,23 +93,26 @@ public async Task CancellationAsync_ObserveException_Succeeds() public async Task CancellationAsyncWithReturnValue_ObserveException_Succeeds() { ManualResetEvent waitException = new(false); - CancellationToken token = new CancellationTokenSource(TimeSpan.FromSeconds(1)).Token; - OperationCanceledException ex = await Assert.ThrowsAsync(async () - => await Task.Run(async () => + using CancellationTokenSource cancellationTokenSource = new(); + CancellationToken token = cancellationTokenSource.Token; + Task task = Task.Run(async () => + { + await Task.Delay(TimeSpan.FromSeconds(5), TestContext.CancellationToken); + try { - await Task.Delay(TimeSpan.FromSeconds(5), TestContext.CancellationToken); - try - { - return 2; - } - finally - { - waitException.Set(); + return 2; + } + finally + { + waitException.Set(); #pragma warning disable CA2219 // Do not raise exceptions in finally clauses - throw new InvalidOperationException(); + throw new InvalidOperationException(); #pragma warning restore CA2219 // Do not raise exceptions in finally clauses - } - }).WithCancellationAsync(token)); + } + }).WithCancellationAsync(token); + + cancellationTokenSource.Cancel(); + OperationCanceledException ex = await Assert.ThrowsAsync(async () => await task); Assert.AreEqual(token, ex.CancellationToken); Assert.IsTrue( waitException.WaitOne(TimeSpan.FromSeconds(30)), From b4a9ea15fd20c880b9d366cd3711626bf83525a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Fri, 17 Jul 2026 14:03:06 +0200 Subject: [PATCH 3/3] Suppress synchronous cancellation warning Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: fb77a624-ff12-4dda-849c-882199b9830e --- .../Helpers/TaskExtensionsTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs index 9d34905293e..e7b1189b043 100644 --- a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs +++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/TaskExtensionsTests.cs @@ -111,7 +111,9 @@ public async Task CancellationAsyncWithReturnValue_ObserveException_Succeeds() } }).WithCancellationAsync(token); +#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 ex = await Assert.ThrowsAsync(async () => await task); Assert.AreEqual(token, ex.CancellationToken); Assert.IsTrue(