简体   繁体   中英

How to pass an object to a Method using FitNesse and Slim

I'm using FitNesse and SLIM and I would like to be able to pass an object to a method and can't seem to find out how? How do you do this using SLIM?

So for example I want to build a call object

!|FitTesting.MakeCall                             |
|ANI       |Call Type|Call Id|Call Key No| Data|
|4403951403|2        |2000   |8000       |5000 |

I want to store that object in a symbol or variable name CallObject

Then I want to use that object in the Start Call method.

|script | FitTesting.PracticeCallTestFixture|
|Initialize Call Fixture|
|Start Call|<<With Call Object>>
|check|Check For Call|true|
|Finalize Phone Desktop|

I tried to use a dictionary but got the following exception

EXCEPTION_:fitSharp.Machine.Exception.ParseException1[System.String]: Parse parameter 1 for 'UpdateECCData' type System.Collections.Generic.Dictionary2[System.String,System.String] failed. ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at fitSharp.Machine.Model.BranchList1.get_Item(Int32 index) at fitSharp.Slim.Operators.ParseDictionary.Parse(Type type, TypedValue instance, Tree1 parameters) at fitSharp.Machine.Engine.ProcessorBase2.<>c__DisplayClass11.<>c__DisplayClass13.<Parse>b__10(ParseOperator1 o) at fitSharp.Machine.Engine.ProcessorBase2.<>c__DisplayClass11.<Parse>b__e(OperationLogging logging) at fitSharp.Machine.Engine.ProcessorBase2.DoLoggedOperation[R](String startMessage, Func2 operation) at fitSharp.Machine.Engine.ParameterList1.ParseParameterValue(RuntimeMember member, TypedValue instance, Tree1 parameter, Int32 parameterIndex) --- End of inner exception stack trace --- at fitSharp.Machine.Engine.ParameterList1.ParseParameterValue(RuntimeMember member, TypedValue instance, Tree1 parameter, Int32 parameterIndex) at fitSharp.Machine.Engine.ParameterList1.<>c_DisplayClass1.b_0(List1 parameterList, Tree1 parameter) at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable1 source, TAccumulate seed, Func3 func) at fitSharp.Machine.Engine.ParameterList1.GetParameterList(TypedValue instance, Tree1 parameters, RuntimeMember member) at fitSharp.Machine.Engine.InvokeDefault2.Invoke(TypedValue instance, String memberName, Tree1 parameters) at fitSharp.Slim.Operators.InvokeLibrary.Invoke(TypedValue instance, String memberName, Tree1 parameters) at fitSharp.Machine.Engine.ProcessorBase2.<>c_DisplayClass18.<>c_DisplayClass1a.b_17(InvokeOperator1 o) at fitSharp.Machine.Engine.ProcessorBase2.<>c_DisplayClass18.b_15(OperationLogging logging)
   at fitSharp.Machine.Engine.ProcessorBase2.DoLoggedOperation[R](String startMessage, Func2 operation)
   at fitSharp.Slim.Operators.InvokeInstructionBase.InvokeMember(Tree1 parameters, Int32 memberIndex) at fitSharp.Slim.Operators.ExecuteCall.ExecuteOperation(Tree1 parameters)
   at fitSharp.Slim.Operators.InvokeInstructionBase.Invoke(TypedValue instance, String memberName, Tree`1 parameters)

Here is the fit markup

!|FitTestingConnectCTI.MakeCall                                                                |
|ANI       |Call Type|Router Call Key Id|Router Call Key Day|Update ECC Data                   |
|4403951403|2        |2000              |5000               |!{ANI:4403951403,StateAbbr:OH}    |

Here is my method call

   public void UpdateECCData(Dictionary<string,string> eccDictionary)
    {
        if (eccDictionary != null)
        {
            if (eccDictionary.Count > 0)
            {
                foreach (KeyValuePair<string, string> keyValuePair in eccDictionary)
                {
                    ECCData.Add(keyValuePair.Key,keyValuePair.Value);
                }
            }
        }
    }

For c# I don't know. For Java you could either register a custom type , or rewrite the method to accept a Hashtable (ie Dictionary) and use the Hash widget .

You can also pass the parameter in Fitnesse in Json format, then implement a method in your code that converts from json to Dictionnary. What I did - using Java - is the following:

  1. Pass a string in Fitnesse having jsonFormat. For example {"username":"xxx", "password":"yyy"}
  2. In the code the method does the following:

    public void login(String credentials){ Map<String,String> cred = (Map<String, String>)JSONValue.parse(credentials); }

In this case you will be only dealing with json on the Fitnesse side. u just need to change the way of converting json to map (json to dictionary in C#) Hope this helps a bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM