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; } } }
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); }
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); }
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; } } }
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) { 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)); }
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); }
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(")"); }
/// <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("'"); }
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); }
public bool Matches(TM item) { if (_matchers.Count != 0) { return(IsMatched(item)); } _description.AppendText("no match for: "); _description.AppendValue(item); return(false); }
public override void Describe(IDescription description) { description.AppendText("a string ") .AppendText(_relationship) .AppendText(" ") .AppendValue(_substring); if (_ignoringCase) { description.AppendText(" ignoring case"); } }
public void DescribeOn(IDescription description) { description.AppendText(name); if (string.IsNullOrEmpty(currentState)) { description.AppendText(" has no current state"); } else { description.AppendText(" is ") .AppendText(currentState); } }
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("\""); }
public override void DescribeTo(IDescription description) { description .AppendText("origin String should contains ") .AppendValue(_substring) .AppendText($" {_expectedCount} times"); }
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); }
/// <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("]"); }
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); }
/// <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); } }
private bool Matches(T collection, IDescription mismatchDescription) { if (collection.Count == _length) { return(true); } mismatchDescription.AppendText("collection had length {0}", collection.Count); return(false); }
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"); }
protected override bool MatchesSafely(string collection, IDescription mismatchDescription) { if (_match(collection)) { return(true); } mismatchDescription.AppendText("TestNonNullDiagnosingMatcher.MatchesSafely"); return(false); }
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)); }
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); }
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); }
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("]"); }
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); }
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); }
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); }
/// <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); }
/// <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); }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public void DescribeOn(IDescription description) { description.AppendText("a clone of "); description.AppendValue(prototype); }
/// <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); }
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"); }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public override void DescribeOn(IDescription description) { description.AppendText("not "); negated.DescribeOn(description); }
/// <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); } }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public void DescribeOn(IDescription description) { description.AppendText("throw "); description.AppendValue(exception); }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public override void DescribeOn(IDescription description) { description.AppendText("equal to ") .AppendValue(expected); }
public void DescribeOn(IDescription description) { description.AppendText("\nthen "); state.DescribeOn(description); description.AppendText(";"); }
public override void DescribeOn(IDescription description1) { description1.AppendText(description); }
/// <summary> /// Describes this object. /// </summary> /// <param name="description"></param> public override void DescribeOn(IDescription description) { description.AppendText("out"); }