public static SearcherItemCollectionEquivalentConstraint SearcherItemCollectionEquivalent( this ConstraintExpression expression, IEnumerable <SearcherItem> expected) { var constraint = new SearcherItemCollectionEquivalentConstraint(expected); expression.Append(constraint); return(constraint); }
protected override bool Matches(IEnumerable actual) { if (m_Expected == null) { Description = "Expected is not a valid collection"; return(false); } if (!(actual is IEnumerable <SearcherItem> actualCollection)) { Description = "Actual is not a valid collection"; return(false); } var actualList = actualCollection.ToList(); if (actualList.Count != m_Expected.Count) { Description = $"Collections lengths are not equal. \nExpected length: {m_Expected.Count}, " + $"\nBut was: {actualList.Count}"; return(false); } for (var i = 0; i < m_Expected.Count; ++i) { var res1 = m_Expected[i].ToString(); var res2 = actualList[i].ToString(); if (!string.Equals(res1, res2)) { Description = $"Object at index {i} are not the same.\nExpected: {res1},\nBut was: {res2}"; return(false); } var constraint = new SearcherItemCollectionEquivalentConstraint(m_Expected[i].Children); if (constraint.Matches(actualList[i].Children)) { continue; } Description = constraint.Description; return(false); } return(true); }