2

I Have an API (.net core) and a local application based on Angular. I want to do integration tests for this API without testing it directly by client side. I checked the .net core docs and I found this : https://learn.microsoft.com/en-us/aspnet/core/testing/integration-testing

That's what I've done :

public class Customers
{
    private readonly TestServer _server;
    private readonly HttpClient _client;
    public Customers()
    {
        // Arrange
        _server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
        _client = _server.CreateClient();
    }

    [Fact]
    public async Task ReturnSomething()
    {
        // Act
        var response = await _client.GetAsync("/api/customers/test");
        response.EnsureSuccessStatusCode();

        var responseString = await response.Content.ReadAsStringAsync();

        // Assert
        Assert.Equal("test",
            responseString);
    }
}

I have this response : Response status code does not indicate success : 500 (internal server error)

When I put "await _client.GetAsync("/api/customers/testtttt" => an incorrect link to API, it display : 404 (not found) so I assume it can join the API.

Why 500 internal error? and how can I have 200 success?

Thank you in advance.

1 Answer 1

1

Okay I found the response to this issue. It was a problem with the connection to database (connectionString is null). The API is called and exceptions are generated for 404 & 500 status but not logs for a bad connectivity with BD).

Sign up to request clarification or add additional context in comments.

1 Comment

where can you specify the connectionString for a TestServer? as in how did you solve this problem? I too am getting 500 error in TestServer with no explanation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.