Exemplo n.º 1
0
        public async Task GraphQLMedia()
        {
            var webAppFactory = new WebAppFactory();

            var client = webAppFactory.CreateClient();

            var query = @"{
                child {
                    anInt
                    aString
                }
            }";

            var response = await client.PostAsync("/graphql", new StringContent(query, Encoding.ASCII, "application/graphql"));

            var rawResult = await response.Content.ReadAsStringAsync();

            var result = JObject.Parse(rawResult)["data"].ToString();

            result.Should().Be(JObject.Parse(@"{
                ""child"": {
                    ""anInt"": 42,
                    ""aString"": ""Hello World!""
                }
            }").ToString());
        }
Exemplo n.º 2
0
        private async Task <HttpClient> GetAuthorizedClientAsync()
        {
            var client  = _factory.CreateClient();
            var command = new AuthCommand()
            {
                Email    = "*****@*****.**",
                Password = "******"
            };
            var response = await client.PostAsJsonAsync("/auth/authenticate", command);

            var jsonResult = await response.Content.ReadAsAsync <AuthResultDto>();

            client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", jsonResult.JwtToken);

            return(client);
        }
Exemplo n.º 3
0
        public async Task JsonMedia()
        {
            var webAppFactory = new WebAppFactory();

            var client = webAppFactory.CreateClient();

            var query = @"query foo($myInt: Int!, $myStr: String!) {
                childFromArgs(anInt: $myInt, aString: $myStr) {
                    anInt
                    aString
                }
            }";

            var postdata = new JObject(
                new JProperty("query", query),
                new JProperty("variables", new JObject(
                                  new JProperty("myInt", 12),
                                  new JProperty("myStr", "Halloo variables")

                                  ))
                ).ToString();

            var response = await client.PostAsync("/graphql", new StringContent(postdata, Encoding.ASCII, "application/json"));

            var rawResult = await response.Content.ReadAsStringAsync();

            var result = JObject.Parse(rawResult)["data"].ToString();

            result.Should().Be(JObject.Parse(@"{
                ""childFromArgs"": {
                    ""anInt"": 12,
                    ""aString"": ""Halloo variables""
                }
            }").ToString(), $"full result: {rawResult}");
        }
Exemplo n.º 4
0
 public AccountControllerTests(
     WebAppFactory <Startup> factory)
 {
     _factory = factory;
     _client  = factory.CreateClient(new WebApplicationFactoryClientOptions
     {
         AllowAutoRedirect = false
     });
 }
        public async Task GreetingAsyncEndpoint()
        {
            // Arrange
            using var client = _factory.CreateClient();

            // Act
            var response = await client.GetAsync($"{routePrefix}GreetingAsync?name=peterparker");

            var responseContent = JsonConvert.DeserializeObject <GreetingResponse>(await response.Content.ReadAsStringAsync());

            // Assert
            responseContent.Greeting.ShouldBe("Hello peterparker");
            response.StatusCode.ShouldBe(System.Net.HttpStatusCode.OK);
        }
Exemplo n.º 6
0
 public void Setup()
 {
     _factory = new WebAppFactory();
     _client  = _factory.CreateClient();
 }
Exemplo n.º 7
0
 public void SetUpFactoryAndHttpClient()
 {
     _factory = new WebAppFactory();
     _client  = _factory.CreateClient();
 }
Exemplo n.º 8
0
 public AuthControllerTest(WebAppFactory <Startup> factory)
 {
     _client = factory.CreateClient();
 }