public void NullableCandidate_ReturnFalse(int?candidate, int?lessThan)
            {
                var sut = new LessThanSpecification <int?>(lessThan);

                var result = sut.IsSatisfiedBy(candidate);

                Assert.False(result);
            }
            public void InvokeNullableCandidate_ReturnFalse(int?candidate, int?lessThan)
            {
                var sut = new LessThanSpecification <int?>(lessThan);

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

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

                var result = sut.IsSatisfiedBy(candidate);

                Assert.False(result);
            }
コード例 #4
0
        public void InvokeLessThan_ReturnLessThanSpecification()
        {
            var comparer = new FakeIntComparer();
            var expected = new LessThanSpecification <int>(0, comparer);

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

            Assert.Equal(expected, sut, new SpecificationComparer());
        }
            public void InvokeLessThanCandidate_ReturnFalse <T>(T candidate, T lessThan, IComparer <T> comparer)
            {
                candidate = candidate?.ToString() != "null" ? candidate : default;
                var sut = new LessThanSpecification <T>(lessThan, comparer);

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

                Assert.False(result);
            }
            public void NonGenericILinqSpecification_ReturnExpressionAsAbstractExpression()
            {
                var sut = new LessThanSpecification <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?lessThan,
                                                                            SpecificationResult expected)
            {
                var sut = new LessThanSpecification <int?>(lessThan);

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

                Assert.True(overall);
                Assert.Equal(expected, result, new SpecificationResultComparer());
            }
コード例 #8
0
        public void Test_LessThan_Options2()
        {
            ISpecification s = _factory.GetSpecification("lessThan_options2");

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

            LessThanSpecification s1 = (LessThanSpecification)s;

            Assert.AreEqual("XXX", s1.RefValueExpression.Text);
            Assert.AreEqual(true, s1.Inclusive);
        }
            public void NotLessThanCandidate_ReturnExpectedResultObject <T>(T candidate, T lessThan,
                                                                            IComparer <T> comparer, SpecificationResult expected)
            {
                candidate = candidate?.ToString() != "null" ? candidate : default;
                var sut = new LessThanSpecification <T>(lessThan, comparer);

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

                Assert.False(overall);
                Assert.Equal(expected, result, new SpecificationResultComparer(candidate));
            }
コード例 #10
0
		public void Test_LessThan_Exclusive()
		{
			LessThanSpecification s = new LessThanSpecification();
			s.RefValueExpression = new ConstantExpression(1);
			Assert.IsTrue(s.Test(0).Success);
			Assert.IsFalse(s.Test(1).Success);
			Assert.IsFalse(s.Test(2).Success);

			// null is less than any other value
			Assert.IsTrue(s.Test(null).Success);
		}
コード例 #11
0
        public void Test_LessThan_Strict()
        {
            LessThanSpecification s = new LessThanSpecification();

            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);
        }
コード例 #12
0
        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();
        }
コード例 #13
0
        // This test is currently failing because coercion code hasn't been merged to trunk yet
        public void Test_LessThan_CoerceTypes()
        {
            LessThanSpecification s = new LessThanSpecification();

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

            Assert.IsTrue(s.Test(0).Success);
            //Assert.IsTrue(s.Test(1).Success);
            Assert.IsFalse(s.Test(2).Success);
            //Assert.IsFalse(s.Test(null).Success);
            Assert.IsFalse(s.Test(1).Success);
        }
コード例 #14
0
        public void Test_LessThan_Exclusive()
        {
            LessThanSpecification s = new LessThanSpecification();

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

            // null is less than any other value
            Assert.IsTrue(s.Test(null).Success);
        }
コード例 #15
0
        public void CombineOrExpression()
        {
            var lessSpec      = new LessThanSpecification(-5);
            var positiveSpec  = new PositiveSpecification();
            var array         = Enumerable.Range(-10, 20).ToList();
            var combinedSpec  = positiveSpec.Or(lessSpec);
            var filteredArray = array.Where(x => combinedSpec.IsSatisfiedBy(x)).ToList();

            array.Count.Should().BeGreaterThan(filteredArray.Count);
            filteredArray.Should().HaveCount(15);
            filteredArray.All(x => x < -5 || x >= 0).Should().BeTrue();
        }
コード例 #16
0
        public void Test_LessThan_CoerceTypes()
        {
            LessThanSpecification s = new LessThanSpecification();

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

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

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

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

            // null is less than any other value
            Assert.IsTrue(s.Test(null).Success);
        }
コード例 #17
0
		public void Test_LessThan_Strict()
		{
			LessThanSpecification s = new LessThanSpecification();
			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);
		}
コード例 #18
0
		public void Test_LessThan_CoerceTypes()
		{
			LessThanSpecification s = new LessThanSpecification();
			s.RefValueExpression = new ConstantExpression("1");

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

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

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

			// null is less than any other value
			Assert.IsTrue(s.Test(null).Success);
		}
コード例 #19
0
		// This test is currently failing because coercion code hasn't been merged to trunk yet
		public void Test_LessThan_CoerceTypes()
		{
			LessThanSpecification s = new LessThanSpecification();
			s.RefValueExpression = new ConstantExpression("1");

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