public void ComplexComposition_LinqUsage_FoundMatchingElements() { IEnumerable <ComplexType> data = new ComplexContainer(); var fooLengthOf2 = new Foo_LengthOf2(); var q1 = from c in data where fooLengthOf2.IsSatisfiedBy(c) select c.Bar; Assert.That(q1.First(), Is.EqualTo(2)); Func <ComplexType, bool> notEven = c => new Bar_Even().Not().IsSatisfiedBy(c); var q2 = data.Where(notEven).Select(c => c.Foo); Assert.That(q2.First(), Is.EqualTo("12")); Specification <ComplexType> enabled = new ComplexType_Enabled(), barEven = new Bar_Even(); 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))); }
public void ComplexComposition_PredicateUsage_FoundMatchingElements() { var data = new List <ComplexType>(new ComplexContainer()); Assert.That(data.Find(new Foo_LengthOf2().IsSatisfiedBy).Bar, Is.EqualTo(2)); Assert.That(data.FindIndex(new Bar_Even().Not().IsSatisfiedBy), Is.EqualTo(2)); Specification <ComplexType> enabled = new ComplexType_Enabled(), barEven = new Bar_Even(); Predicate <ComplexType> enabledOrDisabledAndBarEven = c => enabled.IsSatisfiedBy(c) || (!enabled.IsSatisfiedBy(c) && barEven.IsSatisfiedBy(c)); Assert.That(data.FindAll(enabledOrDisabledAndBarEven), Has.Count.EqualTo(6)); }