コード例 #1
0
        public void SelectsExistentialQuantification()
        {
            var spec = new IntegerGreaterThanZero().ForAny();

            Assert.IsTrue(spec.IsSatisfiedBy(new[] { -1, -2, -3, -4, 0, 1, 2 }));
            Assert.IsFalse(spec.IsSatisfiedBy(new[] { -1, -2, -3, -4, 0 }));
        }
コード例 #2
0
        public void ImplicitConversionFromSpecification()
        {
            var spec = new IntegerGreaterThanZero();
            Expression<Func<int, bool>> expression = spec;

            Assert.That(expression, Is.SameAs(spec.Criteria));
        }
コード例 #3
0
        public void SelectsUniversalQuantification()
        {
            var spec = new IntegerGreaterThanZero().ForAll();

            Assert.IsTrue(spec.IsSatisfiedBy(new[] { 1, 1, 2, 3, 4, 5, 6 }));
            Assert.IsFalse(spec.IsSatisfiedBy(new[] { 3, 32, 589, 0, 11 }));
        }
コード例 #4
0
        public void IsSatisfiedBy_Uses_Criteria()
        {
            var spec = new IntegerGreaterThanZero();

            Assert.That(spec.IsSatisfiedBy(1), Is.True);
            Assert.That(spec.IsSatisfiedBy(0), Is.False);
            Assert.That(spec.IsSatisfiedBy(-1), Is.False);
        }
コード例 #5
0
        public void AndGeneric_ReturnsConjunction()
        {
            var spec = new IntegerGreaterThanZero();
            var conjoinedSpec = spec.And<IntegerLessThanZero>();

            Assert.That(conjoinedSpec, Is.TypeOf<Conjunction<int>>());
            Assert.That(conjoinedSpec, Has.Property("Left").EqualTo(spec));
            Assert.That(conjoinedSpec, Has.Property("Right").TypeOf<IntegerLessThanZero>());
        }
コード例 #6
0
        public void SelectsInverse()
        {
            var spec = new IntegerGreaterThanZero();
            var negatedSpec = new Negation<int>(spec);

            Assert.That(negatedSpec.IsSatisfiedBy(1), Is.False);
            Assert.That(negatedSpec.IsSatisfiedBy(0), Is.True);
            Assert.That(negatedSpec.IsSatisfiedBy(-1), Is.True);
        }
コード例 #7
0
        public void SelectsDisjunction()
        {
            var spec1 = new IntegerGreaterThanZero();
            var spec2 = new IntegerEqualToZero();
            var disjoinedSpec = new Disjunction<int>(spec1, spec2);

            Assert.That(disjoinedSpec.IsSatisfiedBy(1), Is.True);
            Assert.That(disjoinedSpec.IsSatisfiedBy(0), Is.True);
            Assert.That(disjoinedSpec.IsSatisfiedBy(-1), Is.False);
        }
コード例 #8
0
        public void SelectsConjunction()
        {
            var spec1 = new IntegerGreaterThanZero();
            var spec2 = new IntegerPredicate(i => i > -1);
            var conjoinedSpec = new Conjunction<int>(spec1, spec2);

            Assert.That(conjoinedSpec.IsSatisfiedBy(1), Is.True);
            Assert.That(conjoinedSpec.IsSatisfiedBy(0), Is.False);
            Assert.That(conjoinedSpec.IsSatisfiedBy(-1), Is.False);
        }
コード例 #9
0
        public void SelectsConversion()
        {
            var spec = new IntegerGreaterThanZero();
            var converter = (Expression<Func<double, int>>)(d => Math.Sign(d));
            var convertedSpec = new Conversion<double, int>(spec, converter);

            Assert.That(convertedSpec.IsSatisfiedBy(1), Is.True);
            Assert.That(convertedSpec.IsSatisfiedBy(0), Is.False);
            Assert.That(convertedSpec.IsSatisfiedBy(-1), Is.False);
        }
コード例 #10
0
        public void Matching_IQueryable_Uses_Specification()
        {
            var spec = new IntegerGreaterThanZero();
            var candidates = (new[] { -1, 0, 1, 2, 3 }).AsQueryable();

            var queryable = candidates.Matching(spec);
            foreach(var i in queryable)
            {
                Assert.That(spec.IsSatisfiedBy(i));
            }
        }
コード例 #11
0
        public void AndNot_ReturnsConjunction_WithNegationRight()
        {
            var spec1 = new IntegerGreaterThanZero();
            var spec2 = new IntegerLessThanZero();
            var conjoinedSpec = spec1.AndNot(spec2);

            Assert.That(conjoinedSpec, Is.TypeOf<Conjunction<int>>());
            Assert.That(conjoinedSpec, Has.Property("Left").EqualTo(spec1));
            Assert.That(conjoinedSpec, Has.Property("Right").TypeOf<Negation<int>>());
            Assert.That(conjoinedSpec, Has.Property("Right").With.Property("Inner").EqualTo(spec2));
        }
