public UserControllerTest(UserWebApplicationFactory <Startup> factory, AuthWebApplicationFactory <AuthenticationService.Startup> authFactory)
        {
            //calling Auth API to get JWT
            User user = new User {
                UserId = "Jack", Password = "******"
            };

            _authclient = authFactory.CreateClient();
            HttpRequestMessage request   = new HttpRequestMessage();
            MediaTypeFormatter formatter = new JsonMediaTypeFormatter();

            // The endpoint or route of the authentication controller action.
            var httpResponse = _authclient.PostAsync <User>("/api/auth/login", user, formatter);

            httpResponse.Wait();
            // Deserialize and examine results.
            var stringResponse = httpResponse.Result.Content.ReadAsStringAsync();
            var response       = JsonConvert.DeserializeObject <TokenModel>(stringResponse.Result);

            _client = factory.CreateClient();
            _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {response.Token}");
        }
Ejemplo n.º 2
0
 public UserControllerTest(UserWebApplicationFactory <Startup> factory)
 {
     _client = factory.CreateClient();
 }