
nmock2extensions
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()));
Stub.On(childScope) .Method(new GenericMethodMatcher("MethodName", typeof(Type1), typeof(Type3)) .Will(Return.Value(NewMock())); ```
.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();
//After: mockCurrencyService = NewMock(); ```
Note:
protected override void SetUp()
{
...
}
replaces...
[SetUp]
public void SetUp()
{
...
}