public override void DescribeTo(IDescription description)
        {
            description.AppendText("a dictionary consisting of:");

            var first = true;

            using (description.IndentBy(4))
            {
                foreach (var entryDescriptor in _entryDescriptors)
                {
                    if (!first)
                    {
                        description.AppendText(",");
                    }

                    description.AppendNewLine()
                    .AppendText("an entry where:");

                    using (description.IndentBy(4))
                    {
                        description.AppendNewLine()
                        .AppendText("key: ")
                        .AppendDescriptionOf(entryDescriptor.KeyMatcher)
                        .AppendNewLine()
                        .AppendText("value: ")
                        .AppendDescriptionOf(entryDescriptor.ValueMatcher);
                    }

                    first = false;
                }
            }
        }
예제 #2
0
        private bool Matches(T o, IDescription mismatchDescription)
        {
            if (o == null)
            {
                mismatchDescription.AppendText("was null");
                return(false);
            }

            var failedMatchers = _matchers.Where(m => !m.Matches(o)).ToArray();

            if (failedMatchers.Length == 0)
            {
                return(true);
            }

            mismatchDescription.AppendText(_mismatchPrefix)
            .AppendText(" ")
            .AppendText(typeof(T).Name);

            if (typeof(T) != o.GetType())
            {
                mismatchDescription
                .AppendText(" {")
                .AppendText(o.GetType().Name)
                .AppendText("}");
            }
            mismatchDescription.AppendText(" where:");

            DescribeMatchers(mismatchDescription, failedMatchers, (d, m) => m.DescribeMismatch(o, d));

            return(false);
        }
예제 #3
0
파일: Throws.cs 프로젝트: mminns/NHamcrest
        protected override bool Matches(Action action, IDescription mismatchDescription)
        {
            try
            {
                action();
                mismatchDescription.AppendText("no exception was thrown");
            }
            catch (T ex)
            {
                if (predicate(ex))
                {
                    return(true);
                }

                mismatchDescription.AppendText("the exception was of the correct type, but did not match the predicate")
                .AppendNewLine()
                .AppendValue(ex);
            }
            catch (Exception ex)
            {
                mismatchDescription.AppendText("an exception of type {0} was thrown", ex.GetType())
                .AppendNewLine()
                .AppendValue(ex);
            }
            return(false);
        }
예제 #4
0
        public override void DescribeTo(IDescription description)
        {
            var matcherArray = _matcherCollection.ToArray();

            if (matcherArray.Length == 0)
            {
                description.AppendText("an empty list");
                return;
            }

            description.AppendText("a list containing:");

            using (description.IndentBy(4))
            {
                description.AppendNewLine();

                var first = true;

                foreach (var matcher in matcherArray)
                {
                    if (!first)
                    {
                        description.AppendText(",").AppendNewLine();
                    }
                    description.AppendDescriptionOf(matcher);
                    first = false;
                }
            }
        }
예제 #5
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;
            }
        }
예제 #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);
            }
        }
 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));
 }
예제 #9
0
        protected override bool MatchesSafely(IEnumerable <T> actual, IDescription description)
        {
            var enumerable = actual.ToList();

            if (isEmpty(enumerable))
            {
                description.AppendText("was empty");
                return(false);
            }

            if (doesOneMatch(enumerable))
            {
                return(true);
            }

            description.AppendText("mismatches were: [");

            bool isPastFirst = false;

            foreach (T item in enumerable)
            {
                if (isPastFirst)
                {
                    description.AppendText(", ");
                }
                _matcher.DescribeMismatch(item, description);

                isPastFirst = true;
            }

            description.AppendText("]");
            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);
 }
예제 #11
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");
 }
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public override void DescribeOn(IDescription description)
 {
     description.AppendText("[");
     WriteListOfMatchers(MatcherCount() - 1, description);
     description.AppendText("] = (");
     LastMatcher().DescribeOn(description);
     description.AppendText(")");
 }
예제 #13
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public override void DescribeOn(IDescription description)
 {
     description.AppendText("`");
     Left.DescribeOn(description);
     description.AppendText("' and `");
     Right.DescribeOn(description);
     description.AppendText("'");
 }
예제 #14
0
 public override void Describe(IDescription description)
 {
     description.AppendText("a string containing ");
     if (_comparison == StringComparison.CurrentCulture)
     {
         description.AppendText("with current culture ");
     }
     description.AppendValueList("", ", ", "", _substrings);
     description.AppendText(" in order");
 }
 public bool Matches(T item)
 {
     if (_matchers.Count >= _nextMatchIndex)
     {
         return(IsMatched(item));
     }
     _description.AppendText("not matched: ");
     _description.AppendValue(item);
     return(false);
 }
