Exemple #1
0
        public IEnumerable <Person> FilterMales()
        {
            var onlyMales        = new OnlyMalesSpecification();
            var ageGreaterThan40 = new GreaterThanSpecification(40);

            return(this.personRepository.Find(onlyMales.Or(ageGreaterThan40)));
        }
Exemple #2
0
            public void InvokeNullableCandidate_ReturnFalse(int?candidate, int?greaterThan)
            {
                var sut = new GreaterThanSpecification <int?>(greaterThan);

                var result = sut.GetExpression().Compile().Invoke(candidate);

                Assert.False(result);
            }
            public void NullableCandidate_ReturnFalse(int?candidate, int?greaterThan)
            {
                var sut = new GreaterThanSpecification <int?>(greaterThan);

                var result = sut.IsNotSatisfiedBy(candidate);

                Assert.False(result);
            }
            public void GreaterThanCandidate_ReturnFalse <T>(T candidate, T greaterThan, IComparer <T> comparer)
            {
                candidate = candidate?.ToString() != "null" ? candidate : default;
                var sut = new GreaterThanSpecification <T>(greaterThan, comparer);

                var result = sut.IsNotSatisfiedBy(candidate);

                Assert.False(result);
            }
Exemple #5
0
            public void InvokeNotGreaterThanCandidate_ReturnFalse <T>(T candidate, T greaterThan, IComparer <T> comparer)
            {
                candidate = candidate?.ToString() != "null" ? candidate : default;
                var sut = new GreaterThanSpecification <T>(greaterThan, comparer);

                var result = sut.GetExpression().Compile().Invoke(candidate);

                Assert.False(result);
            }
