Ejemplo n.º 1
0
        ///<inheritdoc/>
        public override bool Validate()
        {
            if (Actual == null)
            {
                ActualDisplayName = "null";
                return(false);
            }

            var actualType = Actual.GetType();

            if (actualType != Expected.GetType())
            {
                ActualDisplayName = "an object of type " + actualType.GetFriendlyName();
                return(false);
            }

            if (!Expected.Equals(Actual))
            {
                ActualDisplayName = (bool)Expected ? "false" : "true";
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public Boolean Check(Message msg, Message context, StepItem stepItem)
        {
            T actual = GetValue(msg);

            String expected;
            String received;

            Boolean success      = false;
            Type    type         = null;
            Type    expectedType = Expected.GetType();

            if (actual != null)
            {
                type = actual.GetType();
                if (type == typeof(byte[]))
                {
                    success = this.ValueEqual(actual, Expected);
                }
                else if (type == typeof(string))
                {
                    success = this.ValueEqual(actual, Expected);
                }
                else
                {
                    success = Expected.Equals(actual);
                }
            }
            if (!success)
            {
                if (expectedType == typeof(byte[]))
                {
                    expected = this.ToString(Expected);
                }
                else
                {
                    expected = Expected.ToString();
                }

                if (actual == null)
                {
                    received = "";
                }
                else if (type == typeof(byte[]))
                {
                    received = this.ToString(actual);
                }
                else
                {
                    received = actual.ToString();
                }
                #region MyRegion
                Reason = String.Format("期望{0}的值为\"{1}\",但得到\"{2}\"", Field, expected, received);
                RowItem bi = new RowItem();
                bi.ErrorInfo = String.Format("期望{0}的值为\"{1}\",但得到\"{2}\"", Field, expected, received);
                bi.Expected  = expected;
                bi.Name      = Field;
                bi.IsPassed  = false;
                bi.Parent    = null;
                bi.Received  = received;
                BaseItemInfo = bi;
                #endregion
            }

            return(success);
        }