|
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 NotFoundTestBuilderTests
|
@@ -426,5 +427,58 @@ public void AndAlsoShouldWorkCorrectly()
|
426 | 427 | TestObjectFactory.GetOutputFormatter(),
|
427 | 428 | new CustomOutputFormatter()));
|
428 | 429 | }
|
| 430 | + |
| 431 | + |
| 432 | + [Fact] |
| 433 | + public void PassingShouldCorrectlyRunItsAssertionFunction() |
| 434 | + { |
| 435 | + MyController<MvcController> |
| 436 | + .Instance() |
| 437 | + .Calling(c => c.FullHttpNotFoundAction()) |
| 438 | + .ShouldReturn() |
| 439 | + .NotFound(notFound => notFound |
| 440 | + .Passing(nf => nf.Formatters?.Count == 2)); |
| 441 | + } |
| 442 | + |
| 443 | + [Fact] |
| 444 | + public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion() |
| 445 | + { |
| 446 | + Test.AssertException<InvocationResultAssertionException>( |
| 447 | + () => |
| 448 | + { |
| 449 | + MyController<MvcController> |
| 450 | + .Instance() |
| 451 | + .Calling(c => c.FullHttpNotFoundAction()) |
| 452 | + .ShouldReturn() |
| 453 | + .NotFound(notFound => notFound |
| 454 | + .Passing(nf => nf.Formatters?.Count == 0)); |
| 455 | + }, |
| 456 | + $"When calling {nameof(MvcController.FullHttpNotFoundAction)} " + |
| 457 | + $"action in {nameof(MvcController)} expected the NotFoundObjectResult to pass the given predicate, but it failed."); |
| 458 | + } |
| 459 | + |
| 460 | + [Fact] |
| 461 | + public void PassingShouldCorrectlyRunItsAssertionAction() |
| 462 | + { |
| 463 | + MyController<MvcController> |
| 464 | + .Instance() |
| 465 | + .Calling(c => c.FullHttpNotFoundAction()) |
| 466 | + .ShouldReturn() |
| 467 | + .NotFound(notFound => notFound |
| 468 | + .Passing(nf => |
| 469 | + { |
| 470 | + const int actualFormattersCount = 2; |
| 471 | + var expectedFormattersCount = nf.Formatters?.Count; |
| 472 | + if (expectedFormattersCount != actualFormattersCount) |
| 473 | + { |
| 474 | + throw new InvalidAssertionException( |
| 475 | + string.Format("Expected {0} to have {1} {2}, but it has {3}.", |
| 476 | + nf.GetType().ToFriendlyTypeName(), |
| 477 | + actualFormattersCount, |
| 478 | + nameof(nf.Formatters), |
| 479 | + expectedFormattersCount)); |
| 480 | + }; |
| 481 | + })); |
| 482 | + } |
429 | 483 | }
|
430 | 484 | }
|
0 commit comments