I am trying to mock MySqlConnection using Moq. and it is throwing the below error
System.NotSupportedException: 'Type to mock (MySqlConnection) must be an interface, a delegate, or a non-sealed, non-static class.'
Is there any way to mock the MySqlConnection without changing the code I am trying to write the unit test for?
1条答案
按热度按时间pobjuy321#
You can create an in memory database to mock the application database context and add test data to the in memory db for testing.
Please refer the below code.