Exemple #1
0
        //todo:感觉Application里面不应该提供这么宽泛的接口出去,应该提供的是具体条件的实现
        public List <UserDTO> GetUsers(Expression <Func <UserDTO, bool> > spec)
        {
            Expression <Func <User, bool> > newExpression = ExpressionConvertor <UserDTO, User> .Convert(spec);

            IEnumerable <User> users = userRepository.GetAll(newExpression);

            return(Mapper.Map <List <User>, List <UserDTO> >(users.ToList()));
        }
        public void ConvertExpressionTypeTest()
        {
            Expression <Func <UserDTO, bool> > expression = dto => dto.UserName.Contains("11");
            Func <User, bool> newFunc = ExpressionConvertor <UserDTO, User> .Convert(expression).Compile();

            User u = new User("111", "password", null);
            bool b = newFunc(u);

            Assert.IsTrue(b);

            u = new User("ert", "password", null);
            b = newFunc(u);
            Assert.IsTrue(!b);
        }