private static string mismatchDescription <T>(IMatcher <T> matcher, object arg) { Description description = new Description(); matcher.DescribeMismatch(arg, description); return(description.ToString().Trim()); }
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); }
public override void DescribeMismatch(object actual, IDescription mismatch) { var converted = ConvertToString(actual); mismatch.AppendText("ToString()").AppendText(" "); _subMatcher.DescribeMismatch(converted, mismatch); }
public static void ShouldHaveMismatchDescriptionForValue <TMatched>(this IMatcher <TMatched> matcher, TMatched value, string expected) { var description = new StringDescription(); matcher.DescribeMismatch(value, description); var actual = description.ToString(); Xunit.Assert.Equal(expected, actual); }
public static void ShouldHaveMismatchDescriptionForValue <TMatched>(this IMatcher <TMatched> matcher, TMatched value, IMatcher <string> expectedMatcher) { var description = new StringDescription(); matcher.DescribeMismatch(value, description); var actual = description.ToString(); Assert.That(actual, expectedMatcher); }
protected override bool MatchesSafely(T item, IDescription mismatchDescription) { if (!_matcher.Matches(item)) { _matcher.DescribeMismatch(item, mismatchDescription); return(false); } return(true); }
private static void WriteActual <T>(T actual, IMatcher <T> matcher, TextWriter writer) { writer.Write(" But "); var mismatchDescription = new StringDescription(); matcher.DescribeMismatch(actual, mismatchDescription); writer.Write(mismatchDescription.ToString()); writer.WriteLine(); }
public void MismatchDescriptionMustBeCorrect() { var description = new StringDescription(); _matcher.DescribeMismatch(_matched, description); var expected = ExpectMismatchDescription(); var actual = description.ToString(); Xunit.Assert.Equal(expected, actual); }
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); }
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(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); }
public static void That <T>(String reason, Func <T> func, IMatcher <T> matcher) { T actual = WaitAndGetActualValue(func, matcher, _timeout, _delay); if (!matcher.Matches(actual)) { StringDescription stringDescription1 = new StringDescription(); matcher.DescribeTo(stringDescription1); StringDescription stringDescription2 = new StringDescription(); matcher.DescribeMismatch(actual, stringDescription2); throw new MatchException(stringDescription1.ToString(), stringDescription2.ToString(), reason); } }
public static void That <T>(string message, T actual, IMatcher <T> matcher) { if (!matcher.Matches(actual)) { Description description = new Description(); description.AppendText(message) .AppendText("\nExpected: ") .AppendDescribable(matcher) .AppendText("\n But: "); matcher.DescribeMismatch(actual, description); throw new ArgumentException(description.ToString()); } }
protected override bool MatchesSafely(IEnumerable <T> collection, IDescription mismatchDescription) { foreach (var item in collection) { if (matcher.Matches(item)) { continue; } mismatchDescription.AppendText("an item "); matcher.DescribeMismatch(item, mismatchDescription); return(false); } return(true); }
private static void That <T>(T actual, IMatcher <T> matcher, string reason) { if (matcher.Matches(actual)) { return; } var description = new StringDescription(); description.AppendText(reason) .AppendText("\nExpected: ") .AppendDescriptionOf(matcher) .AppendText("\n but: "); matcher.DescribeMismatch(actual, description); throw new AssertionError(description.ToString()); }
public static void That <T>(T actual, IMatcher <T> matcher) { if (matcher.Matches(actual)) { return; } var description = new StringDescription(); matcher.DescribeTo(description); var mismatchDescription = new StringDescription(); matcher.DescribeMismatch(actual, mismatchDescription); throw new MatchException(description.ToString(), mismatchDescription.ToString(), null); }
private bool Matches(TSource o, IDescription mismatchDescription) { if (!(o is TDest)) { mismatchDescription.AppendText("it was not of type {0}", typeof(TDest).Name); return(false); } var cast = (TDest)(object)o; if (!_innerMatcher.Matches(cast)) { _innerMatcher.DescribeMismatch(cast, mismatchDescription); return(false); } return(true); }
protected override bool MatchesSafely(IEnumerable <T> collection, IDescription mismatchDescription) { var isPastFirst = false; foreach (var item in collection) { if (elementMatcher.Matches(item)) { return(true); } if (isPastFirst) { mismatchDescription.AppendText(", "); } elementMatcher.DescribeMismatch(item, mismatchDescription); isPastFirst = true; } return(false); }
///<summary> /// Asserts that an item satisfies the condition specified by matcher. ///</summary> ///<param name="item">The item to test.</param> ///<param name="matcher">A <see cref="IMatcher{T}">matcher</see>.</param> ///<param name="messageFormat">The custom assertion message format, or null if none.</param> ///<param name="messageArgs">The custom assertion message arguments, or null if none.</param> ///<typeparam name="T">The static type accepted by the matcher.</typeparam> public static void That <T>(T item, IMatcher <T> matcher, string messageFormat, params object[] messageArgs) { AssertionHelper.Verify(() => { if (matcher.Matches(item)) { return(null); } var description = new StringDescription(); var mismatchDescription = new StringDescription(); matcher.DescribeTo(description); matcher.DescribeMismatch(item, mismatchDescription); return(new AssertionFailureBuilder("Expected " + description) .SetMessage(messageFormat, messageArgs) .AddLabeledValue("Expected", description.ToString()) .AddLabeledValue("But", mismatchDescription.ToString()) .ToAssertionFailure()); }); }
private bool Matches(TObject o, IDescription mismatchDescription) { try { var value = _propertyAccessor(o); if (!_propertyMatcher.Matches(value)) { mismatchDescription.AppendText("member {0} value ", _property); _propertyMatcher.DescribeMismatch(value, mismatchDescription); return(false); } return(true); } catch (Exception ex) { mismatchDescription.AppendText("and exception has been thrown while accessing property {0}:", _property) .AppendNewLine() .AppendText(ex.ToString()); return(false); } }
public override void DescribeMismatch(T item, IDescription mismatchDescription) { _toDecorate.DescribeMismatch(item, mismatchDescription); }
public override void DescribeMismatch(T item, IDescription mismatchDescription) { _decoratedMatcher.DescribeMismatch(item, mismatchDescription); }
public void DescribeMismatch(T item, IDescription mismatchDescription) { _createdMatcher.DescribeMismatch(item, mismatchDescription); }
public override void DescribeMismatch(object actual, IDescription description) { _matcher.DescribeMismatch(actual, description); }
private void DescribeMismatch(IMatcher <T> matcher, T item) { _description.AppendText("item " + _nextMatchIndex + ": "); matcher.DescribeMismatch(item, _description); }