I am creating a Unit test, using the moq.Mock class, to simulate the situation. I want to mock a method with a Template param, so that i can check what is being sent to it.
mockGateway = new Mock<GatewayClass>();
//this one works
mockGateway.Setup(e => e.Log(It.IsAny<LogLevel>(), It.IsAny<Exception>(), It.IsAny<string>(), It.IsAny<object[]>()))
.Callback<LogLevelClass, Exception, string,object[]>(LogCheck);
//this one doesnt work
mockGateway.Setup(e => e.SendAndListen<RequestClass>(It.IsAny<RequestClass>()))
.Callback<RequestClass>(SendCheck);
The Setup(e.. gives an 'Ambiguous invocation' Compile Error. The RequestClass gives a compile error of 'The Type must be convertible to an IMessage in order to use as parameter TMessage in generic sendandlisten, but RequestClass implements IMessage, but the metadata when viewed doesnt show this. as i am doing the Test in a different solution to the solution it is defined in.
private void LogCheck(LogLevel level, Exception ex, string str, object[] paramObjs)
{
//do something...
}
private void SendCheck<TMessage>(TMessage message)
where TMessage : class, IMessage,IRequestMessage, new()
{
//do something...
}
Can anyone show me how this should/ could be done?
Aucun commentaire:
Enregistrer un commentaire