Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rhino Mocks: Is there any way to verify a constraint on an object property's property?

If I have

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

and

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

Is there any way to define an expectation that not only will DoSomething get called but that obj.B.Val == true?

I have tried

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

but it seems to fail no matter what the value is.

like image 722
George Mauer Avatar asked Dec 28 '25 05:12

George Mauer


1 Answers

You can try using Is.Matching() and providing a predicate constraint (moved out-of line for clarity):

    Predicate nestedBValIsTrue = delegate(ObjA a) { return a.B.Val == true;};
    Expect.Call( delegate {mockobj.DoSomething(null);})
           .Constraints( Is.Matching(nestedBValIsTrue));
like image 110
Philip Rieck Avatar answered Dec 30 '25 19:12

Philip Rieck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!