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); }
public bool IsFinished() { if (_nextMatchIndex >= _matchers.Count) { return(true); } _description.AppendText("no item was "); _description.AppendDescribable(_matchers[_nextMatchIndex]); return(false); }
protected override bool Matches(object actual, IDescription description) { foreach (var describable in _matchers) { var matcher = (IMatcher <T>)describable; if (matcher.Matches(actual)) { continue; } description.AppendDescribable(matcher).AppendText(" "); matcher.DescribeMismatch(actual, description); return(false); } return(true); }
public override void Describe(IDescription description) { description.AppendDescribable(_matcher); }