|
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 StatusCodeTestBuilderTests
|
@@ -409,5 +410,58 @@ public void AndProvideTheActionResultShouldWorkCorrectly()
|
409 | 410 | Assert.IsAssignableFrom<ObjectResult>(actionResult);
|
410 | 411 | }));
|
411 | 412 | }
|
| 413 | + |
| 414 | + |
| 415 | + [Fact] |
| 416 | + public void PassingShouldCorrectlyRunItsAssertionFunction() |
| 417 | + { |
| 418 | + MyController<MvcController> |
| 419 | + .Instance() |
| 420 | + .Calling(c => c.FullObjectResultAction()) |
| 421 | + .ShouldReturn() |
| 422 | + .StatusCode(result => result |
| 423 | + .Passing(r => r.Formatters?.Count == 2)); |
| 424 | + } |
| 425 | + |
| 426 | + [Fact] |
| 427 | + public void PassingShouldThrowAnExceptionOnAnIncorrectAssertion() |
| 428 | + { |
| 429 | + Test.AssertException<InvocationResultAssertionException>( |
| 430 | + () => |
| 431 | + { |
| 432 | + MyController<MvcController> |
| 433 | + .Instance() |
| 434 | + .Calling(c => c.FullObjectResultAction()) |
| 435 | + .ShouldReturn() |
| 436 | + .StatusCode(result => result |
| 437 | + .Passing(r => r.Formatters?.Count == 0)); |
| 438 | + }, |
| 439 | + $"When calling {nameof(MvcController.FullObjectResultAction)} " + |
| 440 | + $"action in {nameof(MvcController)} expected the ObjectResult to pass the given predicate, but it failed."); |
| 441 | + } |
| 442 | + |
| 443 | + [Fact] |
| 444 | + public void PassingShouldCorrectlyRunItsAssertionAction() |
| 445 | + { |
| 446 | + MyController<MvcController> |
| 447 | + .Instance() |
| 448 | + .Calling(c => c.FullObjectResultAction()) |
| 449 | + .ShouldReturn() |
| 450 | + .StatusCode(result => result |
| 451 | + .Passing(r => |
| 452 | + { |
| 453 | + const int expectedFormattersCount = 2; |
| 454 | + var actualFormattersCount = r.Formatters?.Count; |
| 455 | + if (actualFormattersCount != expectedFormattersCount) |
| 456 | + { |
| 457 | + throw new InvalidAssertionException( |
| 458 | + string.Format("Expected {0} to have {1} {2}, but it has {3}.", |
| 459 | + r.GetType().ToFriendlyTypeName(), |
| 460 | + expectedFormattersCount, |
| 461 | + nameof(r.Formatters), |
| 462 | + actualFormattersCount)); |
| 463 | + }; |
| 464 | + })); |
| 465 | + } |
412 | 466 | }
|
413 | 467 | }
|
0 commit comments