It took me some time to figure this out, but I finally got it.
If you in RhinoMocks want to create a mock based on a interface, the syntax is like this:
IMyInterface myObject = mock.CreateMock<IMyInterface>();
myObject is now a mock object.
When using Moq (mock-you) mocking framework, you have to add .Object to the mock to get the object.
This syntax I don't find very intuitive.Below is a example of a test using Moq (without Expectations):
[TestFixture]
public class MyTestClass
{
[Test]
public void MyTest()
{
var mockedTestInterface = new Mock<IMyInterface >();
MyClass myTest = new MyClass (mockedTestInterface.Object);
}
}
I guess it will take a little time to get used to the syntax. But, that said,
I really like this framework.
Tags: moq