The following constructor parameters did not have matching fixture data

前端 未结 3 1896
感动是毒
感动是毒 2021-02-12 16:29

I\'m trying to test my controllers using xUnitbut getting the following error during execution of Customer Controller:

\"The following constr

相关标签:
3条回答
  • 2021-02-12 16:58

    This article shows how to get xunit working with .Net Core ASP.Net really well. It actually replaces the startup so that your controllers run in the same process, and you can test them as if they were local.

    https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests

    It allows your standard .Net Dependency Injection to work as it normally does. Moreover it has the amazing benefit of not running as a server, and it fakes the whole startup process so that it runs in one single process and you can debug all the way through. This is also the way you should do it because Microsoft says so.

    There's more help to be gleaned from the forum at the bottom of the article.

    0 讨论(0)
  • 2021-02-12 16:59

    For the testing framework, you need the mocking library to inject a mock object through DI in your testing classes. You can use Nmock, Moq or any other mocking library to setup the constructor injection.

    https://www.c-sharpcorner.com/uploadfile/john_charles/mocking-in-net-with-moq/

    http://nmock.sourceforge.net/quickstart.html

    0 讨论(0)
  • 2021-02-12 17:00

    Just new up CustomerController in the constructor, if you don't want to use any mocking framework.

    0 讨论(0)
提交回复
热议问题