Exemplo n.º 1
0
        public void ToExpression_TestEntity_ShouldBeExcludedByAndCondition()
        {
            // arrange
            var leftSpecificationStub = new Mock <ISpecification <api.TestEntity> >();

            leftSpecificationStub.Setup(foo => foo.ToExpression()).Returns(p => p.Price > 0.0m);

            var rightSpecificationStub = new Mock <ISpecification <api.TestEntity> >();

            rightSpecificationStub.Setup(foo => foo.ToExpression()).Returns(p => p.Price < 10.0m);

            var testEntityDummy = new api.TestEntity()
            {
                Name  = "satoshi",
                Price = 10.00m,
            };

            Expression <Func <api.TestEntity, bool> > expectedResult = p => p.Price > 0.0m && p.Price < 10.0m;

            // act
            CompositeSpecification <api.TestEntity> sut = new AndSpecification <api.TestEntity>(leftSpecificationStub.Object, rightSpecificationStub.Object);
            var result = sut.ToExpression();

            Func <api.TestEntity, bool> sutDelegate = result.Compile();

            // assert
            Assert.False(sutDelegate(testEntityDummy));
        }