public async Task OnGetAsync_PopulatesThePageModel_WithAListOfTodoItems() { // Arrange var optionsBuilder = new DbContextOptionsBuilder <BetterDoDbContext>() .UseInMemoryDatabase("InMemoryDb"); #region snippet1 var mockAppDbContext = new Mock <BetterDoDbContext>(optionsBuilder.Options); var expectedMessages = BetterDoDbContext.GetSeedingTodoItems(); mockAppDbContext.Setup( db => db.GetTodoItemsAsync()).Returns(Task.FromResult(expectedMessages)); var pageModel = new IndexModel(mockAppDbContext.Object); #endregion #region snippet2 // Act await pageModel.OnGetAsync(); #endregion #region snippet3 // Assert var actualMessages = Assert.IsAssignableFrom <List <TodoItem> >(pageModel.TodoItems); Assert.Equal( expectedMessages.OrderBy(m => m.ID).Select(m => m.Title), actualMessages.OrderBy(m => m.ID).Select(m => m.Title)); #endregion }
public IndexModel(BetterDo.Data.BetterDoDbContext context) { _context = context; }