示例#1
0
        public async Task Run_SwaggerFalse_Successful()
        {
            using (var tempDirectory = TemplateAssert.GetTempDirectory())
            {
                var project = await tempDirectory.DotnetNew(
                    "api",
                    "SwaggerFalse",
                    new Dictionary <string, string>()
                {
                    { "swagger", "false" },
                });

                await project.DotnetRestore();

                await project.DotnetBuild();

                await project.DotnetRun(
                    @"Source\SwaggerFalse",
                    async (httpClient, httpsClient) =>
                {
                    var swaggerJsonResponse = await httpsClient.GetAsync("swagger/v1/swagger.json");
                    Assert.Equal(HttpStatusCode.NotFound, swaggerJsonResponse.StatusCode);
                });
            }
        }
        public async Task Run_Default_Successful()
        {
            using (var tempDirectory = TemplateAssert.GetTempDirectory())
            {
                var project = await tempDirectory.DotnetNew("graphql", "Default");

                await project.DotnetRun(
                    async (httpClient, httpsClient) =>
                {
                    var httpResponse = await httpClient.GetAsync("/");
                    Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);

                    var httpsResponse = await httpsClient.GetAsync("/");
                    Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);

                    var robotsTxtResponse = await httpsClient.GetAsync("robots.txt");
                    Assert.Equal(HttpStatusCode.OK, robotsTxtResponse.StatusCode);

                    var securityTxtResponse = await httpsClient.GetAsync(".well-known/security.txt");
                    Assert.Equal(HttpStatusCode.OK, securityTxtResponse.StatusCode);

                    var humansTxtResponse = await httpsClient.GetAsync("humans.txt");
                    Assert.Equal(HttpStatusCode.OK, humansTxtResponse.StatusCode);
                });
            }
        }
示例#3
0
        public async Task Run_HealthCheckFalse_Successful()
        {
            using (var tempDirectory = TemplateAssert.GetTempDirectory())
            {
                var project = await tempDirectory.DotnetNew(
                    "api",
                    "HealthCheckFalse",
                    new Dictionary <string, string>()
                {
                    { "health-check", "false" },
                });

                await project.DotnetRestore();

                await project.DotnetBuild();

                await project.DotnetRun(
                    @"Source\HealthCheckFalse",
                    async httpClient =>
                {
                    var statusResponse = await httpClient.GetAsync("status");
                    Assert.Equal(HttpStatusCode.NotFound, statusResponse.StatusCode);

                    var statusSelfResponse = await httpClient.GetAsync("status/self");
                    Assert.Equal(HttpStatusCode.NotFound, statusSelfResponse.StatusCode);
                });
            }
        }
示例#4
0
        public async Task Run_HttpsEverywhereFalse_Successful()
        {
            using (var tempDirectory = TemplateAssert.GetTempDirectory())
            {
                var project = await tempDirectory.DotnetNew(
                    "api",
                    "HttpsEverywhereFalse",
                    new Dictionary <string, string>()
                {
                    { "https-everywhere", "false" },
                });

                await project.DotnetRestore();

                await project.DotnetBuild();

                await project.DotnetRun(
                    @"Source\HttpsEverywhereFalse",
                    async httpClient =>
                {
                    var statusResponse = await httpClient.GetAsync("status");
                    Assert.Equal(HttpStatusCode.OK, statusResponse.StatusCode);
                });
            }
        }
示例#5
0
        public async Task Run_AuthorizationFalse_DateOfBirthReturnedSuccessfully()
        {
            using (var tempDirectory = TemplateAssert.GetTempDirectory())
            {
                var project = await tempDirectory.DotnetNew(
                    "graphql",
                    "AuthorizationFalse",
                    new Dictionary <string, string>()
                {
                    { "authorization", "false" },
                });

                await project.DotnetRestore();

                await project.DotnetBuild();

                await project.DotnetRun(
                    async (httpClient) =>
                {
                    var httpResponse = await httpClient.PostGraphQL(
                        "query getHuman { human(id: \"94fbd693-2027-4804-bf40-ed427fe76fda\") { dateOfBirth } }");
                    Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);
                });
            }
        }