예제 #16
0
 public bool Matches(TM item)
 {
     if (_matchers.Count != 0)
     {
         return(IsMatched(item));
     }
     _description.AppendText("no match for: ");
     _description.AppendValue(item);
     return(false);
 }
예제 #17
0
        public override void Describe(IDescription description)
        {
            description.AppendText("a string ")
            .AppendText(_relationship)
            .AppendText(" ")
            .AppendValue(_substring);

            if (_ignoringCase)
            {
                description.AppendText(" ignoring case");
            }
        }
예제 #18
0
 public void DescribeOn(IDescription description)
 {
     description.AppendText(name);
     if (string.IsNullOrEmpty(currentState))
     {
         description.AppendText(" has no current state");
     }
     else
     {
         description.AppendText(" is ")
                    .AppendText(currentState);
     }
 }
예제 #19
0
        public override void DescribeMismatch(object actual, IDescription mismatch)
        {
            var converted = ConvertToString(actual);

            mismatch.AppendText("ToString()").AppendText(" ");
            _subMatcher.DescribeMismatch(converted, mismatch);
        }
        protected override bool MatchesSafely(IEnumerable <T> items, IDescription mismatchDescription)
        {
            List <IMatcher <T> > matchers = new List <IMatcher <T> >(_matchers);

            object lastMatchedItem = null;
            int    nextMatchIx     = 0;

            foreach (var item in items)
            {
                if (nextMatchIx < matchers.Count)
                {
                    var matcher = matchers.ElementAt(nextMatchIx);
                    if (matcher.Matches(item))
                    {
                        lastMatchedItem = item;
                        nextMatchIx++;
                    }
                }
            }

            if (nextMatchIx >= matchers.Count)
            {
                return(true);
            }

            mismatchDescription.AppendDescribable(matchers.ElementAt(nextMatchIx))
            .AppendText(" was not found");
            if (lastMatchedItem != null)
            {
                mismatchDescription.AppendText(" after ")
                .AppendValue(lastMatchedItem);
            }
            return(false);
        }
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public void DescribeOn(IDescription description)
 {
     description.AppendText("set arg ")
                .AppendText(index.ToString())
                .AppendText("=")
                .AppendValue(value);
 }
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public override void DescribeOn(IDescription description)
 {
     description.AppendText("containing ")
                .AppendText("\"")
                .AppendText(substring)
                .AppendText("\"");
 }
예제 #23
0
 public override void DescribeTo(IDescription description)
 {
     description
     .AppendText("origin String should contains ")
     .AppendValue(_substring)
     .AppendText($" {_expectedCount} times");
 }
예제 #24
0
 public override void Describe(IDescription description)
 {
     description.AppendText("a dictionary containing [")
     .AppendDescribable(_keyMatcher)
     .AppendText("->")
     .AppendDescribable(_valueMatcher)
     .AppendText("]");
 }
 protected override bool MatchesSafely(string item, IDescription mismatchDescription)
 {
     if (value.Equals(item))
     {
         return(true);
     }
     mismatchDescription.AppendText("mismatched: " + item);
     return(false);
 }
예제 #26
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("]");
        }
예제 #27
0
 public override void DescribeOn(IDescription description)
 {
     DescribeToCallCount++;
     if (ExpectedDescribeToWriter != null)
     {
         Assert.AreSame(ExpectedDescribeToWriter, description, "DescribeTo writer");
     }
     description.AppendText(DescribeToOutput);
 }
 protected override bool MatchesSafely(string item, IDescription mismatchDescription)
 {
     if (!_regex.IsMatch(item))
     {
         mismatchDescription.AppendText("the string was ")
         .AppendValue(item);
         return(false);
     }
     return(true);
 }
예제 #29
0
 /// <summary>
 /// Method made final to prevent accidental override.
 /// Override DescribeMismatchSafely instead.
 /// </summary>
 public override void DescribeMismatch(object actual, IDescription description)
 {
     if (actual == null)
     {
         description.AppendText("was null ");
     }
     else if (!(actual is T))
     {
         description.AppendText("was ")
         .AppendText(actual.GetType().Name)
         .AppendText(" (")
         .AppendValue(actual)
         .AppendText(")");
     }
     else
     {
         MatchesSafely((T)actual, description);
     }
 }
예제 #30
0
        private bool Matches(T collection, IDescription mismatchDescription)
        {
            if (collection.Count == _length)
            {
                return(true);
            }

            mismatchDescription.AppendText("collection had length {0}", collection.Count);
            return(false);
        }
