This project is read-only.

Problem with EventBinding

Nov 15, 2013 at 11:18 AM
Edited Nov 15, 2013 at 12:17 PM

First off let me just say that I love using NMock3. Altough I'm not using it daily I try to live the TDD lifestyle.

My problem is that I'm trying to create a unit test that will test if our internal communication component is receiving updates then I will convert the message and send it to another source. So I need to mock out (or stub out) my component. This is fine but I also need to fire the event in my test. So if I use an EventInvoker I will be able to get a handle to the event but the argument will only take EventArgs as argument when calling Invoke. I need to pass in my own class here which the delegate is declared with. Is there anyway to do this?
var mockFactory = new MockFactory();
var mock = mockFactory.CreateMock<ICommunicator>();
var eventInvoker = mock.Stub.Out.EventBinding(_ => _.Updated += null);
eventInvoker.Invoke(new ValueUpdate(123));     //Will only accept EventArgs
BTW I'm using .NET 3.5

Nov 15, 2013 at 12:23 PM
Nevermind I found the DelegateBinding (mock.Stub.Out.DelegateBinding) which is what I'm looking for.