.NET Core C# web API integration testing an inmemory database

Soluble Snake 1 Reputation point

I'm currently trying to create an integration test for my .NET Core Web API. I'm following the advice here: https://timdeschryver.dev/blog/how-to-test-your-csharp-web-api

When I run my test to check the HttpStatusCode 'Should' 'Be' ok, the test is failing BUT the test does pass if I use the '/weatherforecast' example that comes with the .NET Core Web API template. If I use my project, the test fails. Is this because I have no values created in the DB when I start the app? How do I create those values? The code for my test is below:

public async Task Get_Should_Retrieve_Score()
    var response = await Client.GetAsync("/diceroll");

    //var DiceRoll = JsonConvert.DeserializeObject<DiceRoll[]>(await response.Content.ReadAsStringAsync());

Thanks for any help anyone can provide!

A set of technologies in the .NET Framework for building web applications and XML web services.
4,133 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,192 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 47,626 Reputation points

    You didn't post the code for your API so that we can confirm you're returning a 200 from the request. Have you verified via curl, Postman, Powershell or even the browser that the response is actually 200?

    0 comments No comments