public void Setup() { var users = new TestAsyncEnumerable <User>(new List <User>() { new User() { Id = 1, Username = "******", Password = "******", }, new User() { Id = 2, Username = "******", Password = "******", }, new User() { Id = 3, Username = "******", Password = "******" } }.AsQueryable()); _mockLandmarkContext = new Mock <Context>(new DbContextOptions <Context>()); _mockAppsettings = new Mock <IOptions <AppSettings> >(); _mockUserDbSet = new Mock <DbSet <User> >(); _mockLandmarkContext.Setup(m => m.Users).Returns(() => _mockUserDbSet.Object); var queryable = users.AsQueryable(); _mockUserDbSet.As <IQueryable <User> >().Setup(m => m.Provider).Returns(queryable.Provider); _mockUserDbSet.As <IQueryable <User> >().Setup(m => m.Expression).Returns(queryable.Expression); _mockUserDbSet.As <IQueryable <User> >().Setup(m => m.ElementType).Returns(queryable.ElementType); _mockUserDbSet.As <IQueryable <User> >().Setup(m => m.GetEnumerator()).Returns(() => queryable.GetEnumerator()); _mockLandmarkContext.Setup(p => p.Set <User>().Add(It.IsAny <User>())).Returns(() => null); }
public void Setup() { var remarks = new TestAsyncEnumerable <Remark>(new List <Remark>() { new Remark() { Id = 1, Note = "Sample note 1", User = new User() { Id = 1 }, UserId = 1 }, new Remark() { Id = 2, Note = "Sample note 2", User = new User() { Id = 1 }, UserId = 1 }, new Remark() { Id = 3, Note = "Sample note 3", User = new User() { Id = 2 }, UserId = 2 } }.AsQueryable()); _mockLandmarkContext = new Mock <Context>(new DbContextOptions <Context>()); _mockRemarkDbSet = new Mock <DbSet <Remark> >(); _mockLandmarkContext.Setup(m => m.Remarks).Returns(() => _mockRemarkDbSet.Object); var queryable = remarks.AsQueryable(); _mockRemarkDbSet.As <IQueryable <Remark> >().Setup(m => m.Provider).Returns(queryable.Provider); _mockRemarkDbSet.As <IQueryable <Remark> >().Setup(m => m.Expression).Returns(queryable.Expression); _mockRemarkDbSet.As <IQueryable <Remark> >().Setup(m => m.ElementType).Returns(queryable.ElementType); _mockRemarkDbSet.As <IQueryable <Remark> >().Setup(m => m.GetEnumerator()).Returns(() => queryable.GetEnumerator()); _mockLandmarkContext.Setup(p => p.Set <Remark>().Add(It.IsAny <Remark>())).Returns(() => null); }