示例#1
0
        public async Task GraphQL_Queries_Scenatios()
        {
            // Loop Entities
            var entities = ((new ProfileLocationContextEF()).Model.GetEntityTypes());

            var entitiesCount = new List <EntityInvPropCount>();

            foreach (var entity in entities)
            {
                entitiesCount.Add(new EntityInvPropCount()
                {
                    Entity = entity.ClrType, Count = entity.ClrType.GetProperties().Where(x => x.GetCustomAttribute <InversePropertyAttribute>() != null).Count(), IsKeyless = ((IMutableEntityType)entity).IsKeyless
                });
            }

            foreach (var entity in entitiesCount.Where(w => !w.IsKeyless).OrderByDescending(s => s.Count))
            {
                var method       = typeof(GraphQLQueryTestGenerator).GetMethod("GetUpsertQuery").MakeGenericMethod(entity.Entity);
                var queryBuilder = method.Invoke(queryGenerator, null) as List <GraphQLTestQueryResult>;
                var upSertQuery  = queryBuilder.Where(s => s.Type == GraphQLQueryType.UpSert).FirstOrDefault();

                if (upSertQuery != null)
                {
                    // Add Valid
                    await sut.Scenario(scenario =>
                    {
                        var insert = new GraphQLQuery()
                        {
                            Query = upSertQuery.Query
                        };
                        scenario.Post.Json(insert).ToUrl("/graphql");
                        scenario.StatusCodeShouldBe(HttpStatusCode.OK);
                        scenario.GraphQL().ShouldBeSuccess(upSertQuery.ExpectedResult);
                    });
                }

                var getQuery = queryBuilder.Where(s => s.Type == GraphQLQueryType.Get).FirstOrDefault();

                if (getQuery != null)
                {
                    //  Get Valid
                    await sut.Scenario(scenario =>
                    {
                        var insert = new GraphQLQuery()
                        {
                            Query = getQuery.Query
                        };
                        scenario.Post.Json(insert).ToUrl("/graphql");
                        scenario.StatusCodeShouldBe(HttpStatusCode.OK);
                        scenario.GraphQL().ShouldBeSuccess(getQuery.ExpectedResult);
                    });
                }
            }
        }
示例#2
0
文件: Headers.cs 项目: fengweijp/alba
        // ENDSAMPLE

        // SAMPLE: setting-request-headers
        public Task setting_request_headers(ISystemUnderTest system)
        {
            return(system.Scenario(_ =>
            {
                _.Context.Request.Headers["foo"] = "bar";
            }));
        }
示例#3
0
        // ENDSAMPLE


        // SAMPLE: send-text
        public Task send_text(ISystemUnderTest system)
        {
            return(system.Scenario(_ =>
            {
                _.Post.Text("some text").ToUrl("/textdata");
            }));
        }
示例#4
0
文件: Headers.cs 项目: rytmis/alba
        // ENDSAMPLE

        // SAMPLE: setting-request-headers
        public Task setting_request_headers(ISystemUnderTest system)
        {
            return(system.Scenario(_ =>
            {
                _.SetRequestHeader("foo", "bar");
            }));
        }
示例#5
0
        public async Task run_simple_scenario_bootstrapped_by_Startup()
        {
            theSystem = JasperHttpTester.For <AlbaTargetApp2>();

            await theSystem.Scenario(_ =>
            {
                _.Get.Url("/");
                _.StatusCodeShouldBeOk();
                _.ContentShouldContain("Texas");
            });
        }
示例#6
0
        public async Task run_simple_scenario_that_uses_custom_services()
        {
            theSystem = JasperHttpTester.For <AlbaTargetApp>();

            await theSystem.Scenario(_ =>
            {
                _.Get.Url("/");
                _.StatusCodeShouldBeOk();
                _.ContentShouldContain("Texas");
            });
        }
示例#7
0
        // ENDSAMPLE

        // SAMPLE: asserting-windows-auth-with-user
        public Task asserting_authentication_with_user(ISystemUnderTest system)
        {
            return(system.Scenario(_ =>
            {
                var user = new ClaimsPrincipal(new ClaimsIdentity(Enumerable.Empty <Claim>(), "Windows"));
                _.WithWindowsAuthentication(user);
                _.Get.Url("/");

                _.StatusCodeShouldBe(HttpStatusCode.Forbidden);
            }));
        }
示例#8
0
        // ENDSAMPLE

        // SAMPLE: assert-on-text
        public Task assert_on_content(ISystemUnderTest system)
        {
            return(system.Scenario(_ =>
            {
                _.ContentShouldBe("exactly this");

                _.ContentShouldContain("some snippet");

                _.ContentShouldNotContain("some warning");
            }));
        }
示例#9
0
        // SAMPLE: asserting-redirects
        public Task asserting_redirects(ISystemUnderTest system)
        {
            return(system.Scenario(_ =>
            {
                // should redirect to the url
                _.RedirectShouldBe("/redirect");

                // should redirect permanently to the url
                _.RedirectPermanentShouldBe("/redirect");
            }));
        }
示例#10
0
        // SAMPLE: asserting-windows-auth
        public Task asserting_authentication(ISystemUnderTest system)
        {
            return(system.Scenario(_ =>
            {
                _.WithWindowsAuthentication();
                _.Get.Url("/");

                _.StatusCodeShouldBe(HttpStatusCode.Unauthorized);
                _.Header("www-authenticate").ShouldHaveValues("NTLM", "Negotiate");
            }));
        }
