public void SatisfyBySpecification() { var firstSpec = new SpecificationQueryStrategy <Customer>(x => x.Name.Equals("Random Name")); var secondSpec = new SpecificationQueryStrategy <Customer>(x => x.Id == 1); var options = new QueryOptions <Customer>() .WithFilter(firstSpec) .WithFilter(secondSpec); Assert.Equal(firstSpec.And(secondSpec).Predicate.ToString(), ((IQueryOptions <Customer>)options).SpecificationStrategy.Predicate.ToString()); }
public static ISpecificationQueryStrategy <T> OnCondition <T>(this SpecificationQueryStrategy <T> queryStrategy, bool condition) where T : class { Check.NotNull(queryStrategy, "queryStrategy"); if (condition) { return(queryStrategy); } var defaultQueryStrategy = new DefaultSpecificationQueryStrategy <T>(); return(defaultQueryStrategy); }
public void FindBySpecification() { var product = new Product { Price = 99 }; var spec = new SpecificationQueryStrategy <Product>(p => p.Price < 100); Assert.True(spec.IsSatisfiedBy(product)); product.Price = 100; Assert.False(spec.IsSatisfiedBy(product)); }
public void FindByNotCompositeSpecification() { var product = new Product { Price = 99, Name = "Windows XP Professional" }; var spec = new SpecificationQueryStrategy <Product>(p => p.Price < 100).Not(); Assert.False(spec.IsSatisfiedBy(product)); product.Price = 100; Assert.True(spec.IsSatisfiedBy(product)); }
public void Spec_ToString() { var spec = new SpecificationQueryStrategy <Product>(p => p.Price < 100).Or(p => p.Name.Equals("Windows XP Professional")); Assert.Equal("SpecificationQueryStrategy<Product>: [ Predicate = p => ((p.Price < 100) OrElse p.Name.Equals(\"Windows XP Professional\")) ]", spec.ToString()); }