|
18 | 18 | - [JSON result](#json-result) |
19 | 19 | - [StatusCode result](#statuscode-result) |
20 | 20 | - [Redirect result](#redirect-result) |
| 21 | + - [Content result](#content-result) |
21 | 22 | - [Created result](#created-result) |
22 | 23 | - [NotFound result](#notfound-result) |
23 | 24 | - [Conflict result](#conflict-result) |
@@ -820,6 +821,162 @@ MyWebApi |
820 | 821 |
|
821 | 822 | [To top](#table-of-contents) |
822 | 823 |
|
| 824 | +#### Content result |
| 825 | + |
| 826 | +```c# |
| 827 | +// tests whether the action returns |
| 828 | +// NegotiatedContentResult<T> |
| 829 | +// or FormattedContentResult<T> |
| 830 | +MyWebApi |
| 831 | + .Controller<WebApiController>() |
| 832 | + .Calling(c => c.SomeAction()) |
| 833 | + .ShouldReturn() |
| 834 | + .Content(); |
| 835 | + |
| 836 | +// tests whether the action returns |
| 837 | +// content with specific response model |
| 838 | +MyWebApi |
| 839 | + .Controller<WebApiController>() |
| 840 | + .Calling(c => c.SomeAction()) |
| 841 | + .ShouldReturn() |
| 842 | + .Content() |
| 843 | + .WithResponseModelOfType<ResponseModel>(); |
| 844 | + |
| 845 | +// tests whether the action returns |
| 846 | +// content with specific status code result |
| 847 | +MyWebApi |
| 848 | + .Controller<WebApiController>() |
| 849 | + .Calling(c => c.SomeAction()) |
| 850 | + .ShouldReturn() |
| 851 | + .Content() |
| 852 | + .WithStatusCode(HttpStatusCode.OK); |
| 853 | + |
| 854 | +// tests whether the action returns |
| 855 | +// content with specific media type |
| 856 | +// provided by string |
| 857 | +MyWebApi |
| 858 | + .Controller<WebApiController>() |
| 859 | + .Calling(c => c.SomeAction()) |
| 860 | + .ShouldReturn() |
| 861 | + .Content() |
| 862 | + .WithMediaType("application/json"); |
| 863 | + |
| 864 | +// tests whether the action returns |
| 865 | +// content with specific media type |
| 866 | +// provided by predefined in the library constants |
| 867 | +MyWebApi |
| 868 | + .Controller<WebApiController>() |
| 869 | + .Calling(c => c.SomeAction()) |
| 870 | + .ShouldReturn() |
| 871 | + .Content() |
| 872 | + .WithMediaType(MediaType.ApplicationJson); |
| 873 | + |
| 874 | +// tests whether the action returns |
| 875 | +// content with specific media type |
| 876 | +// provided by MediaTypeHeaderValue class |
| 877 | +MyWebApi |
| 878 | + .Controller<WebApiController>() |
| 879 | + .Calling(c => c.SomeAction()) |
| 880 | + .ShouldReturn() |
| 881 | + .Content() |
| 882 | + .WithMediaType(new MediaTypeHeaderValue("application/json")); |
| 883 | + |
| 884 | +// tests whether the action returns |
| 885 | +// content with DefaultContentNegotiator |
| 886 | +MyWebApi |
| 887 | + .Controller<WebApiController>() |
| 888 | + .Calling(c => c.SomeAction()) |
| 889 | + .ShouldReturn() |
| 890 | + .Content() |
| 891 | + .WithDefaultContentNegotiator(); |
| 892 | + |
| 893 | +// tests whether the action returns |
| 894 | +// content with custom content negotiator |
| 895 | +MyWebApi |
| 896 | + .Controller<WebApiController>() |
| 897 | + .Calling(c => c.SomeAction()) |
| 898 | + .ShouldReturn() |
| 899 | + .Content() |
| 900 | + .WithContentNegotiator(customContentNegotiator); |
| 901 | + |
| 902 | +// tests whether the action returns |
| 903 | +// content with custom content negotiator |
| 904 | +// provided by generic definition |
| 905 | +MyWebApi |
| 906 | + .Controller<WebApiController>() |
| 907 | + .Calling(c => c.SomeAction()) |
| 908 | + .ShouldReturn() |
| 909 | + .Content() |
| 910 | + .WithContentNegotiatorOfType<CustomContentNegotiator>(); |
| 911 | + |
| 912 | +// tests whether the action returns |
| 913 | +// content containing media type formatter |
| 914 | +// provided by an instance |
| 915 | +MyWebApi |
| 916 | + .Controller<WebApiController>() |
| 917 | + .Calling(c => c.SomeAction()) |
| 918 | + .ShouldReturn() |
| 919 | + .Content() |
| 920 | + .ContainingMediaTypeFormatter(customMediaTypeFormatter); |
| 921 | + |
| 922 | +// tests whether the action returns |
| 923 | +// content containing media type formatter |
| 924 | +// provided by an generic definition |
| 925 | +MyWebApi |
| 926 | + .Controller<WebApiController>() |
| 927 | + .Calling(c => c.SomeAction()) |
| 928 | + .ShouldReturn() |
| 929 | + .Content() |
| 930 | + .ContainingMediaTypeFormatterOfType<JsonMediaTypeFormatter>(); |
| 931 | + |
| 932 | +// tests whether the action returns |
| 933 | +// content containing the default media type formatter |
| 934 | +MyWebApi |
| 935 | + .Controller<WebApiController>() |
| 936 | + .Calling(c => c.SomeAction()) |
| 937 | + .ShouldReturn() |
| 938 | + .Content() |
| 939 | + .ContainingDefaultFormatters(); |
| 940 | + |
| 941 | +// tests whether the action returns |
| 942 | +// content containing the media type formatters |
| 943 | +// provided in a collection |
| 944 | +MyWebApi |
| 945 | + .Controller<WebApiController>() |
| 946 | + .Calling(c => c.ContentActionWithCustomFormatters()) |
| 947 | + .ShouldReturn() |
| 948 | + .Content() |
| 949 | + .ContainingMediaTypeFormatters(collectionOfMediaTypeFormatters); |
| 950 | + |
| 951 | +// tests whether the action returns |
| 952 | +// content containing the media type formatters |
| 953 | +// provided by a builder |
| 954 | +MyWebApi |
| 955 | + .Controller<WebApiController>() |
| 956 | + .Calling(c => c.ContentAction()) |
| 957 | + .ShouldReturn() |
| 958 | + .Content() |
| 959 | + .ContainingMediaTypeFormatters( |
| 960 | + formatters => formatters |
| 961 | + .ContainingMediaTypeFormatter(new JsonMediaTypeFormatter) |
| 962 | + .AndAlso() |
| 963 | + .ContainingMediaTypeFormatterOfType<FormUrlEncodedMediaTypeFormatter>()); |
| 964 | + |
| 965 | +// tests whether the action returns |
| 966 | +// content with status code and response model |
| 967 | +// combined by AndAlso |
| 968 | +MyWebApi |
| 969 | + .Controller<WebApiController>() |
| 970 | + .Calling(c => c.ContentAction()) |
| 971 | + .ShouldReturn() |
| 972 | + .Content() |
| 973 | + .WithStatusCode(HttpStatusCode.OK) |
| 974 | + .AndAlso() // AndAlso is not necessary |
| 975 | + .WithResponseModelOfType<ResponseModel>(); |
| 976 | +``` |
| 977 | + |
| 978 | +[To top](#table-of-contents) |
| 979 | + |
823 | 980 | #### Created result |
824 | 981 |
|
825 | 982 | ```c# |
|
0 commit comments