Ejemplo n.º 1
0
        /// <summary>
        /// Stores an object as a result.  These results will be propagated to the ResultStore after the TestStep completes.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name">The name of the result.</param>
        /// <param name="result">The result whose properties should be stored.</param>
        public void Publish <T>(string name, T result)
        {
            var runtimeType = TypeData.GetTypeData(result);

            if (AnonResultFunc == null)
            {
                lock (resultFuncLock)
                    AnonResultFunc = new Dictionary <ITypeData, Func <string, object, ResultTable> >();
            }
            if (!AnonResultFunc.ContainsKey(runtimeType))
            {
                var Props     = runtimeType.GetMembers().Where(x => x.Readable && x.TypeDescriptor.DescendsTo(typeof(IConvertible))).ToArray();
                var PropNames = Props.Select(p => p.GetDisplayAttribute().GetFullName()).ToArray();

                AnonResultFunc[runtimeType] = (n, v) =>
                {
                    var cols = new ResultColumn[Props.Length];

                    for (int i = 0; i < Props.Length; i++)
                    {
                        cols[i] = new ResultColumn(PropNames[i], GetArray(Props[i].TypeDescriptor.AsTypeData().Type, Props[i].GetValue(v)));
                    }

                    return(new ResultTable(n, cols));
                };
            }

            var res = AnonResultFunc[runtimeType](name, result);

            DoStore(res);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Stores an object as a result.  These results will be propagated to the ResultStore after the TestStep completes.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="result">The result whose properties should be stored.</param>
        public void Publish <T>(T result)
        {
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }
            ITypeData runtimeType = TypeData.GetTypeData(result);

            if (ResultFunc == null)
            {
                lock (resultFuncLock)
                    ResultFunc = new Dictionary <ITypeData, Func <object, ResultTable> >();
            }
            if (!ResultFunc.ContainsKey(runtimeType))
            {
                var Typename  = runtimeType.GetDisplayAttribute().GetFullName();
                var Props     = runtimeType.GetMembers().Where(x => x.Readable && x.TypeDescriptor.DescendsTo(typeof(IConvertible))).ToArray();
                var PropNames = Props.Select(p => p.GetDisplayAttribute().GetFullName()).ToArray();

                ResultFunc[runtimeType] = (v) =>
                {
                    var cols = new ResultColumn[Props.Length];
                    for (int i = 0; i < Props.Length; i++)
                    {
                        cols[i] = new ResultColumn(PropNames[i], GetArray(Props[i].TypeDescriptor.AsTypeData().Type, Props[i].GetValue(v)));
                    }
                    return(new ResultTable(Typename, cols));
                };
            }

            var res = ResultFunc[runtimeType](result);

            DoStore(res);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Called by OpenTAP when the source TestStep publishes results. This is happening in a background thread.
 /// </summary>
 public void OnResultPublished(TestStepRun stepRun, ResultTable result)
 {
     if (stepRun.TestStepId == SourceTestStep?.Id)
     {
         ResultColumn column = result.Columns.FirstOrDefault(col => col.Name == ResultColumnName);
         if (column != null)
         {
             lock (Result)
             {
                 Result.Enqueue(column.GetValue <T>(0));
                 ItemsInQueue.Set();
             }
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates an empty vector.
 /// </summary>
 public ResultTable()
 {
     Name    = "";
     Columns = new ResultColumn[0];
     Rows    = 0;
 }