Apr 1 2008

A problem I had with a new mocking framework.

Category: C# | Testing | Mockingfossmo @ 15:21
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:

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Comments are closed