public void Setup() { var builder = new DbContextOptionsBuilder <BikesContext>().UseSqlServer(ConnectionString); _context = new BikesContext(builder.Options); _service = new DiscountsService(_context); using (var transaction = _context.Database.BeginTransaction()) { _context.Products.Add(new Product { Id = 1, Manufacturer = "Acme", Name = "Toy", SalePrice = new decimal(1.25), Style = "Toddler", PurchasePrice = new decimal(1.50), QuantityAvailable = 5, CommissionPercentage = new decimal(.05) }); _context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [Products] ON"); _context.SaveChanges(); _context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [Products] OFF"); _context.Discounts.Add(new Discount { Id = 1, ProductId = 1, BeginDate = DateTime.UtcNow, DiscountPercentage = new decimal(.20), EndDate = DateTime.UtcNow.AddDays(2) }); _context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [Discounts] ON"); _context.SaveChanges(); _context.Database.ExecuteSqlCommand(@"SET IDENTITY_INSERT [Discounts] OFF"); transaction.Commit(); } }
public DiscountsController(DiscountsService productsService) { _discountsService = productsService; }
public DiscountsController(shopRUDBContext context, DiscountsService discountsService) { _discountsService = discountsService; }
public DiscountsController(BikesContext context) { this._service = new DiscountsService(context); }