Beispiel #1
0
        public void TestInitialize()
        {
            //create in-memory context and inject to controller instance
            var options = new DbContextOptionsBuilder <LowballersContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            _context = new LowballersContext(options);

            var category = new Categories
            {
                CategoryId = 100,
                Name       = "Some Category"
            };

            //create mock data and add to in-memory database
            products.Add(new Products
            {
                ProductId = 200,
                Name      = "Prod 1",
                Price     = 12,
                Category  = category
            });

            //create mock data and add to in-memory database
            products.Add(new Products
            {
                ProductId = 30,
                Name      = "Prod 0",
                Price     = 15,
                Category  = category
            });

            //create mock data and add to in-memory database
            products.Add(new Products
            {
                ProductId = 29,
                Name      = "Prod 3",
                Price     = 55,
                Category  = category
            });

            foreach (var p in products)
            {
                _context.Add(p);
            }

            _context.SaveChanges();

            //instantiate controller with mock data in the dependency
            productsController = new ProductsController(_context);
        }
 public CategoriesController(LowballersContext context)
 {
     _context = context;
 }
Beispiel #3
0
 public ProductsController(LowballersContext context)
 {
     _context = context;
 }
Beispiel #4
0
 //constructor that accepts an instance of our dbcontext
 public ShopController(LowballersContext context, IConfiguration configuration)
 {
     _context        = context;
     _iconfiguration = configuration;
 }
 public OrdersController(LowballersContext context)
 {
     _context = context;
 }