示例#1
0
        public void EntityPredicate_Can_Be_Used_With_DerivedEntityQueryable()
        {
            using (var fruitContext = new FruitContext())
            {
                var badFruitSpecification = new BadFruitSpecification();

                var satisfiedApples = badFruitSpecification.SatisfiedBy(fruitContext.Apples);

                Assert.IsTrue(satisfiedApples.Any());
            }
        }
        public void False_Satisfies_None()
        {
            var falseSpecification = Specification <int> .False();

            using (var fruitContext = new FruitContext())
            {
                var integers          = GetIntegers(fruitContext);
                var satisfiedIntegers = falseSpecification.SatisfiedBy(integers);

                Assert.IsTrue(!satisfiedIntegers.Any());
            }
        }
        public void True_Satisfies_All()
        {
            var trueSpecification = Specification <int> .True();

            using (var fruitContext = new FruitContext())
            {
                var integers          = GetIntegers(fruitContext);
                var satisfiedIntegers = trueSpecification.SatisfiedBy(integers);

                Assert.IsTrue(satisfiedIntegers.Any());
                CollectionAssert.AreEquivalent(integers.ToList(), satisfiedIntegers.ToList());
            }
        }
        public void AndAlso_Satisfies_Both()
        {
            var greaterThanSpecification = new GreaterThanSpecification(-2);
            var lessThanSpecification    = new LessThanSpecification(2);
            var compositeSpecification   = greaterThanSpecification.AndAlso(lessThanSpecification);

            using (var fruitContext = new FruitContext())
            {
                var integers          = GetIntegers(fruitContext);
                var satisfiedIntegers = compositeSpecification.SatisfiedBy(integers);

                Assert.IsTrue(satisfiedIntegers.Any());
                Assert.IsTrue(satisfiedIntegers.All(i => i > -2 && i < 2));
            }
        }
        public void OrElse_Satisfies_Either()
        {
            var greaterThanSpecification = new GreaterThanSpecification(2);
            var lessThanSpecification    = new LessThanSpecification(-2);
            var compositeSpecification   = greaterThanSpecification.OrElse(lessThanSpecification);

            using (var fruitContext = new FruitContext())
            {
                var integers          = GetIntegers(fruitContext);
                var satisfiedIntegers = compositeSpecification.SatisfiedBy(integers);

                Assert.IsTrue(satisfiedIntegers.Any());
                Assert.IsTrue(satisfiedIntegers.All(i => i > 2 || i < -2));
            }
        }
示例#6
0
        public void EntitySpecification_Can_Be_Used_With_DerivedEntitySpecification()
        {
            using (var fruitContext = new FruitContext())
            {
                var badFruitSpecification  = new BadFruitSpecification();
                var appleNameSpecification = new AppleNameSpecification("R");

                var satisfiedApples = badFruitSpecification
                                      .AndAlso(appleNameSpecification)
                                      .SatisfiedBy(fruitContext.Apples);

                Assert.IsTrue(satisfiedApples.Any());
                Assert.IsTrue(satisfiedApples.All(a => a.Bad && a.Name.Contains("R")));
            }
        }
示例#7
0
        public void EntityPredicate_Can_Be_Used_With_IEnumerable()
        {
            using (var fruitContext = new FruitContext())
            {
                var badFruitSpecification  = new BadFruitSpecification();
                var appleNameSpecification = new AppleNameSpecification("R");

                var satisfiedApples = badFruitSpecification
                                      .AndAlso(appleNameSpecification)
                                      // ToList => Pass an IEnumerable that's not an IQueryable.
                                      .SatisfiedBy(fruitContext.Apples.ToList());

                var satisfiedApplesList = satisfiedApples.ToList();

                Assert.IsTrue(satisfiedApplesList.Any());
                Assert.IsTrue(satisfiedApplesList.All(a => a.Bad && a.Name.Contains("R")));
            }
        }
 private static IQueryable <int> GetIntegers(FruitContext fruitContext)
 {
     return(fruitContext.Fruits.Select(f => f.FruitId - 13));
 }