Exemple #6
0
        public void InvokeGreaterThan_ReturnGreaterThanSpecification()
        {
            var comparer = new FakeIntComparer();
            var expected = new GreaterThanSpecification <int>(0, comparer);

            var sut = Specification.GreaterThan(0, comparer);

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
		public void Test_GreaterThan_Strict()
		{
			GreaterThanSpecification s = new GreaterThanSpecification();
			s.RefValueExpression = new ConstantExpression("1");
			s.Strict = true;

			// this should fail because in strict mode we don't do type coercion,
			// and IComparable throws an ArgumentException in this situation
			s.Test(0);
		}
Exemple #8
0
            public void NonGenericILinqSpecification_ReturnExpressionAsAbstractExpression()
            {
                var sut = new GreaterThanSpecification <string>(null);

                var expected      = sut.GetExpression().ToString();
                var sutExpression = ((ILinqSpecification)sut).GetExpression();
                var result        = sutExpression.ToString();

                Assert.Equal(expected, result);
            }
            public void CorrectNullableCandidate_ReturnExpectedResultObject(int?candidate, int?greaterThan,
                                                                            SpecificationResult expected)
            {
                var sut = new GreaterThanSpecification <int?>(greaterThan);

                var overall = sut.IsNotSatisfiedBy(candidate, out var result);

                Assert.True(overall);
                Assert.Equal(expected, result, new SpecificationResultComparer());
            }
        public void Test_GreaterThan_Strict()
        {
            GreaterThanSpecification s = new GreaterThanSpecification();

            s.RefValueExpression = new ConstantExpression("1");
            s.Strict             = true;

            // this should fail because in strict mode we don't do type coercion,
            // and IComparable throws an ArgumentException in this situation
            s.Test(0);
        }
        public void Test_GreaterThan_Options2()
        {
            ISpecification s = _factory.GetSpecification("greaterThan_options2");

            Assert.IsInstanceOfType(typeof(GreaterThanSpecification), s);

            GreaterThanSpecification s1 = (GreaterThanSpecification)s;

            Assert.AreEqual("XXX", s1.RefValueExpression.Text);
            Assert.AreEqual(true, s1.Inclusive);
        }
		public void Test_GreaterThan_Exclusive()
		{
			GreaterThanSpecification s = new GreaterThanSpecification();
			s.RefValueExpression = new ConstantExpression(1);
			Assert.IsFalse(s.Test(0).Success);
			Assert.IsFalse(s.Test(1).Success);
			Assert.IsTrue(s.Test(2).Success);

			// null is less than any other value
			Assert.IsFalse(s.Test(null).Success);
		}
		// This test is currently failing because coercion code hasn't been merged to trunk yet
		public void Test_GreaterThan_CoerceTypes()
		{
			GreaterThanSpecification s = new GreaterThanSpecification();
			s.RefValueExpression = new ConstantExpression("1");

			Assert.IsFalse(s.Test(0).Success);
			Assert.IsFalse(s.Test(1).Success);
			Assert.IsTrue(s.Test(2).Success);
			//Assert.IsTrue(s.Test(null).Success);
			//Assert.IsTrue(s.Test(1).Success);
		}
            public void GreaterThanCandidate_ReturnExpectedResultObject <T>(T candidate, T greaterThan,
                                                                            IComparer <T> comparer, SpecificationResult expected)
            {
                candidate = candidate?.ToString() != "null" ? candidate : default;
                var sut = new GreaterThanSpecification <T>(greaterThan, comparer);

                var overall = sut.IsNotSatisfiedBy(candidate, out var result);

                Assert.False(overall);
                Assert.Equal(expected, result, new SpecificationResultComparer(candidate));
            }
        public void CombineAndExpression()
        {
            var lessSpec      = new LessThanSpecification(5);
            var greaterSpec   = new GreaterThanSpecification(2);
            var array         = Enumerable.Range(0, 10).ToList();
            var combinedSpec  = lessSpec.And(greaterSpec);
            var filteredArray = array.Where(x => combinedSpec.IsSatisfiedBy(x)).ToList();

            array.Count.Should().BeGreaterThan(filteredArray.Count);
            filteredArray.Should().HaveCount(2);
            filteredArray.All(x => x > 2 && x < 5).Should().BeTrue();
        }
        // This test is currently failing because coercion code hasn't been merged to trunk yet
        public void Test_GreaterThan_CoerceTypes()
        {
            GreaterThanSpecification s = new GreaterThanSpecification();

            s.RefValueExpression = new ConstantExpression("1");

            Assert.IsFalse(s.Test(0).Success);
            Assert.IsFalse(s.Test(1).Success);
            Assert.IsTrue(s.Test(2).Success);
            //Assert.IsTrue(s.Test(null).Success);
            //Assert.IsTrue(s.Test(1).Success);
        }
        public void Test_GreaterThan_Exclusive()
        {
            GreaterThanSpecification s = new GreaterThanSpecification();

            s.RefValueExpression = new ConstantExpression(1);
            Assert.IsFalse(s.Test(0).Success);
            Assert.IsFalse(s.Test(1).Success);
            Assert.IsTrue(s.Test(2).Success);

            // null is less than any other value
            Assert.IsFalse(s.Test(null).Success);
        }
		public void Test_GreaterThan_CoerceTypes()
		{
			GreaterThanSpecification s = new GreaterThanSpecification();
			s.RefValueExpression = new ConstantExpression("1");

			Assert.IsFalse(s.Test(0).Success);
			Assert.IsFalse(s.Test(1).Success);
			Assert.IsTrue(s.Test(2).Success);

			Assert.IsFalse(s.Test(0.5).Success);
			Assert.IsTrue(s.Test(2.1).Success);

			// these will do string comparison, not numeric comparison
			Assert.IsFalse(s.Test("0.5").Success);
			Assert.IsTrue(s.Test("2.1").Success);

			// null is less than any other value
			Assert.IsFalse(s.Test(null).Success);
		}
Exemple #19
0
        public void Test_GreaterThan_CoerceTypes()
        {
            GreaterThanSpecification s = new GreaterThanSpecification();

            s.RefValueExpression = new ConstantExpression("1");

            Assert.IsFalse(s.Test(0).Success);
            Assert.IsFalse(s.Test(1).Success);
            Assert.IsTrue(s.Test(2).Success);

            Assert.IsFalse(s.Test(0.5).Success);
            Assert.IsTrue(s.Test(2.1).Success);

            // these will do string comparison, not numeric comparison
            Assert.IsFalse(s.Test("0.5").Success);
            Assert.IsTrue(s.Test("2.1").Success);

            // null is less than any other value
            Assert.IsFalse(s.Test(null).Success);
        }