示例#6
0
        public async Task Run_AuthorizationTrue_Returns400BadRequest()
        {
            using (var tempDirectory = TemplateAssert.GetTempDirectory())
            {
                var project = await tempDirectory.DotnetNew(
                    "graphql",
                    "AuthorizationTrue",
                    new Dictionary <string, string>()
                {
                    { "authorization", "true" },
                });

                await project.DotnetRestore();

                await project.DotnetBuild();

                await project.DotnetRun(
                    async (httpClient) =>
                {
                    var httpResponse = await httpClient.PostGraphQL(
                        "query getHuman { human(id: \"94fbd693-2027-4804-bf40-ed427fe76fda\") { dateOfBirth } }");
                    var response = await httpResponse.Content.ReadAsAsync <GraphQLResponse>();

                    Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);
                    var error = Assert.Single(response.Errors);
                    Assert.Equal(
                        "You are not authorized to run this query.\nRequired claim 'role' with any value of 'admin' is not present.",
                        error.Message);
                });
            }
        }
示例#7
0
        public async Task Run_HealthCheckFalse_Successful()
        {
            using (var tempDirectory = TemplateAssert.GetTempDirectory())
            {
                var project = await tempDirectory.DotnetNew(
                    "graphql",
                    "HealthCheckFalse",
                    new Dictionary <string, string>()
                {
                    { "health-check", "false" },
                });

                await project.DotnetRestore();

                await project.DotnetBuild();

                await project.DotnetRun(
                    async httpClient =>
                {
                    var liveResponse = await httpClient.GetAsync("status/live");
                    Assert.Equal(HttpStatusCode.NotFound, liveResponse.StatusCode);

                    var readyResponse = await httpClient.GetAsync("status/ready");
                    Assert.Equal(HttpStatusCode.NotFound, readyResponse.StatusCode);
                });
            }
        }
示例#8
0
        public async Task Run_Default_Successful()
        {
            using (var tempDirectory = TemplateAssert.GetTempDirectory())
            {
                var project = await tempDirectory.DotnetNew("api", "Default");

                await project.DotnetRestore();

                await project.DotnetBuild();

                await project.DotnetRun(
                    async (httpClient, httpsClient) =>
                {
                    var httpResponse = await httpClient.GetAsync("status");
                    Assert.Equal(HttpStatusCode.NoContent, httpResponse.StatusCode);

                    var httpsResponse = await httpsClient.GetAsync("status");
                    Assert.Equal(HttpStatusCode.NoContent, httpsResponse.StatusCode);

                    var swaggerJsonResponse = await httpsClient.GetAsync("swagger/v1/swagger.json");
                    Assert.Equal(HttpStatusCode.OK, swaggerJsonResponse.StatusCode);

                    var robotsTxtResponse = await httpsClient.GetAsync("robots.txt");
                    Assert.Equal(HttpStatusCode.OK, robotsTxtResponse.StatusCode);

                    var securityTxtResponse = await httpsClient.GetAsync(".well-known/security.txt");
                    Assert.Equal(HttpStatusCode.OK, securityTxtResponse.StatusCode);

                    var humansTxtResponse = await httpsClient.GetAsync("humans.txt");
                    Assert.Equal(HttpStatusCode.OK, humansTxtResponse.StatusCode);
                });
            }
        }
