public void Init() { Random r = new Random(); var databaseName = $"db_Test{r.Next(1, 100000000)}"; var options = new DbContextOptionsBuilder <GroceryStoreDbContext>() .UseInMemoryDatabase(databaseName: databaseName) .Options; _db = new GroceryStoreDbContext(options); _service = new GroceryStoreService(_db); var jObjects = JObject.Parse(File.ReadAllText("database.json")); //Customers JArray customerArray = jObjects.GetValue("customers") as JArray; var customers = customerArray.Select(p => new Customer { Id = (int)p["id"], Name = (string)p["name"] }); _db.Customers.AddRange(customers); //Orders var orders = new List <Order>(); JArray orderArray = jObjects.GetValue("orders") as JArray; _db.Orders.AddRange(orderArray.Select(p => p.ToObject <Order>())); //Products var productsArray = jObjects.GetValue("products") as JArray; var products = productsArray.Select(p => new Product { Id = (int)p["id"], Description = (string)p["description"], Price = (double)p["price"] }); _db.Products.AddRange(products); //"Save" everything in-memory _db.SaveChanges(); }
public ValuesController(IGroceryStoreService groceryStoreService) : base(groceryStoreService) { }
public ProductsController(IGroceryStoreService groceryStoreService) : base(groceryStoreService) { }
public CustomerController(IGroceryStoreService groceryStoreService) : base(groceryStoreService) { }
public OrdersController(IGroceryStoreService groceryStoreService) : base(groceryStoreService) { }
public CustomersController(IGroceryStoreService groceryStoreService) { _service = groceryStoreService; }
public OrdersController(IGroceryStoreService service) { _service = service; }
public ProductsController(IGroceryStoreService service) { _service = service; }
public GroceryStoreController(IGroceryStoreService groceryStoreService) { this.groceryStoreService = groceryStoreService; }