开发者

How to verify method arguments after method call?

Say I have a method A.Do(Arg arg) which assigns some properties of arg (class Arg), let say it sets arg.Prop1 = "done". And I'm testing a void method B.Do(void):

public class B
{
  public void Do()
  {
  开发者_运维知识库  var arg = InitArg();
    A.Do(arg)
    ...
  }
}

and I've mocked class A as new Mock< A>() with CodeBase=true. So how do I verify that arg.Prop1 == "done"?


You should have a unit test for class A that verifies the arg your pass in gets manipulated correctly rather than trying to test this behaviour via B.Do().


With the example as given, you can't. arg is private to the method B.Do(), so it's not visible to the outside world, so you can't verify any of its properties.


Anyway, it seems pretty reasonable to add such functionality for MoQ to verify the arguments after method call. Because, having the feature that MoQ verifies the number of method call is logically leads having argument verification feature.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