Using Moq can you verify a method call with an anonymous type?

前端 未结 3 1824
萌比男神i
萌比男神i 2021-02-18 17:50

I\'m trying to verify a method call using Moq, but I can\'t quite get the syntax right. Currently I\'ve go this as my verify:

repository.Verify(x => x.Execute         


        
3条回答
  •  悲&欢浪女
    2021-02-18 18:21

    One option is to "verify" it in a Callback. Obviously this needs to be done at Setup time, e.g.:

    aMock.Setup(x => x.Method(It.IsAny())).Callback(
      (p1) =>
        {
          dynamic o = p1;
          Assert.That(o.Name, Is.EqualTo("Bilbo"));
        });
    
        

    提交回复
    热议问题