Integration test in .NET6

Anna Kozorovitsky 1 Reputation point
2022-03-23T12:06:25.36+00:00

I do integration test to my system. I have 2 webAPIs and one monitor.
"manager" webAPI ->Server->"notify" webAPI

I created default client with WebApplicationFactory that sends requests to "manager" webAPI. My question is how can I test that "notify" webAPI got a response from the server by post request in the controller.

186113-image.png

I want to check that Notify() called.

Thank you

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,242 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Brando Zhang-MSFT 3,041 Reputation points Microsoft Vendor
    2022-03-24T02:05:46.673+00:00

    Hi @Anna Kozorovitsky ,

    I created default client with WebApplicationFactory that sends requests to "manager" webAPI. My question is how can I test that "notify" webAPI got a response from the server by post request in the controller.

    According to your description, I suggest you could try to follow this article to use the WebApplicationFactory to create the test server for integration tests. By using this class, you could create the client and set the url to test it.


  2. Anna Kozorovitsky 1 Reputation point
    2022-03-25T21:15:02.547+00:00

    187074-image.png

    This is my SUT I want to test. I created TestServer and HttpClient to test manager API.

    actionsManageFactory = new WebApplicationFactory<ActionsManageProgram>();
    actionsManageClient = actionsManageFactory.CreateDefaultClient();
    var result = await _actionsManageClient.PostAsJsonAsync(URI, actionContent.Content);

    Now, I need to test that notification API receiving post request from the monitor server.

      [HttpPost, Route("notify")]  
      public async Task<IActionResult> Notify()  
        {  
            var rawRequestBody = await GetRawBodyAsync(Request);  
            _logger.LogInformation(string.Format("Action result: {0}", rawRequestBody.ToString()));  
    
            return Ok();  
        }  
    

    How can I test that Notify() method was called from the monitor server?