Keeping in mind the answers on this question Settings variable values in a Moq Callback() call, which is how I came to understand (or so I thought) I can defer the execution of the Returns
, I'm not able to get it to work.
this.mock = new Mock<ICriteria>();
this.mock
.As<IRuleProcessor<Input, Output>>()
.Setup(m => m.Process(It.IsAny<Input>()))
.Returns((Input input) => new Output
{
ExecutionStatus = executionStatus
});
where the aforementioned code is executed in [TestInitialize]
and executionStatus
is defined like this:
private RuleExecutionStatus executionStatus = RuleExecutionStatus.Success;
and finally, executionStatus
is modified like this:
executionStatus = RuleExecutionStatus.FailedValidation;
in the test I'm executing before the SUT is executed. Now, when an internal method to the SUT is executed it calls Process
on the mock setup above. However, it's not grabbing the modified value, it's only grabbing the initial value.
Keep in mind, it wouldn't surprise me if I've set this up wrong.
How can I achieve modifying this status for one test in the class? All other tests need the success status.
Does it have something to do with the .As<IRuleProcessor<Input, Output>>()
? Does deferred execution like this not work when I have to setup a method on an inherited interface?