public void endpoint_invocation___model_lookup_tests() { 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, } } }; // Test model lookup methods var models = context.Request.InvocationContext.Models(); models.Should().NotBeNull(); models.Should().HaveCount(2); models.Should().Contain(uriModel); models.Should().Contain(bodyModel); var foundUriModel = context.Request.InvocationContext.Models <StandardModel>().FirstOrDefault(); foundUriModel.Should().NotBeNull(); foundUriModel.Should().BeSameAs(uriModel); var foundBodyModel = context.Request.InvocationContext.Models <StandardNullableModel>().FirstOrDefault(); foundBodyModel.Should().NotBeNull(); foundBodyModel.Should().BeSameAs(bodyModel); var baseModels = context.Request.InvocationContext.Models <StandardModelBase>(); baseModels.Should().NotBeNull(); baseModels.Should().HaveCount(2); }
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); }