예제 #31
0
 public void DescribeOn(IDescription description)
 {
     if (Equals(AllowAny)) description.AppendText("allowed");
     else if (maximum == 1 && required == 1) DescribeExpected(description, "once");
     else if (maximum == int.MaxValue && required == 1) DescribeExpected(description, "atleast once", required);
     else if (maximum == int.MaxValue && required > 1) DescribeExpected(description, "atleast {0} times", required);
     else if (maximum == required && required > 1) DescribeExpected(description, "exactly {0} times", required);
     else if (0 == required && maximum > 0) DescribeExpected(description,"at most {0} times", maximum);
     else if (Equals( NeverCardinality)) DescribeExpected(description,"never");
 }
예제 #32
0
            protected override bool MatchesSafely(string collection, IDescription mismatchDescription)
            {
                if (_match(collection))
                {
                    return(true);
                }

                mismatchDescription.AppendText("TestNonNullDiagnosingMatcher.MatchesSafely");
                return(false);
            }
예제 #33
0
        public void DescribeTo(IDescription description)
        {
            description.AppendText(_describePrefix)
            .AppendText(" ")
            .AppendText(typeof(T).Name);

            if (typeof(T) != _valueType)
            {
                description
                .AppendText(" {")
                .AppendText(_valueType.Name)
                .AppendText("}");
            }

            if (_matchers.Count > 0)
            {
                description.AppendText(" where:");
            }

            DescribeMatchers(description, _matchers, (d, m) => d.AppendDescriptionOf(m));
        }
예제 #34
0
        protected override bool MatchesSafely(IEnumerable <T> actual, IDescription description)
        {
            T invalid = actual.FirstOrDefault(value => !_matcher.Matches(value));

            if (invalid != null)
            {
                description.AppendText("an item ");
                _matcher.DescribeMismatch(invalid, description);
                return(false);
            }
            return(true);
        }
예제 #35
0
        private bool Matches(IEnumerable <T> collection, IDescription mismatchDescription)
        {
            var actualLength = collection.Count();

            if (actualLength == _length)
            {
                return(true);
            }

            mismatchDescription.AppendText("collection had length {0}", actualLength);
            return(false);
        }
예제 #36
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("]");
        }
예제 #37
0
        protected override bool MatchesSafely(TSafe actual, IDescription mismatch)
        {
            TSub featureValue = FeatureValueOf(actual);

            if (!_subMatcher.Matches(featureValue))
            {
                mismatch.AppendText(_featureName).AppendText(" ");
                _subMatcher.DescribeMismatch(featureValue, mismatch);
                return(false);
            }
            return(true);
        }
예제 #38
0
        protected override bool MatchesSafely(IEnumerable <T> collection, IDescription mismatchDescription)
        {
            var collectionArray = collection.ToArray();
            var matcherArray    = _matcherCollection.ToArray();

            for (var i = 0; i < Math.Max(collectionArray.Length, matcherArray.Length); i++)
            {
                if (i >= collectionArray.Length)
                {
                    mismatchDescription.AppendText("was too short (expected to be of length {0}, was {1})", matcherArray.Length, collectionArray.Length);
                    return(false);
                }

                if (i >= matcherArray.Length)
                {
                    mismatchDescription.AppendText("was too long (expected to be of length {0}, was {1})", matcherArray.Length, collectionArray.Length);
                    return(false);
                }

                if (!matcherArray[i].Matches(collectionArray[i]))
                {
                    mismatchDescription.AppendText("was not matched at position {0}:", i);

                    using (mismatchDescription.IndentBy(4))
                    {
                        mismatchDescription.AppendNewLine()
                        .AppendText("expected: ")
                        .AppendDescriptionOf(matcherArray[i])
                        .AppendNewLine()
                        .AppendText("but: ");

                        matcherArray[i].DescribeMismatch(collectionArray[i], mismatchDescription);
                    }

                    return(false);
                }
            }

            return(true);
        }
예제 #39
0
        protected override bool MatchesSafely(T collection, IDescription mismatchDescription)
        {
            var featureValue = FeatureValueOf(collection);

            if (subMatcher.Matches(featureValue) == false)
            {
                mismatchDescription.AppendText(featureName).AppendText(" ");
                subMatcher.DescribeMismatch(featureValue, mismatchDescription);
                return(false);
            }

            return(true);
        }
예제 #40
0
        /// <summary>
        /// Describes this object.
        /// </summary>
        /// <param name="description"></param>
        public override void DescribeOn(IDescription description)
        {
            description.AppendText("? ");
            if (minComparisonResult == -1)
            {
                description.AppendText("<");
            }

            if (maxComparisonResult == 1)
            {
                description.AppendText(">");
            }

            if (minComparisonResult == 0 || maxComparisonResult == 0)
            {
                description.AppendText("=");
            }

            description.AppendText(" ")
                       .AppendValue(value);
        }
