Rhino Mocks: Is there a way to check the restriction on a property of a property of an object?

If i have

class ObjA {
  public ObjB B;
}
class ObjB {
  public bool Val;
}

and

class ObjectToMock {
  public DoSomething(ObjA obj){...}
}

Is there a way to determine the expectation that not only will cause DoSomething, but that obj.B.Val == true?

I tried

Expect.Call(delegate { 
    mockObj.DoSomething(null);
}).Constraints(new PropertyIs("B.Val", true));

but he seems to fail no matter what that value is.

+3
source share
1 answer

You can try using Is.Matching () and provide a predicate restriction (for clarity, translated out of line):

    Predicate nestedBValIsTrue = delegate(ObjA a) { return a.B.Val == true;};
    Expect.Call( delegate {mockobj.DoSomething(null);})
           .Constraints( Is.Matching(nestedBValIsTrue));
+2
source

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


All Articles