Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moq - Using VerifySet to check number of times called

Tags:

c#

moq

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
like image 400
Matt Avatar asked Jul 27 '10 14:07

Matt


People also ask

Which method on expect () is used to count the number of times a method to have been called?

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.

What is verifiable in MOQ?

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.


1 Answers

You need to call the function Times.Once():

mockTimer.VerifySet(timer => timer.Prop = value, Times.Once()); 
like image 176
Darin Dimitrov Avatar answered Oct 24 '22 00:10

Darin Dimitrov