Trying to write Unit test for Silverlight 4.0 using Moq 4.0.10531.7
public delegate void DataReceived(ObservableCollection<TeamPlayerData> AllReadyPlayers, GetSquadDataCompletedEventArgs squadDetails);
public interface ISquadModel : IModelBase
{
void RequestData(int matchId, int teamId);
void SaveData();
event DataReceived DataReceivedEvent;
}
void MyTest()
{
Mock<ISquadModel> mockSquadModel = new Mock<ISquadModel>();
mockSquadModel.Raise(model => model.DataReceivedEvent += null, EventArgs.Empty);
}
Instead of raising the 'DataReceivingEvent' the following error is received:
Object of type 'Castle.Proxies.ISquadModelProxy' cannot be converted to type 'System.Collections.ObjectModel.ObservableCollection`1[TeamPlayerData]'.
Why attempt to convert mock to the type of 1st event parameter is performed?
How can I raise an event?
I've also tried another approach:
mockSquadModel
.Setup(model => model.RequestData(TestMatchId, TestTeamId))
.Raises(model => model.DataReceivedEvent += null, EventArgs.Empty)
;
this should raise event if case somebody calls 'Setup' method... Instead the same error is generated...
Any thoughts are welcome.
Thanks