public async Task SavePosition_UpdatingValidPosition_PositionUpdated() { var data = new List <Position> { new Position { id = 999, name = "q", description = "a" } }.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); var mockContext = new Mock <ExtremeSportDBEntities>(); mockContext.Setup(m => m.Position).Returns(mockSet.Object); var positionLogic = new PositionLogic { Context = mockContext.Object }; var b = await positionLogic.SavePosition(new DtoPosition { Id = 999, Name = "qqqqqqqqqqq", Description = "aaaa" }); Assert.AreEqual(b, true); mockSet.Verify(m => m.Add(It.IsAny <Position>()), Times.Never); mockContext.Verify(m => m.SaveChangesAsync(), Times.Once()); }
//保存职位信息 public ActionResult SavePostion(PositionModel pModel) { if (pModel.PositionId == null || pModel.PositionId.ToString().Length == 0) { pModel.PositionId = Guid.Empty; } PositionLogic logic = new PositionLogic(); var result = logic.SavePosition(pModel); return(Json(result)); }