开发者

How to Verify a method is called when I don't know what the parameter for the method will be in Moq

开发者 https://www.devze.com 2023-02-15 07:19 出处:网络
I need to verify that a method is called, however it receives a parameter object which I can\'t determine at design time. I don\'t care what the parameter is, I just want to verify that the method is

I need to verify that a method is called, however it receives a parameter object which I can't determine at design time. I don't care what the parameter is, I just want to verify that the method is called.

So I would like to call something like this:

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

However ISubscri开发者_开发百科ptionSnapshotDao.Save takes an object to save.

 Save(Subscription entity);

Is there a way verify that Save has been called without knowing what the parameter will be?


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

It.IsAny<T>()

Try the following

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

精彩评论

暂无评论...
验证码 换一张
取 消