Menu

#13 Predicates as expected values for static mocks

Design_Additions
open-later
nobody
5
2005-02-16
2004-08-27
Max Kulkin
No

Add the ability to provide IPredicate object as an
expected parameter in any MockObject.

E.g.,I faced problem to provide IsAnything() predicate
to MockDataParameter.Value.

Discussion

  • Griffin Caprio

    Griffin Caprio - 2004-08-27
    • labels: 498021 --> Dynamic Mock Objects
     
  • Griffin Caprio

    Griffin Caprio - 2004-08-27

    Logged In: YES
    user_id=397472

    Could you be more specific as to this request.

    Do you mean using IPredicates in the static part of the library?

    Perhaps some pseudo code on what you are trying to do would help.

    Griffin

     
  • Max Kulkin

    Max Kulkin - 2004-08-28

    Logged In: YES
    user_id=358624

    Yes! I was surprised, that IPredicate defined only in
    DotNetMock.Dynamic namespace, not in DotNetMock namespace.
    It's a very handy thing.

    MockDataParameter param = new MockDataParameter();
    param.DbType = DbType.String;
    param.Value = new DotNetMock.Dynamic.Predicates.IsAnything();

     
  • Max Kulkin

    Max Kulkin - 2004-08-28

    Logged In: YES
    user_id=358624

    Oops.. Sorry for typo.
    I really meant this:

    MockDataParameter param = new MockDataParameter();
    param.SetExpectedType( DbType.String );
    param.SetExpectedValue( new
    DotNetMock.Dynamic.Predicates.IsAnything() );

     
  • Max Kulkin

    Max Kulkin - 2004-08-28

    Logged In: YES
    user_id=358624

    I think that this could be done, if Verify method in
    Expectation* classes would be changed to (e.g. for
    ExpectationValue):

    public override void Verify() {
    if (this.HasExpectations) {
    IPredicate predicate = expectedArg as IPredicate;

        // if expectedArg is not an IPredicate, use default
        // behavior of IsEqual or IsAnything
        if \(predicate == null\) \{
            predicate = new IsEqual\(this.\_expectedValue\);
        \}
    
        Assertion.Assert\("Value do not equal for object " +
    

    this.name, predicate.Eval(this._actualValue));
    }
    }

     
  • rgavrilov

    rgavrilov - 2004-12-28

    Logged In: YES
    user_id=1170022

    Wrap instance of IsAnything in IsEqual predicate as in:
    mockCtrl.Expect("Method", new IsEqual(new IsAnything()));

    Since IsAnything does not have a state, you probably need to
    compare references. IsEqual uses Object.Equals to evaluate
    equality which should work just as you want it.

    Regards,
    Roman V. Gavrilov

     
  • Choy Rim

    Choy Rim - 2005-02-16
    • status: open --> open-later
     
  • Choy Rim

    Choy Rim - 2005-02-16

    Logged In: YES
    user_id=1023300

    This is a good idea but we'll have to defer it for a while.
    I've got a few other things on my plate. I haven't fully
    grokked the static mock stuff yet anyways.

     
  • Choy Rim

    Choy Rim - 2005-02-16
    • assigned_to: gcaprio --> nobody
     
  • Choy Rim

    Choy Rim - 2005-02-16
    • summary: Predicates as expected values --> Predicates as expected values for static mocks
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.