|
7 | 7 | using System.Linq.Expressions;
|
8 | 8 | using System.Reflection;
|
9 | 9 | using System.Text;
|
| 10 | +using System.Text.RegularExpressions; |
10 | 11 | using Moq;
|
11 | 12 | using Moq.Properties;
|
12 | 13 | using Moq.Protected;
|
@@ -175,6 +176,64 @@ public void DoTest()
|
175 | 176 | #endif
|
176 | 177 | #endregion
|
177 | 178 |
|
| 179 | + #region #176 |
| 180 | + |
| 181 | + public class Issue176 |
| 182 | + { |
| 183 | + public interface ISomeInterface |
| 184 | + { |
| 185 | + TResult DoSomething<TResult>(int anInt); |
| 186 | + int DoSomethingElse(int anInt); |
| 187 | + } |
| 188 | + |
| 189 | + [Fact] |
| 190 | + public void when_a_mock_doesnt_match_generic_parameters_exception_indicates_generic_parameters() |
| 191 | + { |
| 192 | + var mock = new Mock<ISomeInterface>(MockBehavior.Strict); |
| 193 | + mock.Setup(m => m.DoSomething<int>(0)).Returns(1); |
| 194 | + |
| 195 | + try |
| 196 | + { |
| 197 | + mock.Object.DoSomething<string>(0); |
| 198 | + } |
| 199 | + catch (MockException exception) |
| 200 | + { |
| 201 | + var genericTypesRE = new Regex(@"\<.*?\>"); |
| 202 | + var match = genericTypesRE.Match(exception.Message); |
| 203 | + |
| 204 | + Assert.True(match.Success); |
| 205 | + Assert.Equal("<string>", match.Captures[0].Value, StringComparer.OrdinalIgnoreCase); |
| 206 | + return; |
| 207 | + } |
| 208 | + |
| 209 | + Assert.True(false, "No exception was thrown when one should have been"); |
| 210 | + } |
| 211 | + |
| 212 | + [Fact] |
| 213 | + public void when_a_method_doesnt_have_generic_parameters_exception_doesnt_include_brackets() |
| 214 | + { |
| 215 | + var mock = new Mock<ISomeInterface>(MockBehavior.Strict); |
| 216 | + mock.Setup(m => m.DoSomething<int>(0)).Returns(1); |
| 217 | + |
| 218 | + try |
| 219 | + { |
| 220 | + mock.Object.DoSomethingElse(0); |
| 221 | + } |
| 222 | + catch (MockException exception) |
| 223 | + { |
| 224 | + var genericTypesRE = new Regex(@"\<.*?\>"); |
| 225 | + var match = genericTypesRE.Match(exception.Message); |
| 226 | + |
| 227 | + Assert.False(match.Success); |
| 228 | + return; |
| 229 | + } |
| 230 | + |
| 231 | + Assert.True(false, "No exception was thrown when one should have been"); |
| 232 | + } |
| 233 | + } |
| 234 | + |
| 235 | + #endregion // #176 |
| 236 | + |
178 | 237 | // Old @ Google Code
|
179 | 238 |
|
180 | 239 | #region #47
|
|
0 commit comments