问题
我试图在c#中创建一个容器数组,将其作为测试结果传递回TestStand,而且似乎没有一种简单的方法来完成这个任务。
动机
在c#中,我有来自我的测试系统的List<Dictionary<string,object>>中包含的结果,我希望这些结果显示在我的测试报告中。Dictionary<string,object>具有不同类型的可变元素数。
尝试解决方案
如果给予:
var result = sequenceContext.AsPropertyObject().EvaluateEx(destination, EvaluationOptions.EvalOption_NoOptions);哪里
我尝试了几种不同的方法来向result中添加一个容器数组,例如:
var newPropertyObject = sequenceContext.Engine.NewPropertyObject(PropertyValueTypes.PropValType_Container, true, string.Empty, PropertyOptions.PropOption_InsertIfMissing);
result.SetPropertyObject("TestResultDestination", PropertyOptions.PropOption_InsertIfMissing, newPropertyObject);
result.SetFlags("TestResultDestination", PropertyOptions.PropOption_NoOptions, PropertyFlags.PropFlags_IncludeInReport | PropertyFlags.PropFlags_IsMeasurementValue);它将容器数组添加到我的结果中,但是,任何向容器数组中插入元素的尝试都会导致异常。
有什么想法?
发布于 2013-10-04 20:00:59
我离得很近,我错过了几个关键步骤:
if (!result.Exists("TestResultDestination", 0))
{
//once we have added this element do not add it again, it will overwrite the other array elements
var newPropertyObject = sequenceContext.Engine.NewPropertyObject(PropertyValueTypes.PropValType_Container, true, string.Empty, PropertyOptions.PropOption_InsertIfMissing);
//for my example I only need 5 elements, set the dimension of the array
newPropertyObject.SetNumElements(5, 0);
result.SetPropertyObject("TestResultDestination", PropertyOptions.PropOption_InsertIfMissing, newPropertyObject);
result.SetFlags(newKey, PropertyOptions.PropOption_NoOptions, PropertyFlags.PropFlags_IncludeInReport | PropertyFlags.PropFlags_IsMeasurementValue);
}然后可以通过使用数组语法(即TestResultDestination[0] )来存储实际结果来处理数组中的元素。
https://stackoverflow.com/questions/19189668
复制相似问题