@@ -10,8 +10,10 @@ namespace PosInformatique.Moq.Analyzers.Tests
1010
1111 public class CallBackDelegateMustMatchMockedMethodAnalyzerTest
1212 {
13- [ Fact ]
14- public async Task CallBackSignatureMatch_NoDiagnosticReported ( )
13+ [ Theory ]
14+ [ InlineData ( "" ) ]
15+ [ InlineData ( ".InSequence(sequence)" ) ]
16+ public async Task CallBackSignatureMatch_NoDiagnosticReported ( string sequence )
1517 {
1618 var source = @"
1719 namespace ConsoleApplication1
@@ -23,31 +25,33 @@ public class TestClass
2325 {
2426 public void TestMethod()
2527 {
28+ var sequence = new MockSequence();
29+
2630 var mock1 = new Mock<I>();
2731
28- mock1.Setup(m => m.TestMethod())
32+ mock1" + sequence + @" .Setup(m => m.TestMethod())
2933 .Callback(() => { })
3034 .Throws(new Exception());
31- mock1.Setup(m => m.TestMethod(default))
35+ mock1" + sequence + @" .Setup(m => m.TestMethod(default))
3236 .Callback((string x) => { })
3337 .Throws(new Exception());
34- mock1.Setup(m => m.TestMethod(default, default))
38+ mock1" + sequence + @" .Setup(m => m.TestMethod(default, default))
3539 .Callback((string x, int y) => { })
3640 .Throws(new Exception());
37- mock1.Setup(m => m.TestGenericMethod(1234))
41+ mock1" + sequence + @" .Setup(m => m.TestGenericMethod(1234))
3842 .Callback((int x) => { })
3943 .Throws(new Exception());
40- mock1.Setup(m => m.TestGenericMethod(It.IsAny<It.IsAnyType>()))
44+ mock1" + sequence + @" .Setup(m => m.TestGenericMethod(It.IsAny<It.IsAnyType>()))
4145 .Callback((object x) => { })
4246 .Throws(new Exception());
4347
44- mock1.Setup(m => m.TestMethodReturn())
48+ mock1" + sequence + @" .Setup(m => m.TestMethodReturn())
4549 .Callback(() => { })
4650 .Returns(1234);
47- mock1.Setup(m => m.TestMethodReturn(default))
51+ mock1" + sequence + @" .Setup(m => m.TestMethodReturn(default))
4852 .Callback((string x) => { })
4953 .Returns(1234);
50- mock1.Setup(m => m.TestMethodReturn(default, default))
54+ mock1" + sequence + @" .Setup(m => m.TestMethodReturn(default, default))
5155 .Callback((string x, int y) => { })
5256 .Returns(1234);
5357
@@ -80,8 +84,10 @@ public interface I
8084 await Verifier . VerifyAnalyzerAsync ( source ) ;
8185 }
8286
83- [ Fact ]
84- public async Task CallBackSignatureNotMatch_DiagnosticReported ( )
87+ [ Theory ]
88+ [ InlineData ( "" ) ]
89+ [ InlineData ( ".InSequence(sequence)" ) ]
90+ public async Task CallBackSignatureNotMatch_DiagnosticReported ( string sequence )
8591 {
8692 var source = @"
8793 namespace ConsoleApplication1
@@ -93,37 +99,39 @@ public class TestClass
9399 {
94100 public void TestMethod()
95101 {
102+ var sequence = new MockSequence();
103+
96104 var mock1 = new Mock<I>();
97105
98- mock1.Setup(m => m.TestMethod())
106+ mock1" + sequence + @" .Setup(m => m.TestMethod())
99107 .Callback([|(int too, int much, int parameters)|] => { })
100108 .Throws(new Exception());
101- mock1.Setup(m => m.TestMethod(default))
109+ mock1" + sequence + @" .Setup(m => m.TestMethod(default))
102110 .Callback([|()|] => { })
103111 .Throws(new Exception());
104- mock1.Setup(m => m.TestMethod(default))
112+ mock1" + sequence + @" .Setup(m => m.TestMethod(default))
105113 .Callback(([|int otherType|]) => { })
106114 .Throws(new Exception());
107- mock1.Setup(m => m.TestMethod(default))
115+ mock1" + sequence + @" .Setup(m => m.TestMethod(default))
108116 .Callback([|(int too, int much, int parameters)|] => { })
109117 .Throws(new Exception());
110- mock1.Setup(m => m.TestGenericMethod(1234))
118+ mock1" + sequence + @" .Setup(m => m.TestGenericMethod(1234))
111119 .Callback(([|string x|]) => { })
112120 .Throws(new Exception());
113- mock1.Setup(m => m.TestGenericMethod(It.IsAny<It.IsAnyType>()))
121+ mock1" + sequence + @" .Setup(m => m.TestGenericMethod(It.IsAny<It.IsAnyType>()))
114122 .Callback(([|string x|]) => { })
115123 .Throws(new Exception());
116124
117- mock1.Setup(m => m.TestMethodReturn())
125+ mock1" + sequence + @" .Setup(m => m.TestMethodReturn())
118126 .Callback([|(int too, int much, int parameters)|] => { })
119127 .Returns(1234);
120- mock1.Setup(m => m.TestMethodReturn(default))
128+ mock1" + sequence + @" .Setup(m => m.TestMethodReturn(default))
121129 .Callback([|()|] => { })
122130 .Returns(1234);
123- mock1.Setup(m => m.TestMethodReturn(default))
131+ mock1" + sequence + @" .Setup(m => m.TestMethodReturn(default))
124132 .Callback(([|int otherType|]) => { })
125133 .Returns(1234);
126- mock1.Setup(m => m.TestMethodReturn(default))
134+ mock1" + sequence + @" .Setup(m => m.TestMethodReturn(default))
127135 .Callback([|(int too, int much, int parameters)|] => { })
128136 .Returns(1234);
129137 }
0 commit comments