public void ComplexComposition_PredicateUsage_FoundMatchingElements() { var data = new List <ComplexType>(new ComplexContainer()); Assert.That(data.Find(FooLengthOf2).Bar, Is.EqualTo(2)); Assert.That(data.FindIndex(!new BarEven()), Is.EqualTo(2)); Specification <ComplexType> enabled = new ComplexTypeEnabled(), barEven = new BarEven(); Predicate <ComplexType> enabledOrDisabledAndBarEven = c => enabled.IsSatisfiedBy(c) || (!enabled.IsSatisfiedBy(c) && barEven.IsSatisfiedBy(c)); Assert.That(data.FindAll(enabledOrDisabledAndBarEven), Has.Count.EqualTo(6)); }
public void ComplexComposition_LinqUsage_FoundMatchingElements() { IEnumerable <ComplexType> data = new ComplexContainer(); var q1 = from c in data where FooLengthOf2.IsSatisfiedBy(c) select c.Bar; Assert.That(q1.First(), Is.EqualTo(2)); var q2 = data.Where(!new BarEven()).Select(c => c.Foo); Assert.That(q2.First(), Is.EqualTo("12")); Specification <ComplexType> enabled = new ComplexTypeEnabled(), barEven = new BarEven(); Func <ComplexType, bool> enabledOrDisabledAndBarEven = c => enabled.IsSatisfiedBy(c) || (!enabled.IsSatisfiedBy(c) && barEven.IsSatisfiedBy(c)); var q3 = from c in data where enabledOrDisabledAndBarEven(c) select c; Assert.That(q3, Must.Have.Count(Is.EqualTo(6))); }