예제 #1
0
        protected override void DescribeMismatchSafely(T[] actualItems, IDescription mismatchDescription)
        {
            if (_elementMatchers.Count != actualItems.Length)
            {
                mismatchDescription.AppendText("array length was ");
                // ReSharper disable once HeapView.BoxingAllocation
                mismatchDescription.AppendValue(actualItems.Length);
                return;
            }

            for (var i = 0; i < _elementMatchers.Count; ++i)
            {
                if (_elementMatchers[i].Matches(actualItems[i]))
                {
                    // If it matches, continue
                    continue;
                }

                // If it doesnt match, write out why
                mismatchDescription.AppendText("element ");
                // ReSharper disable once HeapView.BoxingAllocation
                mismatchDescription.AppendValue(i);
                mismatchDescription.AppendText(" ");
                _elementMatchers[i].DescribeMismatch(actualItems[i], mismatchDescription);
                return;
            }
        }
 public override void Describe(IDescription description)
 {
     description.AppendText("a string ");
     description.AppendValue(_originalValue);
     description.AppendText(" compressing white space to ");
     description.AppendValue(_value);
 }
 protected override void DescribeMismatchSafely(IEnumerable <char> item, IDescription mismatchDescription)
 {
     mismatchDescription.AppendText("was ");
     mismatchDescription.AppendValue(item);
     mismatchDescription.AppendText(" compressing white space to ");
     mismatchDescription.AppendValue(RemoveRepeatedSpaces(item));
 }
예제 #4
0
 public bool Matches(TM item)
 {
     if (_matchers.Count != 0)
     {
         return(IsMatched(item));
     }
     _description.AppendText("no match for: ");
     _description.AppendValue(item);
     return(false);
 }
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public void DescribeOn(IDescription description)
 {
     description.AppendText("set ");
     description.AppendText(name);
     description.AppendText("=");
     description.AppendValue(value);
 }
예제 #6
0
        public override void Describe(IDescription description)
        {
            MatchCollection matches = ArgPattern.Matches(_descriptionTemplate);

            int textStart = 0;

            foreach (Match match in matches)
            {
                // Add the description
                string subStr = _descriptionTemplate.Substring(textStart, match.Index - textStart);
                description.AppendText(subStr);

                // Add the value of the description
                int argIndex = getIndex(match);
                description.AppendValue(_args[argIndex]);

                // Move our new start location
                textStart = match.Index + match.Length;
            }

            if (textStart < _descriptionTemplate.Length)
            {
                string postLength = _descriptionTemplate.Substring(textStart);
                description.AppendText(postLength);
            }
        }
예제 #7
0
 public override void Describe(IDescription description)
 {
     description.AppendText("a string equal to ");
     description.AppendValue(_value);
     description.AppendText(_comparison == StringComparison.CurrentCultureIgnoreCase
         ? " culture ignoring case"
         : " ignoring case");
 }
 public bool Matches(T item)
 {
     if (_matchers.Count >= _nextMatchIndex)
     {
         return(IsMatched(item));
     }
     _description.AppendText("not matched: ");
     _description.AppendValue(item);
     return(false);
 }
예제 #9
0
        protected override bool Matches(object actual, IDescription mismatchDescription)
        {
            if (actual == null)
            {
                mismatchDescription.AppendText("null");
                return(false);
            }

            if (!_type.IsInstanceOfType(actual))
            {
                Type actualType = actual.GetType();
                mismatchDescription.AppendValue(actual).AppendText(" is an instance of ").AppendText(actualType.FullName);
                return(false);
            }
            return(true);
        }
예제 #10
0
        protected override bool Matches(T item, IDescription mismatchDescription)
        {
            if (ReferenceEquals(item, null))
            {
                mismatchDescription.AppendText("null");
                return(false);
            }

            if (expectedType.IsInstanceOfType(item) == false)
            {
                mismatchDescription.AppendValue(item).AppendText(" is an instance of {0} not {1}", item.GetType().FullName,
                                                                 expectedType.FullName);
                return(false);
            }

            return(true);
        }
예제 #11
0
        /// <summary>
        /// Describes this object.
        /// </summary>
        /// <param name="description"></param>
        public override void DescribeOn(IDescription description)
        {
            description.AppendText("element of [");

            bool separate = false;
            foreach (object element in collection)
            {
                if (separate)
                {
                    description.AppendText(", ");
                }

                description.AppendValue(element);
                separate = true;
            }

            description.AppendText("]");
        }
예제 #12
0
        protected override void DescribeMismatchSafely(IDictionary <TKey, TValue> actual, IDescription mismatchDescription)
        {
            mismatchDescription.AppendText("dictionary was [");
            bool separate = false;

            foreach (TKey key in actual.Keys)
            {
                if (separate)
                {
                    mismatchDescription.AppendText(", ");
                }

                TValue value = actual[key];
                mismatchDescription.AppendValue(key)
                .AppendText("->")
                .AppendValue(value);

                separate = true;
            }
            mismatchDescription.AppendText("]");
        }
예제 #13
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public void DescribeOn(IDescription description)
 {
     description.AppendText("throw ");
     description.AppendValue(exception);
 }
예제 #14
0
 public override void Describe(IDescription description)
 {
     description.AppendValue(_expectedValue);
 }
예제 #15
0
 public void DescribeTo(IDescription description)
 {
     description.AppendValue(_value);
 }
예제 #16
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public override void DescribeOn(IDescription description)
 {
     description.AppendText("same as ");
     description.AppendValue(expected);
 }
예제 #17
0
        /// <summary>
        /// Writes the parameter list to the specified <paramref name="writer"/>.
        /// </summary>
        /// <param name="writer">The writer where the description is written to.</param>
        /// <param name="count">The count of parameters to describe.</param>
        private void WriteParameterList(IDescription writer, int count)
        {
            for (int i = 0; i < count; i++)
            {
                if (i > 0)
                {
                    writer.AppendText(", ");
                }

                if (Method.GetParameters()[i].IsOut)
                {
                    writer.AppendText("out");
                }
                else
                {
                    writer.AppendValue(Parameters[i]);
                }
            }
        }
예제 #18
0
파일: IsEqual.cs 프로젝트: mminns/NHamcrest
 public override void DescribeTo(IDescription description)
 {
     description.AppendValue(@object);
 }
예제 #19
0
 protected override void DescribeMismatchSafely(string item, IDescription mismatchDescription)
 {
     mismatchDescription.AppendText(" was ");
     mismatchDescription.AppendValue(item);
 }
예제 #20
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public void DescribeOn(IDescription description)
 {
     description.AppendText("a clone of ");
     description.AppendValue(prototype);
 }
예제 #21
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public void DescribeOn(IDescription description)
 {
     description.AppendText("return ");
     description.AppendValue(result);
 }