diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/DuplicateDataRowAnalyzerTests.cs b/test/UnitTests/MSTest.Analyzers.UnitTests/DuplicateDataRowAnalyzerTests.cs index 6e2d7c31ae..1371f88aa7 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/DuplicateDataRowAnalyzerTests.cs +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/DuplicateDataRowAnalyzerTests.cs @@ -402,4 +402,140 @@ public static void TestMethod(int x, int y) NumberOfFixAllInProjectIterations = 2, }.RunAsync(); } + + [TestMethod] + public async Task WhenEnumArgumentIsDuplicated_Diagnostic() + { + string code = """ + using System; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class MyTestClass + { + [TestMethod] + [DataRow(ConsoleColor.Red)] + [[|DataRow(ConsoleColor.Red)|]] + public static void TestMethod(object c) + { + } + } + """; + + await VerifyCS.VerifyAnalyzerAsync(code); + } + + [TestMethod] + public async Task WhenEnumArgumentsAreDifferent_NoDiagnostic() + { + string code = """ + using System; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class MyTestClass + { + [TestMethod] + [DataRow(ConsoleColor.Red)] + [DataRow(ConsoleColor.Blue)] + public static void TestMethod(object c) + { + } + } + """; + + await VerifyCS.VerifyAnalyzerAsync(code); + } + + [TestMethod] + public async Task WhenTypeArgumentIsDuplicated_Diagnostic() + { + string code = """ + using System; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class MyTestClass + { + [TestMethod] + [DataRow(typeof(int))] + [[|DataRow(typeof(int))|]] + public static void TestMethod(Type t) + { + } + } + """; + + await VerifyCS.VerifyAnalyzerAsync(code); + } + + [TestMethod] + public async Task WhenTypeArgumentsAreDifferent_NoDiagnostic() + { + string code = """ + using System; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class MyTestClass + { + [TestMethod] + [DataRow(typeof(int))] + [DataRow(typeof(string))] + public static void TestMethod(Type t) + { + } + } + """; + + await VerifyCS.VerifyAnalyzerAsync(code); + } + + [TestMethod] + public async Task WhenArrayContainsNullElement_SameContent_Diagnostic() + { + // Tests the IsNull && IsNull path within a nested array element comparison. + // Using a typed string[] ensures both null elements share the same element type (string), + // so the comparer reaches the IsNull && IsNull guard instead of short-circuiting on a type mismatch. + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class MyTestClass + { + [TestMethod] + [DataRow(new string[] { null })] + [[|DataRow(new string[] { null })|]] + public static void TestMethod(string[] x) + { + } + } + """; + + await VerifyCS.VerifyAnalyzerAsync(code); + } + + [TestMethod] + public async Task WhenArrayFirstElementNullDiffersFromNonNull_NoDiagnostic() + { + // Tests the asymmetric IsNull || IsNull path: one null element vs one non-null element. + // Using a typed string[] ensures both elements share the same element type (string), + // so the comparer reaches the IsNull || IsNull guard instead of short-circuiting on a type mismatch. + string code = """ + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class MyTestClass + { + [TestMethod] + [DataRow(new string[] { null })] + [DataRow(new string[] { "a" })] + public static void TestMethod(string[] x) + { + } + } + """; + + await VerifyCS.VerifyAnalyzerAsync(code); + } }