示例#1
0
        public async Task endpoint_invocation___returns_true_for_api_response_and_empty_parameter_endpoint()
        {
            var controller = new StandardController();

            var context = new ApiRequestContext
            {
                RequestAborted = new CancellationToken(false),
                Request        = new ApiRequestInfo
                {
                    InvocationContext = new ApiInvocationContext
                    {
                        ControllerInstance = controller,
                    }
                },
                Routing = new ApiRoutingInfo
                {
                    Route = new ApiRoutingItem
                    {
                        Location = new ApiEndpointLocation(
                            controller: controller.GetType(),
                            methodInfo: controller.GetType().GetMethod(nameof(controller.DefaultFullApiResponseEndpoint)),
                            httpMethod: null)
                    }
                }
            };

            var processed = await context.ProcessHttpEndpointInvocation().ConfigureAwait(false);

            processed.Should().BeTrue();

            context.Response.Should().NotBeNull();
            context.Response.ResponseObject.Should().NotBeNull();
            context.Response.ResponseObject.Should().BeOfType <int>();
            context.Response.ResponseObject.Should().Be(200);
        }
示例#2
0
        public async Task endpoint_invocation___returns_true_for_api_response_and_uri_and_body_parameter_and_extra_parameters_endpoint()
        {
            var controller = new StandardController();

            var uriModel = new StandardModel
            {
                IntProp = 204
            };

            var bodyModel = new StandardNullableModel
            {
                IntProp = 301
            };

            var context = new ApiRequestContext
            {
                RequestAborted = new CancellationToken(false),
                Request        = new ApiRequestInfo
                {
                    InvocationContext = new ApiInvocationContext
                    {
                        ControllerInstance = controller,
                        UriModel           = uriModel,
                        BodyModel          = bodyModel
                    }
                },
                Routing = new ApiRoutingInfo
                {
                    Route = new ApiRoutingItem
                    {
                        Location = new ApiEndpointLocation(
                            controller: controller.GetType(),
                            methodInfo: controller.GetType().GetMethod(nameof(controller.DefaultFullApiResponseEndpointWithUriParameterAndBodyParameterAndExtraParameters)),
                            httpMethod: null)
                    }
                }
            };

            var processed = await context.ProcessHttpEndpointInvocation().ConfigureAwait(false);

            processed.Should().BeTrue();

            context.Response.Should().NotBeNull();
            context.Response.StatusCode.Should().Be(200);
            context.Response.ResponseObject.Should().BeOfType <int>();
            context.Response.ResponseObject.Should().Be(301);
        }