If this happens, use the checklist
- For some versions of Verify.xUnit, you need to add [UsesVerify] attribute to your test class.
- Verifier.Verify methods are asynchronous, make sure the calls are awaited.
Bruce Ng's software development blog
An archive of solutions of programming problems I have faced in my career
If this happens, use the checklist
Follow this article
You cannot mock HttpClient, but you can mock the HttpMessageHandler that the HttpClient uses.
To use in unit tests, make sure HttpClient can be injected into the test class, then in tests create an instance of HttpClient with a mocked HttpMessageHandler.
https://stackoverflow.com/questions/758066/how-to-mock-controller-user-using-moq
Simply mock the ControllerContext and assign it to the controller before running the method that needs testing.
https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/
I tried to use Moq to mock the DbContext and IQueryable<>, but it seems to be really complicated. It’s also not recommended by Microsoft.
For unit testing, it’s recommended to use a real database, perhaps using an in-memory database or a temporary sqlite database. Whatever the type of database you use, install the required NuGet package.
If the return type is of a class that is not referenced by the test project, Returns() won’t show up, adding a reference to the assembly/project containing the return type will fix this.