Example #1
0
        public void Xor_Should_Return_True_Only_If_Both_Specifications_Return_Different_Values()
        {
            var mocks = new MockRepository();
            var s1 = mocks.StrictMock<ISpecification<int>>();
            var s2 = mocks.StrictMock<ISpecification<int>>();

            // 1st call
            Expect.Call(s1.IsSatisfiedBy(5)).Return(true);
            Expect.Call(s2.IsSatisfiedBy(5)).Return(false);

            // 2nd call
            Expect.Call(s1.IsSatisfiedBy(5)).Return(false);
            Expect.Call(s2.IsSatisfiedBy(5)).Return(true);

            // 3rd call
            Expect.Call(s1.IsSatisfiedBy(5)).Return(true);
            Expect.Call(s2.IsSatisfiedBy(5)).Return(true);

            // 4th call
            Expect.Call(s1.IsSatisfiedBy(5)).Return(false);
            Expect.Call(s2.IsSatisfiedBy(5)).Return(false);

            mocks.ReplayAll();

            ISpecification<int> XorSpecification = new XorSpecification<int>(s1, s2);

            Assert.AreEqual(XorSpecification.IsSatisfiedBy(5), true);
            Assert.AreEqual(XorSpecification.IsSatisfiedBy(5), true);
            Assert.AreEqual(XorSpecification.IsSatisfiedBy(5), false);
            Assert.AreEqual(XorSpecification.IsSatisfiedBy(5), false);

            mocks.VerifyAll();
        }
Example #2
0
        public void Xor_Should_Return_True_Only_If_Both_Specifications_Return_Different_Values()
        {
            var mocks = new MockRepository();
            var s1    = mocks.StrictMock <ISpecification <int> >();
            var s2    = mocks.StrictMock <ISpecification <int> >();

            // 1st call
            Expect.Call(s1.IsSatisfiedBy(5)).Return(true);
            Expect.Call(s2.IsSatisfiedBy(5)).Return(false);

            // 2nd call
            Expect.Call(s1.IsSatisfiedBy(5)).Return(false);
            Expect.Call(s2.IsSatisfiedBy(5)).Return(true);

            // 3rd call
            Expect.Call(s1.IsSatisfiedBy(5)).Return(true);
            Expect.Call(s2.IsSatisfiedBy(5)).Return(true);

            // 4th call
            Expect.Call(s1.IsSatisfiedBy(5)).Return(false);
            Expect.Call(s2.IsSatisfiedBy(5)).Return(false);

            mocks.ReplayAll();

            ISpecification <int> XorSpecification = new XorSpecification <int>(s1, s2);

            Assert.AreEqual(XorSpecification.IsSatisfiedBy(5), true);
            Assert.AreEqual(XorSpecification.IsSatisfiedBy(5), true);
            Assert.AreEqual(XorSpecification.IsSatisfiedBy(5), false);
            Assert.AreEqual(XorSpecification.IsSatisfiedBy(5), false);

            mocks.VerifyAll();
        }
Example #3
0
        public void Should_Be_Fine_If_None_Are_Null()
        {
            var p1 = new PredicateSpecification<int>(x => x == 5);
            var p2 = new PredicateSpecification<int>(x => x >= 5);

            var spec = new XorSpecification<int>(p1, p2);

            Assert.AreEqual(spec.Left, p1);
            Assert.AreEqual(spec.Right, p2);
        }
Example #4
0
        public void Should_Be_Fine_If_None_Are_Null()
        {
            var p1 = new PredicateSpecification <int>(x => x == 5);
            var p2 = new PredicateSpecification <int>(x => x >= 5);

            var spec = new XorSpecification <int>(p1, p2);

            Assert.AreEqual(spec.Left, p1);
            Assert.AreEqual(spec.Right, p2);
        }
Example #5
0
        public void Xor_Should_Return_True_Only_If_Both_Specifications_Return_Different_Values(bool firstValue, bool secondValue, bool expected)
        {
            var s1 = new Mock <ISpecification <int> >();
            var s2 = new Mock <ISpecification <int> >();
            ISpecification <int> XorSpecification = new XorSpecification <int>(s1.Object, s2.Object);

            s1.Setup(x => x.IsSatisfiedBy(5)).Returns(firstValue);
            s2.Setup(x => x.IsSatisfiedBy(5)).Returns(secondValue);
            Assert.AreEqual(XorSpecification.IsSatisfiedBy(5), expected);
        }
Example #6
0
        public void IsSatisfiedByExample()
        {
            var divisibleByTwoSpecification   = new PredicateSpecification <int>(x => x % 2 == 0);
            var divisibleByThreeSpecification = new PredicateSpecification <int>(x => x % 3 == 0);

            var xorSpecifciation = new XorSpecification <int>(divisibleByTwoSpecification, divisibleByThreeSpecification);

            // Not divisible by either two or three
            Assert.IsFalse(xorSpecifciation.IsSatisfiedBy(1));

            // Divisible by two only
            Assert.IsTrue(xorSpecifciation.IsSatisfiedBy(2));

            // Divisible by thee only
            Assert.IsTrue(xorSpecifciation.IsSatisfiedBy(3));

            // Divisible by two and three
            Assert.IsFalse(xorSpecifciation.IsSatisfiedBy(6));
        }
        public void IsSatisfiedByExample()
        {
            var divisibleByTwoSpecification = new PredicateSpecification<int>(x => x % 2 == 0);
            var divisibleByThreeSpecification = new PredicateSpecification<int>(x => x % 3 == 0);

            var xorSpecifciation = new XorSpecification<int>(divisibleByTwoSpecification, divisibleByThreeSpecification);

            // Not divisible by either two or three
            Assert.IsFalse(xorSpecifciation.IsSatisfiedBy(1));

            // Divisible by two only
            Assert.IsTrue(xorSpecifciation.IsSatisfiedBy(2));

            // Divisible by thee only
            Assert.IsTrue(xorSpecifciation.IsSatisfiedBy(3));

            // Divisible by two and three
            Assert.IsFalse(xorSpecifciation.IsSatisfiedBy(6));
        }
Example #8
0
 /// <summary>
 ///     Create a new specification which is the logical OR of 2 specifications
 /// </summary>
 /// <typeparam name="T">Candidate type of specification</typeparam>
 /// <param name="lhs">LHS specification</param>
 /// <param name="rhs">RHS specification</param>
 /// <returns>New specification representing lhs OR rhs</returns>
 public static ISpecification <T> Xor <T>(this ISpecification <T> lhs, ISpecification <T> rhs)
 {
     return(XorSpecification <T> .Create(lhs, rhs));
 }