tags:

views:

70

answers:

3

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"?

A: 

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.

Jeremy McGee
Thanks. Although I don't know what is "inside" of MoQ, it still lets me to verify how many times A.Do was called. So I was wondering if it lets me verify the arguments as well - but I guess no.. a pity
David
+1  A: 

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().

Paolo
A: 

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.

David