I'm a little confused as to the purpose of the ExpectConstructor() method on the Mock class in TypeMock 3.5.
I would have thought that calling ExpectConstructor would cause the MockManager to fail upon Verify() if the constructor is not called, i.e. if an instance of the mocked type is not instantiated.
However, calling ExpectConstructor() without specifying any arguments to that constructor doesn't appear to set that expectation - and so my test passes regardless.
My questions: Am I missing or misunderstanding something? If ExpectConstructor() isn't for verifying a constructor call, what's it for?
Consider these three NUnit tests which illustrate the problem:
[Test]
public void exampleTest1()
{
MockManager.Init();
Mock fooMock = MockManager.Mock(typeof(Foo));
fooMock.ExpectConstructor().Args(10);
Foo f = new Foo(10); // Constructor called
MockManager.Verify();
// This test passes, as expected...so far so good
}
[Test]
public void exampleTest2()
{
MockManager.Init();
Mock fooMock = MockManager.Mock(typeof(Foo));
fooMock.ExpectConstructor();
Foo f = new Foo(); // Constructor called
MockManager.Verify();
// This test passes...also as expected
}
[Test]
public void exampleTest3()
{
MockManager.Init();
Mock fooMock = MockManager.Mock(typeof(Foo));
fooMock.ExpectConstructor();
// nb. not instantiating an instance of Foo
MockManager.Verify();
// This test passes - why?!
}
Thanks in advance for your help.