// constructor - method to create an instance of this class // Dependency Injection public ShopController(toprockContext context, IConfiguration configuration) { // accept in an instance of our db connection class and use this object to connect _context = context; // accept an instance of the configuration object so we can read appsettings _configuration = configuration; }
public void TestInitialize() { var options = new DbContextOptionsBuilder <toprockContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; _context = new toprockContext(options); products = new List <Product>(); // 2. create mock data and add to in-memory database Category mockCategory = new Category { CategoryId = 100, Name = "A Fake Category" }; products.Add(new Product { ProductId = 1, Name = "Product A", Price = 10, Category = mockCategory }); products.Add(new Product { ProductId = 2, Name = "Product B", Price = 5, Category = mockCategory }); products.Add(new Product { ProductId = 3, Name = "Product C", Price = 15, Category = mockCategory }); foreach (var p in products) { // add each product to in-memory db _context.Product.Add(p); } _context.SaveChanges(); productsController = new ProductsController(_context); }
public ProductsController(toprockContext context) { _context = context; }
public CategoriesController(toprockContext context) { _context = context; }
public OrdersController(toprockContext context) { _context = context; }