I can't seem to figure out how to mock this method properly. The method I want to mock is below:
public virtual void Publish<TEvent>(TEvent evt) where TEvent : IDomainEvent {
HandlerInvoker.Invoke(evt);
}
An example of a TEvent that I want to mock is:
public interface IOrderPlaced : IDomainEvent {}
I am able to mock this if I use:
mock.Setup(h => h.Publish(It.IsAny<IOrderPlaced>));
However, I wish to mock the method for all interfaces that derive from IDomainEvent like so:
mock.Setup(h => h.Publish(It.IsAny<IDomainEvent>));
but that doesn't work at all. It only works when I setup the mock using the specific interface. But that is completely unrealistic in my application as I have over 100 interfaces that derive from IDomainEvent. Not to mention it would be a beast to maintain if I had to mock each one individually. Does anyone see anything I'm doing wrong?