@@ -14,6 +14,7 @@ public sealed class StringAssertToAssertAnalyzerTests
1414 public async Task WhenStringAssertContains ( )
1515 {
1616 string code = """
17+ using System;
1718 using Microsoft.VisualStudio.TestTools.UnitTesting;
1819
1920 [TestClass]
@@ -25,11 +26,17 @@ public void MyTestMethod()
2526 string value = "Hello World";
2627 string substring = "World";
2728 {|#0:StringAssert.Contains(value, substring)|};
29+ {|#1:StringAssert.Contains(value, substring, "message")|};
30+ {|#2:StringAssert.Contains(value, substring, StringComparison.Ordinal)|};
31+ {|#3:StringAssert.Contains(value, substring, "message", StringComparison.Ordinal)|};
32+ {|#4:StringAssert.Contains(value, substring, "message {0}", "arg")|};
33+ {|#5:StringAssert.Contains(value, substring, "message {0}", StringComparison.Ordinal, "arg")|};
2834 }
2935 }
3036 """ ;
3137
3238 string fixedCode = """
39+ using System;
3340 using Microsoft.VisualStudio.TestTools.UnitTesting;
3441
3542 [TestClass]
@@ -41,14 +48,31 @@ public void MyTestMethod()
4148 string value = "Hello World";
4249 string substring = "World";
4350 Assert.Contains(substring, value);
51+ Assert.Contains(substring, value, "message");
52+ Assert.Contains(substring, value, StringComparison.Ordinal);
53+ Assert.Contains(substring, value, StringComparison.Ordinal, "message");
54+ Assert.Contains(substring, value, "message {0}", "arg");
55+ Assert.Contains(substring, value, StringComparison.Ordinal, "message {0}", "arg");
4456 }
4557 }
4658 """ ;
4759
4860 await VerifyCS . VerifyCodeFixAsync (
4961 code ,
50- // /0/Test0.cs(11,9): info MSTEST0046: Use 'Assert.Contains' instead of 'StringAssert.Contains'
51- VerifyCS . DiagnosticIgnoringAdditionalLocations ( ) . WithLocation ( 0 ) . WithArguments ( "Contains" , "Contains" ) ,
62+ [
63+ // /0/Test0.cs(12,9): info MSTEST0046: Use 'Assert.Contains' instead of 'StringAssert.Contains'
64+ VerifyCS . DiagnosticIgnoringAdditionalLocations ( ) . WithLocation ( 0 ) . WithArguments ( "Contains" , "Contains" ) ,
65+ // /0/Test0.cs(13,9): info MSTEST0046: Use 'Assert.Contains' instead of 'StringAssert.Contains'
66+ VerifyCS . DiagnosticIgnoringAdditionalLocations ( ) . WithLocation ( 1 ) . WithArguments ( "Contains" , "Contains" ) ,
67+ // /0/Test0.cs(14,9): info MSTEST0046: Use 'Assert.Contains' instead of 'StringAssert.Contains'
68+ VerifyCS . DiagnosticIgnoringAdditionalLocations ( ) . WithLocation ( 2 ) . WithArguments ( "Contains" , "Contains" ) ,
69+ // /0/Test0.cs(15,9): info MSTEST0046: Use 'Assert.Contains' instead of 'StringAssert.Contains'
70+ VerifyCS . DiagnosticIgnoringAdditionalLocations ( ) . WithLocation ( 3 ) . WithArguments ( "Contains" , "Contains" ) ,
71+ // /0/Test0.cs(16,9): info MSTEST0046: Use 'Assert.Contains' instead of 'StringAssert.Contains'
72+ VerifyCS . DiagnosticIgnoringAdditionalLocations ( ) . WithLocation ( 4 ) . WithArguments ( "Contains" , "Contains" ) ,
73+ // /0/Test0.cs(17,9): info MSTEST0046: Use 'Assert.Contains' instead of 'StringAssert.Contains'
74+ VerifyCS . DiagnosticIgnoringAdditionalLocations ( ) . WithLocation ( 5 ) . WithArguments ( "Contains" , "Contains" ) ,
75+ ] ,
5276 fixedCode ) ;
5377 }
5478
0 commit comments