0

我正在使用 FitNesse 和 SLIM,我希望能够将对象传递给方法,但似乎不知道如何?你如何使用 SLIM 做到这一点?

所以例如我想建立一个调用对象

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

我想将该对象存储在符号或变量名中CallObject

然后我想在 Start Call 方法中使用该对象。

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

我尝试使用字典,但出现以下异常

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)

这是适合标记

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

这是我的方法调用

   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);
                }
            }
        }
    }
4

2 回答 2

0

您也可以将 Fitnesse 中的参数以 Json 格式传递,然后在代码中实现从 json 转换为 Dictionnary 的方法。我所做的 - 使用 Java - 如下:

  1. 在具有 jsonFormat 的 Fitnesse 中传递一个字符串。例如{"username":"xxx", "password":"yyy"}
  2. 在代码中,该方法执行以下操作:

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

在这种情况下,您将只在 Fitnesse 端处理 json。您只需要更改将 json 转换为 map 的方式(json 到 C# 中的字典)希望这会有所帮助。

于 2014-01-28T13:37:29.553 回答
0

对于 c# 我不知道。对于 Java,您可以注册自定义类型,或者重写方法以接受 Hashtable(即 Dictionary)并使用Hash 小部件

于 2013-11-18T07:55:45.677 回答