My favorites | Sign in
Project Logo
                
Code license: MIT License
Labels: NMock2, Mocking, .Net, C, TDD
Feeds:
People details
Project owners:
  nigel.thorne

Adding in all the features I wished NMock had build in.

Mocking Events

Stub.On(mock_with_events).EventAdd("eventname", Is.Anything).Will(Remember.EventAdd);
Stub.On(mock_with_events).EventRemove("eventname", Is.Anything).Will(Remember.EventRemove);

// perform action that makes someone listen to the event.
...

//simulate firing event
Event.Fire("eventname", mock_with_events, new EventArgs());

Mocking Generic Methods

Stub.On(childScope)
      .Method(new GenericMethodMatcher("MethodName", typeof(Type1), typeof(Type2))
      .Will(Return.Value(NewMock<Type2>()));

Stub.On(childScope)
      .Method(new GenericMethodMatcher("MethodName", typeof(Type1), typeof(Type3))
      .Will(Return.Value(NewMock<Type3>()));

.Net 3.5 people can now do this...

Stub.On(childScope)
      .Method<Type1, Type3>("MethodName")
      .Will(Return.Value(NewMock<Type3>()));

Simple!

DRY Fixtures

Derive your test fixtures from MockingTestFixture.

You don't need:-

   mocks = new Mockery();
//or
   mocks.VerifyAllExpectationsHaveBeenMet();

And...

// Before:
        mockCurrencyService = mocks.NewMock<ICurrencyService>();

//After:
        mockCurrencyService = NewMock<ICurrencyService>();

Note:

    protected override void SetUp()
    {
      ...
    }

replaces...

    [SetUp]
    public void SetUp()
    {
      ...
    }








Hosted by Google Code