Using Moq, I need to create a fake over an existing class (not interface*) that has no default ctor.
I can do this using the "traditional" syntax:
var fakeResponsePacket = new Mock<DataResponse>(
new object[]{0, 0, 0, new byte[0]}); //specify ctor arguments
fakeResponsePacket.Setup(p => p.DataLength).Returns(5);
var checkResult = sut.Check(fakeResponsePacket.Object);
My question is: Is there a way to do the same using the newer Mock.Of<T>()
syntax ?
From what I can see, there are only two overloads for Mock.Of<T>
, none of which accept arguments:
//1 no params at all
var fakeResponsePacket = Mock.Of<DataResponse>(/*??*/);
fakeResponsePacket.DataLength = 5;
//2 the touted 'linq to Moq'
var fakeResponsePacket = Mock.Of<DataResponse>(/*??*/
p => p.DataLength == 5
);
var checkResult = sut.Check(fakeResponsePacket);
--
* I wanted to use an interface. But then reality happened. Let's not go into it.