示例#1
0
        public void GetDataByGroupIdPageableTest()
        {
            PagedResult <Test> expectedResult;

            _repository
            .Setup(it => it.GetDataByGroupIdPageable(It.IsAny <Int32>(), It.IsAny <String>(), It.IsAny <Int32>(), It.IsAny <Int32>()))
            .Returns <Int32, String, Int32, Int32>((groupId, sortExpression, page, pageSize) =>
            {
                var query = _repositoryList.Where(x => x.GroupId == groupId);
                switch (sortExpression)
                {
                case  "Id":
                    query = new List <Test>(query.OrderBy(q => q.Id));
                    break;

                case  "TestTypeId":
                    query = new List <Test>(query.OrderBy(q => q.TestTypeId));
                    break;

                case  "ProjectId":
                    query = new List <Test>(query.OrderBy(q => q.ProjectId));
                    break;

                case  "GroupId":
                    query = new List <Test>(query.OrderBy(q => q.GroupId));
                    break;

                case  "Name":
                    query = new List <Test>(query.OrderBy(q => q.Name));
                    break;

                case  "TestValue":
                    query = new List <Test>(query.OrderBy(q => q.TestValue));
                    break;

                case  "IsActive":
                    query = new List <Test>(query.OrderBy(q => q.IsActive));
                    break;
                }
                return(query.Take(pageSize).Skip((page - 1) * pageSize).ToList());
            });

            _repository
            .Setup(it => it.GetDataByGroupIdRowCount(groupId))
            .Returns(_repositoryList.Count);

            var result = _target.GetDataByGroupIdPageable(GroupIdValue, "Id", 1, 2);

            Assert.IsTrue(result.TryGetContentValue(out expectedResult));
            Assert.AreEqual(_repositoryList.Where(x => x.GroupId == groupId).Take(2).ToList().Count, expectedResult.Results.Count);
            Assert.AreEqual(_repositoryList.Where(x => x.GroupId == groupId).OrderBy(q => q.Id).FirstOrDefault().Id, expectedResult.Results.FirstOrDefault().Id);
        }