示例#9
0
        public async Task Run_Default_Successful()
        {
            using (var tempDirectory = TemplateAssert.GetTempDirectory())
            {
                var project = await tempDirectory.DotnetNew("api", "Default");

                await project.DotnetRestore();

                await project.DotnetBuild();

                await project.DotnetRun(
                    @"Source\Default",
                    async (httpClient, httpsClient) =>
                {
                    var httpResponse = await httpClient.GetAsync("status");
                    Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);

                    var statusResponse = await httpsClient.GetAsync("status");
                    Assert.Equal(HttpStatusCode.OK, statusResponse.StatusCode);
                    Assert.Equal(ContentType.Text, statusResponse.Content.Headers.ContentType.MediaType);

                    var statusSelfResponse = await httpsClient.GetAsync("status/self");
                    Assert.Equal(HttpStatusCode.OK, statusSelfResponse.StatusCode);
                    Assert.Equal(ContentType.Text, statusSelfResponse.Content.Headers.ContentType.MediaType);

                    var carsResponse = await httpsClient.GetAsync("cars");
                    Assert.Equal(HttpStatusCode.OK, carsResponse.StatusCode);
                    Assert.Equal(ContentType.RestfulJson, carsResponse.Content.Headers.ContentType.MediaType);

                    var postCarResponse = await httpsClient.PostAsJsonAsync("cars", new SaveCar());
                    Assert.Equal(HttpStatusCode.BadRequest, postCarResponse.StatusCode);
                    Assert.Equal(ContentType.ProblemJson, postCarResponse.Content.Headers.ContentType.MediaType);

                    var notAcceptableCarsRequest = new HttpRequestMessage(HttpMethod.Get, "cars");
                    notAcceptableCarsRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(ContentType.Text));
                    var notAcceptableCarsResponse = await httpsClient.SendAsync(notAcceptableCarsRequest);
                    Assert.Equal(HttpStatusCode.NotAcceptable, notAcceptableCarsResponse.StatusCode);

                    var swaggerJsonResponse = await httpsClient.GetAsync("swagger/v1/swagger.json");
                    Assert.Equal(HttpStatusCode.OK, swaggerJsonResponse.StatusCode);
                    Assert.Equal(ContentType.Json, swaggerJsonResponse.Content.Headers.ContentType.MediaType);

                    var robotsTxtResponse = await httpsClient.GetAsync("robots.txt");
                    Assert.Equal(HttpStatusCode.OK, robotsTxtResponse.StatusCode);
                    Assert.Equal(ContentType.Text, robotsTxtResponse.Content.Headers.ContentType.MediaType);

                    var securityTxtResponse = await httpsClient.GetAsync(".well-known/security.txt");
                    Assert.Equal(HttpStatusCode.OK, securityTxtResponse.StatusCode);
                    Assert.Equal(ContentType.Text, securityTxtResponse.Content.Headers.ContentType.MediaType);

                    var humansTxtResponse = await httpsClient.GetAsync("humans.txt");
                    Assert.Equal(HttpStatusCode.OK, humansTxtResponse.StatusCode);
                    Assert.Equal(ContentType.Text, humansTxtResponse.Content.Headers.ContentType.MediaType);
                });
            }
        }
        public async Task RestoreAndBuild_Default_Successful(string name, params string[] arguments)
        {
            using (var tempDirectory = TemplateAssert.GetTempDirectory())
            {
                var dictionary = arguments
                                 .Select(x => x.Split('=', StringSplitOptions.RemoveEmptyEntries))
                                 .ToDictionary(x => x.First(), x => x.Last());
                var project = await tempDirectory.DotnetNew("graphql", name, dictionary);

                await project.DotnetRestore();

                await project.DotnetBuild();
            }
        }
        public async Task Run_HttpsEverywhereFalse_Successful()
        {
            using (var tempDirectory = TemplateAssert.GetTempDirectory())
            {
                var project = await tempDirectory.DotnetNew(
                    "graphql",
                    "HttpsEverywhereFalse",
                    new Dictionary <string, string>()
                {
                    { "https-everywhere", "false" },
                });

                await project.DotnetRun(
                    async (httpClient) =>
                {
                    var httpResponse = await httpClient.GetAsync("/");
                    Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);
                });
            }
        }
示例#12
0
        public async Task Run_QueryGraphQlIntrospection_ReturnsResults()
        {
            using (var tempDirectory = TemplateAssert.GetTempDirectory())
            {
                var project = await tempDirectory.DotnetNew("graphql", "Default");

                await project.DotnetRestore();

                await project.DotnetBuild();

                await project.DotnetRun(
                    async (httpClient, httpsClient) =>
                {
                    var introspectionQuery = await httpClient.PostGraphQL(GraphQlQuery.Introspection);
                    Assert.Equal(HttpStatusCode.OK, introspectionQuery.StatusCode);
                    var introspectionContent = await introspectionQuery.Content.ReadAsAsync <GraphQLResponse>();
                    Assert.Null(introspectionContent.Errors);
                });
            }
        }