How to test event registration in Rhino Mocks
I am try开发者_JAVA技巧ing to write a Rhino Mocks test to verify that I have registered for an event. Here is my test:
var dataSvc = MockRepository.GenerateStub<IDataService>();
Search srch = new Search(dataSvc, vr);
dataSvc.GetCarriersCompleted += srch.OnCarrierDataReturned;
dataSvc.AssertWasCalled(x => x.GetCarriersCompleted += Arg<GetCarriersCompletedEventArgs>.Is.Anything);
My code is just a simple register for event like this:
public void GetCarrierList()
{
try
{
_dataService.GetCarriersCompleted += OnCarrierDataReturned; ; //hangedEventHandler(OnDataReturned);
_dataService.GetCarriersAsync(_param);
}
catch (Exception ex)
{
}
}
public void OnCarrierDataReturned(object sender, GetCarriersCompletedEventArgs e)
{
// get results
}
My data service looks like this:
void GetCarriersAsync(System.Collections.Generic.Dictionary<string, string> param);
event System.EventHandler<GetCarriersCompletedEventArgs> GetCarriersCompleted;
I can't figure out what Rhino Mocks needs for this test. The error is:
Error 7 Cannot implicitly convert type 'MACS2SLApp.MACSWcfServiceProxy.GetCarriersCompletedEventArgs' to 'System.EventHandler' C:\Documents and Settings\600124238\My Documents\MACS3\Prototype\Web UI\MACSUnitTests\MACSUnitTests.cs 126 68 MACSUnitTests
Any ideas would be appreciated.
thanks, Bill44077
Your Arg<>
constraint needs to be the type of event, not the type of event args. Try:
Arg<EventHandler<GetCarriersCompletedEventArgs>>.Is.Anything
精彩评论