Beispiel #1
0
        private EcommDataContext CreateStubContext()
        {
            var optionsBuilder = new DbContextOptionsBuilder <EcommDataContext>();

            optionsBuilder.UseInMemoryDatabase("TestDb");
            var context = new EcommDataContext(optionsBuilder.Options);

            // Add sample data
            context.Products.Add(new Product
            {
                Id          = 1,
                ProductName = "Milk",
                UnitPrice   = 2.50M
            });
            context.Products.Add(new Product
            {
                Id          = 2,
                ProductName = "Bread",
                UnitPrice   = 3.25M,
                SupplierId  = 1
            });
            context.Products.Add(new Product
            {
                Id          = 3,
                ProductName = "Juice",
                UnitPrice   = 5.75M
            });
            context.Suppliers.Add(new Supplier {
                Id = 1, CompanyName = "Acme"
            });

            context.SaveChanges();
            return(context);
        }
Beispiel #2
0
 public HomeController(EcommDataContext dataContext)
 {
     _dataContext = dataContext;
 }
Beispiel #3
0
 public ProductList(EcommDataContext dataContext)
 {
     _dataContext = dataContext;
 }
Beispiel #4
0
 public ProductController(EcommDataContext dataContext)
 {
     _dataContext = dataContext;
 }