mercredi 4 juillet 2018

xUnit TestServer MVC CORE

I am trying to setup a test for getting all my product but I am getting and ArgumentNullException but I do not get why, I recently started studying this so ...

This is the error message

Message: System.ArgumentNullException : Value cannot be null.
Parameter name: connectionString

private readonly TestServer server;
private readonly HttpClient client;

public ProductControllerIntegrationTests()
{
    server = new TestServer(new WebHostBuilder()
        .UseStartup<Startup>());
    client = server.CreateClient();
}

[Fact]
public async Task Product_Get_All()
{
    var response = await client.GetAsync("/api/Products");
    response.EnsureSuccessStatusCode();
    var responseString = await response.Content.ReadAsStringAsync();
    var products = JsonConvert.DeserializeObject<IEnumerable<Product>>(responseString);
    products.Count().Should().Be(12);
}

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire