chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi again

Maybe i ask to much but u also deliver !!! so why not

How about an event that will fire every a succefull verification that way we can use the Parameters,DynamicReturnValue Delegate in much more ways!!!
asked by tolisss (28.8k points)

7 Answers

0 votes
How about an event that will fire every a succefull verification that way we can use the Parameters,DynamicReturnValue Delegate in much more ways!!!


Sounds like a very interesting idea.
How does this fit into a test driven environment?
If the test is successfull, shouldn't we just continue with the test?
answered by scott (32k points)
0 votes
sure but imagine that we use parameter checker delegate and assert a value with a value from a collection .We need a way to tell the delegate method to assert to the next item of the collection after the the first mock verification success
answered by tolisss (28.8k points)
0 votes
explain my self beter something like this
public void AssertRowCellDisplayText()
      {
         mockController.AlwaysReturn("RelationCount",1);
         mockController.AlwaysReturn("IsEmpty",false);

         currentViewIndex=0;
         int i=0;
         foreach (string key in Properties.LevelDefaults.Keys)
         {
            mockController.ExpectAndReturn("RelationName",key).Args(new ParameterChecker(CheckView));
            mockController.ExpectAndReturn("RelationName",key).Args(new ParameterChecker(CheckView));
            mockController.ExpectAndReturn("ChildList",xpCollections[i]).Args(
               new ParameterChecker(CheckView));
                mockController.AfterVerification+=new EventHandler(MethodName);
            i+=1;
         }
         AssertRowCellDisplayText(xpBaseObjects,exludedColumns);
      }

      public void MethodName(object sender,EventArgs e)
      {
         if (e.ExpectedMethod=="ChildList")
            currentViewIndex+=1;
      }

      int currentViewIndex=0;
      public bool CheckView(object parameter)
      {
         bool equals = Properties.Views[currentViewIndex].Equals(parameter);
         return equals;
      }


at the 1st loop Properties.Views contains only 1 item the 2nd item is added after succefull

mockController.ExpectAndReturn("ChildList",xpCollections[i]).Args(
               new ParameterChecker(CheckView));


i m sure u can implemented better than i did but i just try to make my self understandable
answered by tolisss (28.8k points)
0 votes
This might be a better way to do this:

// Class for checking parameters,
// We expect that the parameter will be the Properties.Views[currentViewIndex]
public class ViewChecker
{
    int currentViewIndex;
    // Set index 
    public ViewChecker(int index) 
    {
         currentViewIndex = index;
    }
    // Actual test
    public bool CheckView(object parameter)
    {
        return Properties.Views[currentViewIndex].Equals(parameter);
    }
    // Return Check Delegate
    public ParameterChecker Checker
    { 
       get { return new ParameterChecker(CheckView); }
    }
}


public void AssertRowCellDisplayText()
{
    mockController.AlwaysReturn("RelationCount",1);
    mockController.AlwaysReturn("IsEmpty",false);

    int i=0;
    foreach (string key in Properties.LevelDefaults.Keys)
    {
        mockController.ExpectAndReturn("RelationName",key).Args(new ViewChecker(0+i*3).Checker);
        mockController.ExpectAndReturn("RelationName",key).Args(new ViewChecker(1+i*3).Checker);
        mockController.ExpectAndReturn("ChildList",xpCollections[i]).Args(new ViewChecker(2+i*3).Checker);
        i+=1;
    }
    AssertRowCellDisplayText(xpBaseObjects,exludedColumns);
}
answered by scott (32k points)
0 votes
thnks for the effort and the code Scott . But i still wonder if the support for events will make our life easier?

What do u say?
answered by tolisss (28.8k points)
0 votes
thnks for the effort and the code Scott . But i still wonder if the support for events will make our life easier?

What do u say?


I have sent this request to our product manager. :D
answered by scott (32k points)
0 votes
Hi,
:D Good news, we have added MockMethodCalled events on a type/instance scope and on a method scope. for more information see the Call Events topic in the user Guide.
answered by richard (3.9k points)
...