Ejemplo n.º 1
0
 public override string ToString()
 {
     return(string.Format(
                @"expected: ""{0}"" but was: ""{1}""",
                (Expected == null) ? null : Expected.ToString(),
                (Actual == null) ? null : Actual.ToString()));
 }
        protected override Calculator Given()
        {
            Expected = Fixture.Create <int>();
            Numbers  = Expected.ToString();

            return(Fixture.Create <Calculator>());
        }
Ejemplo n.º 3
0
        protected override bool InternalPassed(object actual)
        {
            if (actual == null)
            {
                return(Expected == null || Expected.ToString().Equals("null", StringComparison.InvariantCultureIgnoreCase));
            }

            return(string.Format("{0:" + _format + "}", actual) == string.Format("{0:" + _format + "}", Expected));
        }
Ejemplo n.º 4
0
        public override string ToString()
        {
            if (Expected == null || Actual == null)
            {
                return(Message);
            }

            return($"Could not match expected type: {Expected.ToString()} with the actual type: {Actual.ToString()}" +
                   $"{Environment.NewLine} In line: {Line.ToString()}, column: {Column.ToString()} {Environment.NewLine}" +
                   Message);
        }
 protected override bool InternalPassed(object actual)
 {
     if (actual == null)
     {
         return(Expected == null || Expected.ToString().Equals("null", StringComparison.InvariantCultureIgnoreCase));
     }
     else
     {
         return(actual.Equals(Expected));
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Builds the verification failure message.
        /// </summary>
        /// <returns></returns>
        public string BuildVerificationFailureMessage()
        {
            StringBuilder sb = new StringBuilder();
            string        expectationMessege = ErrorMessage;

            sb.Append(expectationMessege).Append(' ');
            sb.Append("Expected #");
            sb.Append(Expected.ToString()).Append(", ");
            sb.Append("Actual #").Append(ActualCallsCount).Append('.');
            return(sb.ToString());
        }
Ejemplo n.º 7
0
        public override string ToString()
        {
            StringBuilder Builder = new StringBuilder();

            Builder.Append(string.Format("<Expected>{0}</Expected><Result>{1}</Result><ErrorText>{2}</ErrorText><Trace>{3}</Trace><ErrorType>{4}</ErrorType>",
                                         (Expected == null) ? "" : Expected.ToString().StripIllegalXML(),
                                         (Result == null) ? "" : Result.ToString().StripIllegalXML(),
                                         string.IsNullOrEmpty(Message) ? "" : this.Message.StripIllegalXML(),
                                         string.IsNullOrEmpty(StackTrace) ? "" : this.StackTrace.StripIllegalXML(),
                                         this.GetType().Name.StripIllegalXML()));
            return(Builder.ToString());
        }
Ejemplo n.º 8
0
 public override ConstraintResult ApplyTo <TActual>(TActual actual)
 {
     Description = Expected.ToString();
     // TODO: fix this to work with hierarchies
     if (actual is IEnumerable <Int32> transformed)
     {
         // var orderConstraint = new CollectionOrderedConstraint();
         // var constraintResult = orderConstraint.ApplyTo(transformed);
         // return constraintResult;
         var residual = transformed
                        .SkipWhile(e => e.CompareTo(this.Pivot) == -1)
                        .SkipWhile(e => e.CompareTo(this.Pivot) == 0)
                        .SkipWhile(e => e.CompareTo(this.Pivot) == 1);
         return(new EmptyConstraint().ApplyTo(residual));
         // return new ConstraintResult(this, actual, true);
     }
     return(new ConstraintResult(this, actual, false));
 }
Ejemplo n.º 9
0
        protected override bool InternalPassed(object actual)
        {
            if (actual == null)
            {
                return(Expected == null || Expected.ToString().Equals("null", StringComparison.InvariantCultureIgnoreCase));
            }

            try
            {
                // this will compare double and int as well as possible (eg int 3 will equal double 3, unless there are rounding error type issues)
                // if there are rounding type issues, then use "Percentage Precision" in the Excel spreadsheet to indicate how much difference is allowable
                return((dynamic)actual == (dynamic)Expected);
            }
            catch
            {
                // it is possible that the dynamic comparison fails (it can't compare objects to each other for example), in which case we just return false.
                // the comparisons should all be on primitives, but we have no control over what the system under test returns.
                return(false);
            }
        }
        protected override bool InternalPassed(object actual)
        {
            if (actual == null)
            {
                return(Expected == null || Expected.ToString().Equals("null", StringComparison.InvariantCultureIgnoreCase));
            }

            double actualDouble;

            try
            {
                actualDouble = Convert.ToDouble(actual);
            }
            catch (Exception e)
            {
                throw new Exception("EqualityAssertionWithPercentagePrecision must be used on a property that can be converted to a double, actual value passed was " + actual.ToString(), e);
            }

            double difference = Math.Abs(actualDouble - (double)Expected);

            return(difference <= Math.Abs((double)Expected * _percentagePrecision));
        }
Ejemplo n.º 11
0
 public string GetSolution()
 {
     return(Expected == null?string.Empty: Expected.ToString());
 }
Ejemplo n.º 12
0
 public string GetSolution()
 {
     return(Expected.ToString());
 }
Ejemplo n.º 13
0
 public override void When()
 {
     Expected = DateTime.Today;
     Actual   = TypeParser.Parse <DateTime?>(Expected.ToString());
 }
Ejemplo n.º 14
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);
        }