How do you prohibit calling the base class constructor using Moq?

How do you prohibit calling the base class constructor using Moq?

I cannot Mock an object with Moq because the base class constructor is called, and it requires real objects, so I want to stop calling the base class constructor.

var parametersMoq = new Mock<MyDerivedClass>(null, "Params", null){ CallBase = false, };
_storedProcedureAccessor._parameters = parametersMoq.Object;

The base class constructor MyDerivedClass is causing me problems.

+3
source share
1 answer

It is not possible to prevent the constructor of the base class from being called.

If you can edit the base class, you must replace the fixed dependencies with abstractions (for example, an interface, an abstract class, or a delegate).

, , (, , ).

+4

All Articles