I have the following method signature that I would like to set up a mock:-
public int Update<T>(T item) where T : IItemID, IItemData
When trying to set up the mock (using Moq), I cannot set the correct type for T:-
mock.Setup(x => x.Update(It.IsAny<???>()).Returns(1);
I've tried with a "fake" interface in my unit test project:-
public interface IFake : IITemID, IItemData
{
}
mock.Setup(x => x.Update(It.IsAny<IFake>()).Returns(1)
but the verify in my unit test fails because the object I'm using does not inherit from IFake. The object is an actual type that inherits from IItemID and IItemData.
Is there anyway to set up the mock for this Update method with multiple constraints?
UPDATE Thanks for the info all. After going through this again it looks like the best solution is to not use multiple interface constraints as this can't be mocked. I just wondered if there was a solution to this as it seems like something that can cause massive problems later down the line.
Thanks again!
Update()method appear in both interfaces? If not can't you just mock the appropriate interface required for the unit test? - AlwaysLearninginterface IItem : IItemIdD, IItemDataand use that as a constraint. It will be easier to mock. - Johnny