public async Task Index_CanLoadFromContext() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseSqlite(connection) .Options; using (var context = new ApplicationDbContext(options)) { context.Database.EnsureCreated(); context.ProductType.AddRange( new ProductType { Nome = "Alimento" }, new ProductType { Nome = "Educação" }, new ProductType { Nome = "Bem-Estar" }); context.SaveChanges(); context.Product.AddRange( new Product { ProductTypeID = 1, Nome = "Osso", Referencia = "PR12345", Preco = 5.0, Quantidade = 10, QuantidadeLimite = 5 }, new Product { ProductTypeID = 1, Nome = "Osso", Referencia = "PR12345", Preco = 5.0, Quantidade = 10, QuantidadeLimite = 5 }, new Product { ProductTypeID = 1, Nome = "Osso", Referencia = "PR12345", Preco = 5.0, Quantidade = 10, QuantidadeLimite = 5 }); context.SaveChanges(); } using (var context = new ApplicationDbContext(options)) { var controller = new ProductTypeController(context); var result = await controller.Index(); var viewResult = Assert.IsType <ViewResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <ProductType> >( viewResult.ViewData.Model); Assert.Equal(3, model.Count()); } }