Ejemplo n.º 1
0
        //获取所有职位信息
        public ActionResult GetAllPositions(string positionName, string departmentName, int pageIndex, int pageSize)
        {
            PositionLogic logic = new PositionLogic();
            int           rowCount;
            var           data = logic.GetAllPositions(positionName, departmentName, pageIndex, pageSize, out rowCount);

            return(Json(new { Result = data, RowCount = rowCount }));
        }
Ejemplo n.º 2
0
        public async Task GetAllPositions_ReturningAllPositions_AllPositionsReturned()
        {
            var data = new List <Position>
            {
                new Position {
                    name = "BBB"
                },
                new Position {
                    name = "ZZZ"
                },
                new Position {
                    name = "AAA"
                }
            }.AsQueryable();
            var mockSet = new Mock <DbSet <Position> >();

            mockSet.As <IDbAsyncEnumerable <Position> >()
            .Setup(m => m.GetAsyncEnumerator())
            .Returns(new TestDbAsyncEnumerator <Position>(data.GetEnumerator()));
            mockSet.As <IQueryable <Position> >()
            .Setup(m => m.Provider)
            .Returns(new TestDbAsyncQueryProvider <Position>(data.Provider));
            mockSet.As <IQueryable <Position> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Position> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Position> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());
            var mockContext = new Mock <ExtremeSportDBEntities>();

            mockContext.Setup(c => c.Position).Returns(mockSet.Object);
            var positionLogic = new PositionLogic {
                Context = mockContext.Object
            };
            var pos = await positionLogic.GetAllPositions();

            Assert.AreEqual(3, pos.Count);
            Assert.AreEqual("BBB", pos[0].Name);
            Assert.AreEqual("ZZZ", pos[1].Name);
            Assert.AreEqual("AAA", pos[2].Name);
        }