Reputation: 1
Need code to write xunit test case for ControllerApi
I tried to inject Contructor from xunit test method, but it asking contructor value which I don't have in test method.
Controller ItemApiController.cs
public class ItemApiController : ControllerBase
{
Private ItemClassDataSerices __ItemClassDataSerices;
public ItemApiController(IItemClassDataSerices ItemClassDataSerices)
{
__ItemClassDataSerices = ItemClassDataSerices;
}
public ActionResult ItemClass([FromQuery] ItemRequest request)
{
return __ItemClassDataSerices.GetData(reqest);
}
}
Now how to write Xunit test method for ItemClass method which is present in ItemApiController.
Upvotes: 0
Views: 41
Reputation: 3660
This kind of tests are named Integration tests. You can follow the Microsoft documentation.
https://learn.microsoft.com/fr-fr/aspnet/core/test/integration-tests?view=aspnetcore-2.2
The documentation has a lot of examples, and some code about startup configuration to use your DI inside your tests
Upvotes: 1