Moq class - Constructor with parameter

3,794 views
Skip to first unread message

Swami

unread,
Sep 29, 2011, 3:27:29 PM9/29/11
to Moq Discussions
is it possible to mock class with parameter in constructor?

public class testClass
{
public testClass(string s);
}

how do we mock this class?
private Mock<testClass> _testClass = new
Mock<testClass>(MockBehavior.Strict, new object[] {"Hello"});


Is tht ok?

Because when i tried this, i got the following msg:
testClass cannot be serialized because it does not have a
parameterless constructor.


Any idea?

Daniel Cazzulino

unread,
Sep 29, 2011, 4:24:16 PM9/29/11
to moq...@googlegroups.com

private Mock<testClass> _testClass = new
Mock<testClass>(MockBehavior.Strict, "Hello");

?

/kzu

--
Daniel Cazzulino | Developer Lead | XML MVP | Clarius Consulting | +1 425.329.3471


Reply all
Reply to author
Forward
0 new messages