|
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 RedirectTestBuilderTests
|
@@ -541,5 +542,58 @@ public void AndAlsoShouldWorkCorrectly()
|
541 | 542 | .AndAlso()
|
542 | 543 | .ToController("MyController"));
|
543 | 544 | }
|
| 545 | + |
| 546 | + |
| 547 | + [Fact] |
| 548 | + public void PassingShouldCorrectlyRunItsAssertionFunction() |
| 549 | + { |
| 550 | + MyController<MvcController> |
| 551 | + .Instance() |
| 552 | + .Calling(c => c.RedirectToActionResult()) |
| 553 | + .ShouldReturn() |
| 554 | + .Redirect(redirect => redirect |
| 555 | + .Passing(r => r.ActionName == "MyAction")); |
| 556 | + } |
| 557 | + |
| 558 | + [Fact] |
| 559 | + public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion() |
| 560 | + { |
| 561 | + Test.AssertException<InvocationResultAssertionException>( |
| 562 | + () => |
| 563 | + { |
| 564 | + MyController<MvcController> |
| 565 | + .Instance() |
| 566 | + .Calling(c => c.RedirectToActionResult()) |
| 567 | + .ShouldReturn() |
| 568 | + .Redirect(redirect => redirect |
| 569 | + .Passing(r => r.ActionName == string.Empty)); |
| 570 | + }, |
| 571 | + $"When calling {nameof(MvcController.RedirectToActionResult)} " + |
| 572 | + $"action in {nameof(MvcController)} expected the RedirectToActionResult to pass the given predicate, but it failed."); |
| 573 | + } |
| 574 | + |
| 575 | + [Fact] |
| 576 | + public void PassingShouldCorrectlyRunItsAssertionAction() |
| 577 | + { |
| 578 | + MyController<MvcController> |
| 579 | + .Instance() |
| 580 | + .Calling(c => c.RedirectToActionResult()) |
| 581 | + .ShouldReturn() |
| 582 | + .Redirect(redirect => redirect |
| 583 | + .Passing(r => |
| 584 | + { |
| 585 | + const string expectedActionName = "MyAction"; |
| 586 | + var actualActionName = r.ActionName; |
| 587 | + if (actualActionName != expectedActionName) |
| 588 | + { |
| 589 | + throw new InvalidAssertionException( |
| 590 | + string.Format("Expected {0} to have {1} equal to {2}, but it was {3}.", |
| 591 | + r.GetType().ToFriendlyTypeName(), |
| 592 | + nameof(r.ActionName), |
| 593 | + expectedActionName, |
| 594 | + actualActionName)); |
| 595 | + }; |
| 596 | + })); |
| 597 | + } |
544 | 598 | }
|
545 | 599 | }
|
0 commit comments