Exemple #1
0
        public void ComplexTest()
        {
            var webAppFactory     = new WebApplicationFactory <Startup>();
            var client            = webAppFactory.CreateClient();
            var controllerFactory = new ControllerFactory(client,
                                                          webAppFactory.Services,
                                                          new NunitLogWriter()); // add writer which writes generated requests to test output.

            // Register transformer which allows us to work with custom model binder
            controllerFactory.AddActionInfoTransformer(new CustomModelBinderTransformer());
            // add httpRequestTransformation which allows us to transform final http request
            controllerFactory.AddHttpRequestPipelinePart(new HttpRequestTransformationPipelinePart());
            var testController = controllerFactory.CreateController <ExamplesController>();
            var response       = testController.ComplexExample(
                complexObjectFromQuery: new ComplexObject()
            {
                Str = "str",
                NestedComplexObject = new NestedComplexObject()
                {
                    Integer = 1,
                    Str     = "string",
                },
            },
                listOfSimpleTypesFromQuery: new List <string>()
            {
                "foo", "bar",
            },
                complexObjectsFromBody: new List <ComplexObject>()
            {
                new()
                {
                    Str = "str",
                    NestedComplexObject = new NestedComplexObject()
                    {
                        Integer = 5,
                        Str     = "bar",
                    },
                },
            },