|
17 | 17 | - [BadRequest result](#badrequest-result)
|
18 | 18 | - [JSON result](#json-result)
|
19 | 19 | - [StatusCode result](#statuscode-result)
|
| 20 | + - [Redirect result](#redirect-result) |
| 21 | + - [Created result](#created-result) |
20 | 22 | - [NotFound result](#notfound-result)
|
21 | 23 | - [Conflict result](#conflict-result)
|
22 | 24 | - [EmptyContent (void) result](#emptycontent-void-result)
|
| 25 | + - [Null or Default result](#null-or-default-result) |
23 | 26 | - [AndProvide... methods](#andprovide-methods)
|
24 | 27 |
|
25 | 28 | ### Controller instantiation
|
@@ -177,6 +180,12 @@ MyWebApi
|
177 | 180 | .ContainingModelStateErrorFor(m => m.ThirdProperty).EndingWith("message")
|
178 | 181 | .AndAlso() // error must contain the provided string
|
179 | 182 | .ContainingModelStateErrorFor(m => m.SecondProperty).Containing("ror mes");
|
| 183 | + |
| 184 | +// disable validation if needed |
| 185 | +MyWebApi |
| 186 | + .Controller<WebApiController>() |
| 187 | + .WithoutValidation() |
| 188 | + .Calling(c => c.SomeAction()); |
180 | 189 | ```
|
181 | 190 |
|
182 | 191 | [To top](#table-of-contents)
|
@@ -645,6 +654,221 @@ MyWebApi
|
645 | 654 | .StatusCode(HttpStatusCode.Created);
|
646 | 655 | ```
|
647 | 656 |
|
| 657 | +[To top](#table-of-contents) |
| 658 | + |
| 659 | +#### Redirect result |
| 660 | + |
| 661 | +```c# |
| 662 | +// tests whether the action returns |
| 663 | +// RedirectResult or RedirectToRouteResult |
| 664 | +MyWebApi |
| 665 | + .Controller<WebApiController>() |
| 666 | + .Calling(c => c.SomeAction()) |
| 667 | + .ShouldReturn() |
| 668 | + .Redirect(); |
| 669 | + |
| 670 | +// tests whether the action returns redirect result |
| 671 | +// with location provided as string |
| 672 | +MyWebApi |
| 673 | + .Controller<WebApiController>() |
| 674 | + .Calling(c => c.SomeAction()) |
| 675 | + .ShouldReturn() |
| 676 | + .Redirect() |
| 677 | + .AtLocation("http://somehost.com/someuri/1?query=someQuery"); |
| 678 | + |
| 679 | +// tests whether the action returns redirect result |
| 680 | +// with location provided as URI |
| 681 | +MyWebApi |
| 682 | + .Controller<WebApiController>() |
| 683 | + .Calling(c => c.SomeAction()) |
| 684 | + .ShouldReturn() |
| 685 | + .Redirect() |
| 686 | + .AtLocation(someUri); |
| 687 | + |
| 688 | +// tests whether the action returns redirect result |
| 689 | +// with location provided as URI builder |
| 690 | +MyWebApi |
| 691 | + .Controller<WebApiController>() |
| 692 | + .Calling(c => c.SomeAction()) |
| 693 | + .ShouldReturn() |
| 694 | + .Redirect() |
| 695 | + .AtLocation( |
| 696 | + location => |
| 697 | + location |
| 698 | + .WithHost("somehost.com") |
| 699 | + .AndAlso() // AndAlso is not necessary |
| 700 | + .WithAbsolutePath("/someuri/1") |
| 701 | + .AndAlso() |
| 702 | + .WithPort(80) |
| 703 | + .AndAlso() |
| 704 | + .WithScheme("http") |
| 705 | + .AndAlso() |
| 706 | + .WithFragment(string.Empty) |
| 707 | + .AndAlso() |
| 708 | + .WithQuery("?query=Test")); |
| 709 | +``` |
| 710 | + |
| 711 | +[To top](#table-of-contents) |
| 712 | + |
| 713 | +#### Created result |
| 714 | + |
| 715 | +```c# |
| 716 | +// tests whether the action returns |
| 717 | +// CreatedNegotiatedContentResult<T> |
| 718 | +// or CreatedAtRouteNegotiatedContentResult<T> |
| 719 | +MyWebApi |
| 720 | + .Controller<WebApiController>() |
| 721 | + .Calling(c => c.SomeAction()) |
| 722 | + .ShouldReturn() |
| 723 | + .Created(); |
| 724 | + |
| 725 | +// tests whether the action returns created result |
| 726 | +// with DefaultContentNegotiator |
| 727 | +MyWebApi |
| 728 | + .Controller<WebApiController>() |
| 729 | + .Calling(c => c.SomeAction()) |
| 730 | + .ShouldReturn() |
| 731 | + .Created() |
| 732 | + .WithDefaultContentNegotiator(); |
| 733 | + |
| 734 | +// tests whether the action returns created result |
| 735 | +// with custom IContentNegotiator provided by instance |
| 736 | +MyWebApi |
| 737 | + .Controller<WebApiController>() |
| 738 | + .Calling(c => c.SomeAction()) |
| 739 | + .ShouldReturn() |
| 740 | + .Created() |
| 741 | + .WithContentNegotiator(customContentNegotiator); |
| 742 | + |
| 743 | +// tests whether the action returns created result |
| 744 | +// with custom IContentNegotiator provided by generic definition |
| 745 | +MyWebApi |
| 746 | + .Controller<WebApiController>() |
| 747 | + .Calling(c => c.SomeAction()) |
| 748 | + .ShouldReturn() |
| 749 | + .Created() |
| 750 | + .WithContentNegotiatorOfType<CustomContentNegotiator>(); |
| 751 | + |
| 752 | +// tests whether the action returns created result |
| 753 | +// with location provided as string |
| 754 | +MyWebApi |
| 755 | + .Controller<WebApiController>() |
| 756 | + .Calling(c => c.SomeAction()) |
| 757 | + .ShouldReturn() |
| 758 | + .Created() |
| 759 | + .AtLocation("http://somehost.com/someuri/1?query=someQuery"); |
| 760 | + |
| 761 | +// tests whether the action returns created result |
| 762 | +// with location provided as URI |
| 763 | +MyWebApi |
| 764 | + .Controller<WebApiController>() |
| 765 | + .Calling(c => c.SomeAction()) |
| 766 | + .ShouldReturn() |
| 767 | + .Created() |
| 768 | + .AtLocation(someUri); |
| 769 | + |
| 770 | +// tests whether the action returns created result |
| 771 | +// with location provided as URI builder |
| 772 | +MyWebApi |
| 773 | + .Controller<WebApiController>() |
| 774 | + .Calling(c => c.SomeAction()) |
| 775 | + .ShouldReturn() |
| 776 | + .Created() |
| 777 | + .AtLocation( |
| 778 | + location => |
| 779 | + location |
| 780 | + .WithHost("somehost.com") |
| 781 | + .AndAlso() // AndAlso is not necessary |
| 782 | + .WithAbsolutePath("/someuri/1") |
| 783 | + .AndAlso() |
| 784 | + .WithPort(80) |
| 785 | + .AndAlso() |
| 786 | + .WithScheme("http") |
| 787 | + .AndAlso() |
| 788 | + .WithFragment(string.Empty) |
| 789 | + .AndAlso() |
| 790 | + .WithQuery("?query=Test")); |
| 791 | + |
| 792 | +// tests whether the action returns created result |
| 793 | +// with exactly the default media type formatters |
| 794 | +MyWebApi |
| 795 | + .Controller<WebApiController>() |
| 796 | + .Calling(c => c.SomeAction()) |
| 797 | + .ShouldReturn() |
| 798 | + .Created() |
| 799 | + .ContainingDefaultFormatters(); |
| 800 | + |
| 801 | +// tests whether the action returns created result |
| 802 | +// containing media type formatter provided by instance |
| 803 | +MyWebApi |
| 804 | + .Controller<WebApiController>() |
| 805 | + .Calling(c => c.SomeAction()) |
| 806 | + .ShouldReturn() |
| 807 | + .Created() |
| 808 | + .ContainingMediaTypeFormatter(someMediaTypeFormatter); |
| 809 | + |
| 810 | +// tests whether the action returns created result |
| 811 | +// containing media type formatter provided by generic definition |
| 812 | +MyWebApi |
| 813 | + .Controller<WebApiController>() |
| 814 | + .Calling(c => c.SomeAction()) |
| 815 | + .ShouldReturn() |
| 816 | + .Created() |
| 817 | + .ContainingMediaTypeFormatterOfType<JsonMediaTypeFormatter>(); |
| 818 | + |
| 819 | +// tests whether the action returns created result |
| 820 | +// with exactly the provided media type formatters |
| 821 | +MyWebApi |
| 822 | + .Controller<WebApiController>() |
| 823 | + .Calling(c => c.SomeAction()) |
| 824 | + .ShouldReturn() |
| 825 | + .Created() |
| 826 | + .ContainingMediaTypeFormatters(someCollectionOfMediaTypeFormatters); |
| 827 | + |
| 828 | +// tests whether the action returns created result |
| 829 | +// with exactly the provided media type formatters |
| 830 | +// by using params |
| 831 | +MyWebApi |
| 832 | + .Controller<WebApiController>() |
| 833 | + .Calling(c => c.SomeAction()) |
| 834 | + .ShouldReturn() |
| 835 | + .Created() |
| 836 | + .ContainingMediaTypeFormatters( |
| 837 | + someMediaTypeFormatter, |
| 838 | + anotherMediaTypeFormatter, |
| 839 | + yetAnotherMediaTypeFormatter); |
| 840 | + |
| 841 | +// tests whether the action returns created result |
| 842 | +// with exactly the provided media type formatters |
| 843 | +// by using formatters builder |
| 844 | +MyWebApi |
| 845 | + .Controller<WebApiController>() |
| 846 | + .Calling(c => c.SomeAction()) |
| 847 | + .ShouldReturn() |
| 848 | + .Created() |
| 849 | + .ContainingMediaTypeFormatters( |
| 850 | + formatters => |
| 851 | + formatters |
| 852 | + .ContainingMediaTypeFormatter(someMediaTypeFormatter) |
| 853 | + .AndAlso() |
| 854 | + .ContainingMediaTypeFormatterOfType<SomeMediaTypeFormatter>()); |
| 855 | + |
| 856 | +// tests whether the action returns created result |
| 857 | +// with different types of properties by using AndAlso() |
| 858 | +MyWebApi |
| 859 | + .Controller<WebApiController>() |
| 860 | + .Calling(c => c.CreatedActionWithCustomContentNegotiator()) |
| 861 | + .ShouldReturn() |
| 862 | + .Created() |
| 863 | + .WithDefaultContentNegotiator() |
| 864 | + .AndAlso() // AndAlso is not necessary |
| 865 | + .AtLocation(someUri) |
| 866 | + .AndAlso() |
| 867 | + .ContainingMediaTypeFormatterOfType<SomeMediaTypeFormatter>(); |
| 868 | +``` |
| 869 | + |
| 870 | +[To top](#table-of-contents) |
| 871 | + |
648 | 872 | #### NotFound result
|
649 | 873 | ```c#
|
650 | 874 | // tests whether the action returns NotFoundResult
|
@@ -761,6 +985,25 @@ MyWebApi
|
761 | 985 |
|
762 | 986 | [To top](#table-of-contents)
|
763 | 987 |
|
| 988 | +#### Null or Default result |
| 989 | +```c# |
| 990 | +// tests whether the action returns the default value of the return type |
| 991 | +MyWebApi |
| 992 | + .Controller<WebApiController>() |
| 993 | + .Calling(c => c.SomeAction()) |
| 994 | + .ShouldReturn() |
| 995 | + .DefaultValue(); |
| 996 | + |
| 997 | +// tests whether the action returns null |
| 998 | +MyWebApi |
| 999 | + .Controller<WebApiController>() |
| 1000 | + .Calling(c => c.SomeAction()) |
| 1001 | + .ShouldReturn() |
| 1002 | + .Null(); |
| 1003 | +``` |
| 1004 | + |
| 1005 | +[To top](#table-of-contents) |
| 1006 | + |
764 | 1007 | ### AndProvide... methods
|
765 | 1008 |
|
766 | 1009 | You can get controller, action, action result and response model information where applicable by using AndProvide... methods.
|
|
0 commit comments