I am trying to use VerifySet with Moq to check the number of times a setter on a collaborating Object is being called. But when I put in the Times portion of the call I get an error that the assignment operator is not valid in an expression tree.
mockTimer.VerifySet(timer => timer.Prop = value); //Works fine
mockTimer.VerifySet(timer => timer.Prop = value, Times.Once); //Compile Error
Using Verify This is probably the best way to go as Verify is designed for this exact purpose - to verify the number of times a method has been called.
Verifiable(); 'Setup' mocks a method and 'Returns' specify what the mocked method should return. 'Verifiable' marks this expectation to verified at the end when Verify or VerifyAll is called i.e. whether AddIncomePeriod was called with an object of IncomePeriod and if it returned the same output.
You need to call the function Times.Once()
:
mockTimer.VerifySet(timer => timer.Prop = value, Times.Once());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With