When i mock a type first like
MockManager.Init();
Mock mock=MockManager.Mock(typeof(TestedClass));
and the initialize the type
TestedClass testedClass=new TestedClass();
the code inside the constructor is never executed??
How can i allow that code to be executed?
Hi, This is simple use the following:
Mock mock=MockManager.Mock(typeof(TestedClass),false);
The second parameter is bool mockConstructors, by default it is true, but you can turn it off as shown above.
:idea: Tip: To mock the constructor but to run initializations of static fields you can do the following:
Mock mock=MockManager.Mock(typeof(TestedClass),false);
mock.ExpectAlways(".ctor");
I hope this helps