|
6 | 6 | using Setups;
|
7 | 7 | using Setups.Common;
|
8 | 8 | using Setups.Controllers;
|
| 9 | + using Utilities; |
9 | 10 | using Xunit;
|
10 | 11 |
|
11 | 12 | public class LocalRedirectTestBuilderTests
|
@@ -251,5 +252,58 @@ public void AndAlsoShouldWorkCorrectly()
|
251 | 252 | .AndAlso()
|
252 | 253 | .ToUrl("/local/test"));
|
253 | 254 | }
|
| 255 | + |
| 256 | + |
| 257 | + [Fact] |
| 258 | + public void PassingShouldCorrectlyRunItsAssertionFunction() |
| 259 | + { |
| 260 | + MyController<MvcController> |
| 261 | + .Instance() |
| 262 | + .Calling(c => c.LocalRedirectAction()) |
| 263 | + .ShouldReturn() |
| 264 | + .LocalRedirect(localRedirect => localRedirect |
| 265 | + .Passing(lr => lr.Url == "/local/test")); |
| 266 | + } |
| 267 | + |
| 268 | + [Fact] |
| 269 | + public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion() |
| 270 | + { |
| 271 | + Test.AssertException<InvocationResultAssertionException>( |
| 272 | + () => |
| 273 | + { |
| 274 | + MyController<MvcController> |
| 275 | + .Instance() |
| 276 | + .Calling(c => c.LocalRedirectAction()) |
| 277 | + .ShouldReturn() |
| 278 | + .LocalRedirect(localRedirect => localRedirect |
| 279 | + .Passing(lr => lr.Url == string.Empty)); |
| 280 | + }, |
| 281 | + $"When calling {nameof(MvcController.LocalRedirectAction)} " + |
| 282 | + $"action in {nameof(MvcController)} expected the LocalRedirectResult to pass the given predicate, but it failed."); |
| 283 | + } |
| 284 | + |
| 285 | + [Fact] |
| 286 | + public void PassingShouldCorrectlyRunItsAssertionAction() |
| 287 | + { |
| 288 | + MyController<MvcController> |
| 289 | + .Instance() |
| 290 | + .Calling(c => c.LocalRedirectAction()) |
| 291 | + .ShouldReturn() |
| 292 | + .LocalRedirect(localRedirect => localRedirect |
| 293 | + .Passing(lr => |
| 294 | + { |
| 295 | + const string expectedRedirect = "/local/test"; |
| 296 | + var actualRedirect = lr.Url; |
| 297 | + if (expectedRedirect != actualRedirect) |
| 298 | + { |
| 299 | + throw new InvalidAssertionException( |
| 300 | + string.Format("Expected {0} to have {1} equal to {2}, but it was {3}.", |
| 301 | + lr.GetType().ToFriendlyTypeName(), |
| 302 | + nameof(lr.Url), |
| 303 | + expectedRedirect, |
| 304 | + actualRedirect)); |
| 305 | + }; |
| 306 | + })); |
| 307 | + } |
254 | 308 | }
|
255 | 309 | }
|
0 commit comments