示例#11
0
        // ENDSAMPLE


        // SAMPLE: read-text
        public async Task read_text(ISystemUnderTest system)
        {
            var result = await system.Scenario(_ =>
            {
                _.Get.Url("/output");
            });

            // This deserializes the response body to the
            // designated Output type
            var outputString = result.ResponseBody.ReadAsText();

            // do assertions against the Output string
        }
示例#12
0
        // SAMPLE: check-the-status-code
        public Task check_the_status(ISystemUnderTest system)
        {
            return(system.Scenario(_ =>
            {
                // Shorthand for saying that the StatusCode should be 200
                _.StatusCodeShouldBeOk();

                // Or a specific status code
                _.StatusCodeShouldBe(403);

                // Ignore the status code altogether
                _.IgnoreStatusCode();
            }));
        }
示例#13
0
        // ENDSAMPLE



        // SAMPLE: read-xml
        public async Task read_xml(ISystemUnderTest system)
        {
            var result = await system.Scenario(_ =>
            {
                _.Get.Url("/output");
            });

            // This deserializes the response body to the
            // designated Output type
            var output = result.ResponseBody.ReadAsXml <Output>();

            // do assertions against the Output model

            // OR, if you just want the XmlDocument itself:
            XmlDocument document = result.ResponseBody.ReadAsXml();
        }
示例#14
0
文件: Headers.cs 项目: fengweijp/alba
        // ENDSAMPLE


        // SAMPLE: asserting-on-header-values
        public Task asserting_on_header_values(ISystemUnderTest system)
        {
            return(system.Scenario(_ =>
            {
                // Assert that there is one and only one value equal to "150"
                _.Header("content-length").SingleValueShouldEqual("150");

                // Assert that there is no value for this response header
                _.Header("connection").ShouldNotBeWritten();

                // Only write one value for this header
                _.Header("set-cookie").ShouldHaveOneNonNullValue();

                // Check the content-type header
                _.ContentTypeShouldBe("text/json");
            }));
        }
示例#15
0
        // SAMPLE: write-form-data
        public Task write_form_data(ISystemUnderTest system)
        {
            var form1 = new Dictionary <string, string>
            {
                ["a"] = "what?",
                ["b"] = "now?",
                ["c"] = "really?"
            };

            return(system.Scenario(_ =>
            {
                // This writes the dictionary values to the HTTP
                // request as form data, and sets the content-length
                // header as well as setting the content-type
                // header to application/x-www-form-urlencoded
                _.Context.WriteFormData(form1);
            }));
        }
示例#16
0
文件: Headers.cs 项目: fengweijp/alba
        // SAMPLE: conneg-helpers
        public Task conneg_helpers(ISystemUnderTest system)
        {
            return(system.Scenario(_ =>
            {
                // Set the accepts header on the request
                _.Get.Url("/").Accepts("text/plain");

                // Specify the etag header value
                _.Get.Url("/").Etag("12345");

                // Set the content-type header on the request
                _.Post.Url("/").ContentType("text/json");

                // This is a superset of the code above that
                // will set the content-type header as well
                _.Post.Json(new InputModel()).ToUrl("/");
            }));
        }
示例#17
0
        // ENDSAMPLE

        // SAMPLE: sending-xml
        public Task send_xml(ISystemUnderTest system)
        {
            return(system.Scenario(_ =>
            {
                // This serializes the Input object to xml,
                // writes it to the HttpRequest.Body, and sets
                // the accepts & content-type header values to
                // application/xml
                _.Post
                .Xml(new Input {
                    Name = "Max", Age = 13
                })
                .ToUrl("/person");

                // OR, if url lookup is enabled, this is an equivalent:
                _.Post.Xml(new Input {
                    Name = "Max", Age = 13
                });
            }));
        }
示例#18
0
文件: Headers.cs 项目: rytmis/alba
        // ENDSAMPLE


        // SAMPLE: asserting-on-header-values
        public Task asserting_on_header_values(ISystemUnderTest system)
        {
            return(system.Scenario(_ =>
            {
                // Assert that there is one and only one value equal to "150"
                _.Header("content-length").SingleValueShouldEqual("150");

                // Assert that there is no value for this response header
                _.Header("connection").ShouldNotBeWritten();

                // Only write one value for this header
                _.Header("set-cookie").ShouldHaveOneNonNullValue();

                // Assert that the header has the given values
                _.Header("www-authenticate").ShouldHaveValues("NTLM", "Negotiate");

                // Assert that the header matches a regular expression
                _.Header("location").SingleValueShouldMatch(new Regex(@"^/items/\d*$"));

                // Check the content-type header
                _.ContentTypeShouldBe("text/json");
            }));
        }
示例#19
0
 protected Task <ScenarioAssertionException> fails(Action <Scenario> configuration)
 {
     return(Exception <ScenarioAssertionException> .ShouldBeThrownBy(() => host.Scenario(configuration)));
 }
示例#20
0
            public async Task <TResponse> Receive <TResponse>()
            {
                var response = await _system.Scenario(_configure);

                return(response.ResponseBody.ReadAsJson <TResponse>());
            }
示例#21
0
        /// <summary>
        /// Shortcut to just retrieve the contents of an HTTP GET as JSON and deserialize the resulting
        /// response to the type "T"
        /// </summary>
        /// <param name="system"></param>
        /// <param name="url"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static async Task <T> GetAsJson <T>(this ISystemUnderTest system, string url)
        {
            var response = await system.Scenario(x => x.Get.Url(url).Accepts("application/json;text/json"));

            return(response.ResponseBody.ReadAsJson <T>());
        }