Beispiel #1
0
        public void GetDataPageableTest()
        {
            PagedResult <Test> expectedResult;

            _repository
            .Setup(it => it.GetDataPageable(It.IsAny <String>(), It.IsAny <Int32>(), It.IsAny <Int32>()))
            .Returns <String, Int32, Int32>((sortExpression, page, pageSize) =>
            {
                var query = _repositoryList;
                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.GetRowCount())
            .Returns(_repositoryList.Count);

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

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