How to check a method is called when I do not know what parameter for the method will be in Moq

I need to check if a method is called, however it gets a parameter object that I cannot determine at design time. I don't care what a parameter is, I just want to check if the method is called.

So I would like to name something like this:

var subDao = new Mock<ISubscriptionSnapshotDao>(); subDao.Verify(x => x.Save(), Times.Exactly(1)); 

However, ISubscriptionSnapshotDao.Save takes an object to save.

  Save(Subscription entity); 

Is there any way to verify that Save was called without knowing which parameter would be?

+4
source share
1 answer

Yes there is! If you know the type of parameter that the method expects.

 It.IsAny<T>() 

Try to execute

 subDao.Verify(x => x.Save(It.IsAny<Subscription>()), Times.Exactly(1)); 
+11
source

Source: https://habr.com/ru/post/1342803/


All Articles