|
8 | 8 | using Setups;
|
9 | 9 | using Setups.Common;
|
10 | 10 | using Setups.Controllers;
|
| 11 | + using Utilities; |
11 | 12 | using Xunit;
|
12 | 13 |
|
13 | 14 | public class BadRequestTestBuilderTests
|
@@ -507,5 +508,57 @@ public void AndAlsoShouldWorkCorrectly()
|
507 | 508 | TestObjectFactory.GetOutputFormatter(),
|
508 | 509 | new CustomOutputFormatter()));
|
509 | 510 | }
|
| 511 | + |
| 512 | + [Fact] |
| 513 | + public void PassingShouldCorrectlyRunItsAssertionFunction() |
| 514 | + { |
| 515 | + MyController<MvcController> |
| 516 | + .Instance() |
| 517 | + .Calling(c => c.FullHttpBadRequestAction()) |
| 518 | + .ShouldReturn() |
| 519 | + .BadRequest(badRequest => badRequest |
| 520 | + .Passing(br => br.Formatters?.Count == 2)); |
| 521 | + } |
| 522 | + |
| 523 | + [Fact] |
| 524 | + public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion() |
| 525 | + { |
| 526 | + Test.AssertException<InvocationResultAssertionException>( |
| 527 | + () => |
| 528 | + { |
| 529 | + MyController<MvcController> |
| 530 | + .Instance() |
| 531 | + .Calling(c => c.FullHttpBadRequestAction()) |
| 532 | + .ShouldReturn() |
| 533 | + .BadRequest(badRequest => badRequest |
| 534 | + .Passing(br => br.Formatters?.Count == 0)); |
| 535 | + }, |
| 536 | + $"When calling {nameof(MvcController.FullHttpBadRequestAction)} " + |
| 537 | + $"action in {nameof(MvcController)} expected the BadRequestObjectResult to pass the given predicate, but it failed."); |
| 538 | + } |
| 539 | + |
| 540 | + [Fact] |
| 541 | + public void PassingShouldCorrectlyRunItsAssertionAction() |
| 542 | + { |
| 543 | + MyController<MvcController> |
| 544 | + .Instance() |
| 545 | + .Calling(c => c.FullHttpBadRequestAction()) |
| 546 | + .ShouldReturn() |
| 547 | + .BadRequest(badRequest => badRequest |
| 548 | + .Passing(br => |
| 549 | + { |
| 550 | + const int expectedFormattersCount = 2; |
| 551 | + var actualFormattersCount = br.Formatters?.Count; |
| 552 | + if (actualFormattersCount != expectedFormattersCount) |
| 553 | + { |
| 554 | + throw new InvalidAssertionException( |
| 555 | + string.Format("Expected {0} to have {1} {2}, but it has {3}.", |
| 556 | + br.GetType().ToFriendlyTypeName(), |
| 557 | + expectedFormattersCount, |
| 558 | + nameof(br.Formatters), |
| 559 | + actualFormattersCount)); |
| 560 | + }; |
| 561 | + })); |
| 562 | + } |
510 | 563 | }
|
511 | 564 | }
|
0 commit comments