Mocking objects without no-argument constructor in C# / .NET
问题 Is it possible to create a mock from a class that doesn't provide a no-argument constructor and don't pass any arguments to the constructor? Maybe with creating IL dynamically? The background is that I don't want to define interfaces only for testing. The workaround would be to provide a no-argument constructor for testing. 回答1: Sure thing. In this example i'll use Moq, a really awesome mocking library. Example: public class MyObject { public MyObject(object A, object B, object C) { // Assign