Esempio n. 1
0
        private bool CheckProperty(object actual, int i, Type type)
        {
            bool passed = true;

            string label        = this.GetLabel(i);
            string propertyName = NameComparer.NormalizeName(label);

            PropertyInfo pi = ValueGetter.GetPropertyInfo(type, propertyName);

            if (pi != null)
            {
                object actualValue   = pi.GetValue(actual, null);
                object expectedValue = ValueParser.ParseValue(this.GetValue(i), pi.PropertyType);

                if (!object.Equals(actualValue, expectedValue))
                {
                    this.values[i] = string.Format("{0} (was {1})", expectedValue, actualValue);
                    passed         = false;
                }
            }
            else
            {
                this.values[i] = string.Format("{0} (unknown)", this.GetValue(i));
                passed         = false;
            }

            return(passed);
        }
Esempio n. 2
0
        private bool CheckOutputParameter(Match match, Step step, ParameterInfo pi, object parameter)
        {
            Type type = pi.ParameterType.GetElementType();

            if (InlineTypes.InlineTypeExistsFor(type))
            {
                object expectedValue = ValueParser.ParseValue(match.Groups[pi.Name].Value, type);
                object actualValue   = parameter;

                if (!object.Equals(actualValue, expectedValue))
                {
                    Match m     = GetMatch(step);
                    Group group = m.Groups[pi.Name];
                    step.Text = step.Text.Substring(0, group.Index)
                                + string.Format("{0} (was {1})", expectedValue, actualValue)
                                + step.Text.Substring(group.Index + group.Length);
                    return(false);
                }
            }
            else if (step.Block != null && BlockTypes.BlockTypeExistsFor(type))
            {
                return(step.Block.Check(parameter));
            }

            return(true);
        }
Esempio n. 3
0
        private bool CheckExpectedCell(int columnIndex, object current, int rowIndex, bool updateCell)
        {
            bool passed = true;

            string       header = this.GetHeader(columnIndex);
            PropertyInfo pi     = this.GetPropertyInfo(current.GetType(), header);

            if (pi != null)
            {
                object actualValue   = pi.GetValue(current, null);
                object expectedValue = ValueParser.ParseValue(this.GetValue(rowIndex, columnIndex), pi.PropertyType);

                if (!object.Equals(actualValue, expectedValue))
                {
                    if (updateCell)
                    {
                        this.rows[rowIndex][columnIndex] = string.Format("{0} (was {1})", expectedValue, actualValue);
                    }

                    passed = false;
                }
            }
            else
            {
                this.rows[rowIndex][columnIndex] = string.Format("{0} (unknown)", this.GetValue(rowIndex, columnIndex));
                passed = false;
            }

            return(passed);
        }
Esempio n. 4
0
        private object GetParameterFromMatch(ParameterInfo pi, Match match, IBlock block)
        {
            if (InlineTypes.InlineTypeExistsFor(pi.ParameterType))
            {
                if (match.Groups[pi.Name].Success)
                {
                    string value = match.Groups[pi.Name].Value;
                    return(ValueParser.ParseValue(value, pi.ParameterType));
                }
            }
            else if (block != null && BlockTypes.BlockTypeExistsFor(pi.ParameterType))
            {
                BlockType blockType = BlockTypes.GetBlockTypeFor(pi.ParameterType);
                return(blockType.GetObject(pi.ParameterType, block));
            }

            return(null);
        }
Esempio n. 5
0
 /// <summary>
 /// Sets the formatted value.
 /// </summary>
 /// <param name="value">The value.</param>
 public void SetFormattedValue(string value)
 {
     SetValue(ValueParser.ParseValue(value, GetValueType()));
 }