How can a C# Func be mocked so it returns different values or exceptions when invoked multiple times?
Mock<Func<bool>> mock = new Mock<Func<bool>>();
mock.SetupSequence(m => m.Invoke())
.Throws<Exception>()
.Returns(true);
When run, the following exception is raised:
System.InvalidCastException : Unable to cast object of type
System.Linq.Expressions.InstanceMethodCallExpressionN' to type
'System.Linq.Expressions.InvocationExpression'.
I've seen another SO answer about using SetupSet
, however, I need a sequence.