public ReminderControllerTest(ReminderWebApplicationFactory <ReminderService.Startup> factory, AuthWebApplicationFactory <AuthenticationService.Startup> authFactory) { //calling Auth API to get JWT User user = new User { UserId = "Mukesh", Password = "******" }; _authclient = authFactory.CreateClient(); HttpRequestMessage request = new HttpRequestMessage(); MediaTypeFormatter formatter = new JsonMediaTypeFormatter(); // The endpoint or route of the 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(); //Attaching token in request header _client.DefaultRequestHeaders.Add("Authorization", $"Bearer {response.Token}"); }
public ReminderControllerTest(ReminderWebApplicationFactory <Startup> factory) { _client = factory.CreateClient(); }