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