Exemple #1
0
        public void IsSatisfiedByExample()
        {
            var goldCustomer = new Customer {
                Name = "Customer1", Type = CustomerType.Gold
            };
            var silverCustomer = new Customer {
                Name = "Customer2", Type = CustomerType.Silver
            };
            var bronzeCustomer = new Customer {
                Name = "Customer3", Type = CustomerType.Bronze
            };

            var goldSpecification             = new PredicateSpecification <Customer>(x => x.Type == CustomerType.Gold);
            var specificCustomerSpecification = new PredicateSpecification <Customer>(x => x.Name == "Customer3");

            // Gold customer
            Assert.IsTrue(goldSpecification.IsSatisfiedBy(goldCustomer));

            // Silver customer
            Assert.IsFalse(goldSpecification.IsSatisfiedBy(silverCustomer));

            // Customer 3
            Assert.IsTrue(specificCustomerSpecification.IsSatisfiedBy(bronzeCustomer));

            // Customer 2
            Assert.IsFalse(specificCustomerSpecification.IsSatisfiedBy(silverCustomer));
        }
Exemple #2
0
        public void Specification_Should_Save_And_Use_Predicate_Supplied_Correctly()
        {
            Predicate<int> predicate = x => x == 5;
            var specification = new PredicateSpecification<int>(predicate);
            Assert.AreEqual(specification.Predicate, predicate);

            Assert.IsTrue(specification.IsSatisfiedBy(5));

            Assert.IsFalse(specification.IsSatisfiedBy(3));
            Assert.IsFalse(specification.IsSatisfiedBy(6));
        }
Exemple #3
0
        public void Specification_Should_Save_And_Use_Predicate_Supplied_Correctly()
        {
            Predicate <int> predicate     = x => x == 5;
            var             specification = new PredicateSpecification <int>(predicate);

            Assert.AreEqual(specification.Predicate, predicate);

            Assert.IsTrue(specification.IsSatisfiedBy(5));

            Assert.IsFalse(specification.IsSatisfiedBy(3));
            Assert.IsFalse(specification.IsSatisfiedBy(6));
        }
        public void IsSatisfiedByExample()
        {
            var goldCustomer = new Customer { Name = "Customer1", Type = CustomerType.Gold };
            var silverCustomer = new Customer { Name = "Customer2", Type = CustomerType.Silver };

            var notGoldSpecification = new PredicateSpecification<Customer>(x => x.Type == CustomerType.Gold).Not();

            // Gold customer
            Assert.IsFalse(notGoldSpecification.IsSatisfiedBy(goldCustomer));

            // Silver customer
            Assert.IsTrue(notGoldSpecification.IsSatisfiedBy(silverCustomer));
        }
Exemple #5
0
        public void IsSatisfiedByExample()
        {
            var goldCustomer = new Customer {
                Name = "Customer1", Type = CustomerType.Gold
            };
            var silverCustomer = new Customer {
                Name = "Customer2", Type = CustomerType.Silver
            };

            var notGoldSpecification = new PredicateSpecification <Customer>(x => x.Type == CustomerType.Gold).Not();

            // Gold customer
            Assert.IsFalse(notGoldSpecification.IsSatisfiedBy(goldCustomer));

            // Silver customer
            Assert.IsTrue(notGoldSpecification.IsSatisfiedBy(silverCustomer));
        }
        public void IsSatisfiedByExample()
        {
            var goldCustomer = new Customer { Name = "Customer1", Type = CustomerType.Gold };
            var silverCustomer = new Customer { Name = "Customer2", Type = CustomerType.Silver };
            var bronzeCustomer = new Customer { Name = "Customer3", Type = CustomerType.Bronze };

            var goldSpecification = new PredicateSpecification<Customer>(x => x.Type == CustomerType.Gold);
            var specificCustomerSpecification = new PredicateSpecification<Customer>(x => x.Name == "Customer3");

            // Gold customer
            Assert.IsTrue(goldSpecification.IsSatisfiedBy(goldCustomer));

            // Silver customer
            Assert.IsFalse(goldSpecification.IsSatisfiedBy(silverCustomer));

            // Customer 3
            Assert.IsTrue(specificCustomerSpecification.IsSatisfiedBy(bronzeCustomer));

            // Customer 2
            Assert.IsFalse(specificCustomerSpecification.IsSatisfiedBy(silverCustomer));
        }
Exemple #7
0
        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)));
        }
 public void Can_satisfy_specifications()
 {
     ISpecification<bool> spec = new PredicateSpecification<bool>(v => v);
     Assert.AreEqual(true, spec.IsSatisfiedBy(true));
 }
 public void PredicateSpecification_PredicateTrue_True()
 {
     var specification = new PredicateSpecification<string>(s => true);
     Assert.AreEqual(true, specification.IsSatisfiedBy("test"));
 }
 public void PredicateSpecification_PredicateFalse_False()
 {
     var specification = new PredicateSpecification<string>(s => false);
     Assert.AreEqual(false, specification.IsSatisfiedBy("test"));
 }