Find the methods setup on mock using MOQ
c#, moq
Solution
The Mock<> type will have a private Moq.SetupCollection named 'Setups'. While Moq.SetupCollection has a private List<Moq.Setup> named 'setups'.
Easy to check while debugging
Or you can do so with reflection:
var bindings = BindingFlags.Instance | BindingFlags.NonPublic;
var setupCollectionProperty = Mapper.GetType().GetProperty("Setups", bindings);
var setupCollection = setupCollectionProperty.GetValue(Mapper);
var setupList = setupCollection.GetType().GetField("setups", bindings);
var setups = setupList.GetValue(setupCollection);
Problem
Is there any way to list all the mocked methods (Setups) on a Mock? Lets say, I create mock as following: ``` Mock<IAnInterface> aMock = new Mock<IAnInterface>(); aMock.Setup(am => am.Execute()).Returns(true); ``` Now, i need to find if `Execute` has been setup on `aMock`?