I'm having trouble with running integration test on my application.
I'm trying to write a test on controller that calls another api controller in same solution.
So basicly i have two APIS one calling other in same solution.
I know how to test one API but i can't seem to figure out how to run the other API.
I have tried building two seperate TestServers with different startup. But nothing seems to trigger other api.
Any pointers will be deeply appreciated.
[TestInitialize]
public void Init()
{
var builder = new WebHostBuilder()
.UseConfiguration(new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.Build())
.UseStartup<Startup>();
_server = new TestServer(builder);
_client = _server.CreateClient();
}
[TestMethod]
public void TestUser()
{
var request = _client.GetAsync("/api/v1/").Result;
var jsonString = request.Content.ReadAsStringAsync().Result;
var result = JsonConvert.DeserializeObject<bool>(jsonString);
Assert.IsNotNull(result);
}
public async Task<bool?> GetUser()
{
bool? result = null;
HttpResponseMessage response = await _client.GetAsync("/");
if (response.IsSuccessStatusCode)
{
var responseContent = await response.Content.ReadAsStringAsync();
result = JsonConvert.DeserializeObject<bool>(responseContent);
}
return result;
}
Aucun commentaire:
Enregistrer un commentaire