コード例 #12
0
        public void Filter_IQueryable_Uses_Criteria()
        {
            var spec = new IntegerGreaterThanZero();
            var candidates = (new[] { -1, 0, 1, 2, 3 }).AsQueryable();

            var queryable = spec.Filter(candidates);
            foreach(var i in queryable)
            {
                Assert.That(spec.IsSatisfiedBy(i));
            }
        }
コード例 #13
0
        public void AndConvert_ReturnsConjunctionWithConversion()
        {
            var spec1 = new IntegerGreaterThanZero();
            var spec2 = Specify.EqualTo(DateTime.Now);
            var converter = (Expression<Func<DateTime, int>>)(dt => dt.Minute);
            var conjoinedSpec = spec2.And(converter, spec1);

            Assert.That(conjoinedSpec, Is.TypeOf<Conjunction<DateTime>>());
            Assert.That(conjoinedSpec, Has.Property("Left").EqualTo(spec2));
            Assert.That(conjoinedSpec, Has.Property("Right").InstanceOf<Conversion<DateTime, int>>());
            Assert.That(conjoinedSpec, Has.Property("Right").With.Property("Inner").EqualTo(spec1));
            Assert.That(conjoinedSpec, Has.Property("Right").With.Property("Converter").EqualTo(converter));
        }
コード例 #14
0
        public void ForOne_ReturnsUniqueQuantification()
        {
            var spec = new IntegerGreaterThanZero();
            var anySpec = spec.ForOne();

            Assert.That(anySpec, Is.TypeOf<UniqueQuantification<int>>());
            Assert.That(anySpec, Has.Property("Inner").EqualTo(spec));
        }
コード例 #15
0
        public void AndOperator_ReturnsConjunction()
        {
            var spec1 = new IntegerGreaterThanZero();
            var spec2 = new IntegerLessThanZero();
            var conjoinedSpec = spec1 & spec2;

            Assert.That(conjoinedSpec, Is.TypeOf<Conjunction<int>>());
            Assert.That(conjoinedSpec, Has.Property("Left").EqualTo(spec1));
            Assert.That(conjoinedSpec, Has.Property("Right").EqualTo(spec2));
        }
コード例 #16
0
        public void Xor_ReturnsExclusiveDisjunction()
        {
            var spec1 = new IntegerGreaterThanZero();
            var spec2 = new IntegerLessThanZero();
            var conjoinedSpec = spec1.Xor(spec2);

            Assert.That(conjoinedSpec, Is.TypeOf<ExclusiveDisjunction<int>>());
            Assert.That(conjoinedSpec, Has.Property("Left").EqualTo(spec1));
            Assert.That(conjoinedSpec, Has.Property("Right").EqualTo(spec2));
        }
コード例 #17
0
        public void XorNotGeneric_ReturnsExclusiveDisjunction_WithNegationRight()
        {
            var spec = new IntegerGreaterThanZero();
            var conjoinedSpec = spec.XorNot<IntegerLessThanZero>();

            Assert.That(conjoinedSpec, Is.TypeOf<ExclusiveDisjunction<int>>());
            Assert.That(conjoinedSpec, Has.Property("Left").EqualTo(spec));
            Assert.That(conjoinedSpec, Has.Property("Right").TypeOf<Negation<int>>());
            Assert.That(conjoinedSpec, Has.Property("Right").With.Property("Inner").TypeOf<IntegerLessThanZero>());
        }
コード例 #18
0
        public void Not_ReturnsNegation()
        {
            var spec = new IntegerGreaterThanZero();
            var negatedSpec = spec.IsFalse();

            Assert.That(negatedSpec, Is.TypeOf<Negation<int>>());
            Assert.That(negatedSpec, Has.Property("Inner").EqualTo(spec));
        }
コード例 #19
0
        public void Convert_ReturnsConversion()
        {
            var spec = new IntegerGreaterThanZero();
            var converter = (Expression<Func<double, int>>)(d => (int)d);
            var convertedSpec = spec.From(converter);

            Assert.That(convertedSpec, Is.TypeOf<Conversion<double, int>>());
            Assert.That(convertedSpec, Has.Property("Inner").EqualTo(spec));
            Assert.That(convertedSpec, Has.Property("Converter").EqualTo(converter));
        }
コード例 #20
0
        public void ForAny_ReturnsExistentialQuantification()
        {
            var spec = new IntegerGreaterThanZero();
            var anySpec = spec.ForAny();

            Assert.That(anySpec, Is.TypeOf<ExistentialQuantification<int>>());
            Assert.That(anySpec, Has.Property("Inner").EqualTo(spec));
        }