예제 #41
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public override void DescribeOn(IDescription description)
 {
     description.AppendText("an object with a string representation that is ");
     matcher.DescribeOn(description);
 }
예제 #42
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public void DescribeOn(IDescription description)
 {
     description.AppendText("a clone of ");
     description.AppendValue(prototype);
 }
예제 #43
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public override void DescribeOn(IDescription description)
 {
     description.AppendText(methodName);
 }
 public void DescribeOn(IDescription description)
 {
     description.AppendText("when ");
     predicate.DescribeOn(description);
 }
예제 #45
0
 public void DescribeOn(IDescription description)
 {
     description.AppendText(stateMachine.Name);
     description.AppendText(" is ");
     description.AppendText(state);
 }
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public override void DescribeOn(IDescription description)
 {
     description.AppendText("<");
     WriteListOfMatchers(MatcherCount(), description);
     description.AppendText(">");
 }
        private void DescribeTo(IDescription writer)
        {
            DescribeMethod(writer);
            argumentsMatcher.DescribeOn(writer);
            foreach (Matcher extraMatcher in extraMatchers)
            {
                writer.AppendText(", ");
                extraMatcher.DescribeOn(writer);
            }

            if (actions.Count > 0)
            {
                writer.AppendText(", will ");
                ((IAction) actions[0]).DescribeOn(writer);
                for (int i = 1; i < actions.Count; i++)
                {
                    writer.AppendText(", ");
                    ((IAction) actions[i]).DescribeOn(writer);
                }
            }
            DescribeOrderingConstraintsOn(writer);
            sideEffects.ForEach(sideEffect => sideEffect.DescribeOn(writer));

            if (!string.IsNullOrEmpty(expectationComment))
            {
                writer.AppendText(" Comment: ")
                      .AppendText(expectationComment);
            }
        }
 private void DescribeOrderingConstraintsOn(IDescription writer)
 {
     if (!orderingConstraints.Any()) return;
     writer.AppendText(" ");
     orderingConstraints.ForEach(constraint => constraint.DescribeOn(writer));
 }
 private void DescribeMethod(IDescription description)
 {
     cardinality.DescribeOn(description);
     DescribeInvocationCount(description, callCount);
     description.AppendText(": ")
           .AppendText(receiver.MockName)
           .AppendText(methodSeparator);
     methodMatcher.DescribeOn(description);
     genericMethodTypeMatcher.DescribeOn(description);
 }
 private void DescribeInvocationCount(IDescription description, int count)
 {
     if(cardinality.Equals(Cardinality.Never())) return;
     description.AppendText(", ");
     if (count == 0 )
     {
         description.AppendText("never invoked");
     }
     else
     {
         description.AppendText("already invoked ");
         description.AppendText(count.ToString());
         description.AppendText(" time");
         if (count != 1)
         {
             description.AppendText("s");
         }
     }
 }
 private static void Indent(IDescription writer, int n)
 {
     for (var i = 0; i < n; i++)
     {
         writer.AppendText("  ");
     }
 }
 public void DescribeOn(IDescription description)
 {
     description.AppendText("Test");
 }
예제 #53
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public override void DescribeOn(IDescription description)
 {
     description.AppendText("not ");
     negated.DescribeOn(description);
 }
예제 #54
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public override void DescribeOn(IDescription description)
 {
     description.AppendText(string.Format("property '{0}' ", propertyName));
     valueMatcher.DescribeOn(description);
 }
        /// <summary>
        /// Writes the list of matchers to a <see cref="TextWriter"/>.
        /// </summary>
        /// <param name="listLength">Length of the list.</param>
        /// <param name="writer">The writer.</param>
        protected void WriteListOfMatchers(int listLength, IDescription writer)
        {
            for (int i = 0; i < listLength; i++)
            {
                if (i > 0)
                {
                    writer.AppendText(", ");
                }

                typeMatchers[i].DescribeOn(writer);
            }
        }
예제 #56
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public void DescribeOn(IDescription description)
 {
     description.AppendText("throw ");
     description.AppendValue(exception);
 }
예제 #57
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public override void DescribeOn(IDescription description)
 {
     description.AppendText("equal to ")
                .AppendValue(expected);
 }
예제 #58
0
 public void DescribeOn(IDescription description)
 {
     description.AppendText("\nthen ");
     state.DescribeOn(description);
     description.AppendText(";");
 }
 public override void DescribeOn(IDescription description1)
 {
     description1.AppendText(description);
 }
예제 #60
0
 /// <summary>
 /// Describes this object.
 /// </summary>
 /// <param name="description"></param>
 public override void DescribeOn(IDescription description)
 {
     description.AppendText("out");
 }