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()); }
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); }
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}"); }
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); }
public void Setup() { _factory = new WebAppFactory(); _client = _factory.CreateClient(); }
public void SetUpFactoryAndHttpClient() { _factory = new WebAppFactory(); _client = _factory.CreateClient(); }
public AuthControllerTest(WebAppFactory <Startup> factory) { _client = factory.CreateClient(); }