I define my test class as below and one test is created. I'm confused about how my Controller is invoked. I make the same GetAsync calls twice using the same client, but looks like each call hits the different instance of the Controller (based on the value of GetHashCode()) ... So .. each of client.*Async() calls like GetAsync, PutAsync .. always hit the different instance of controller? Even if using the same client? Is there any way to hit the same instance??
// My test class is defined as:
public class ApiControllerIT : IClassFixture<WebApplicationFactory<Startup>> {
public ApiControllerIT(WebApplicationFactory<Startup> factory)
{
_factory = factory;
}
// test case
[Theory]
[InlineData("/api/values")]
public async Task GET_All_ReturnSuccessAndCorrectContent(string url)
{
try
{
// Arrange
var client = _factory.CreateClient();
// Act
var response = await client.GetAsync(url);
response = await client.GetAsync(url);
}
...
}