public void Repo_ValidOrder_AddsToDb() { // arrange using var connection = new SqliteConnection("Data Source=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <DataModel.Models.TrainingProjectContext>().UseSqlite(connection).Options; var customer = new Customer("John", "Doe", "*****@*****.**"); var location = new Location("TestLocation", "", "", "", "", "", ""); Dictionary <int, int> productsList = new Dictionary <int, int>(); var order = new Order(location, customer, DateTime.Now, productsList); using (var context = new DataModel.Models.TrainingProjectContext(options)) { context.Database.EnsureCreated(); var repo = new StoreRepository(context); repo.AddCustomer(customer); repo.AddLocation(location); customer.Id = 1; location.Id = 1; repo.UpdateLocationStock(location); repo.Save(); // act repo.AddOrder(order); repo.Save(); } // assert using var context2 = new DataModel.Models.TrainingProjectContext(options); DataModel.Models.Order orderActual = context2.Orders.Single(o => o.Id == 1); Assert.Equal(order.Time, orderActual.Date); }
public void AddLocation_Database_Test() { // arrange using var connection = new SqliteConnection("Data Source=:memory:"); connection.Open(); var options = new DbContextOptionsBuilder <StoreAppDbContext>().UseSqlite(connection).Options; var location = new Location { Id = 1, Name = "Walmart" }; // act using (var context = new StoreAppDbContext(options)) { context.Database.EnsureCreated(); var repo = new StoreRepository(context, new NullLogger <StoreRepository>()); repo.AddLocation(location); } //assert using var context2 = new StoreAppDbContext(options); LocationEntity customerActual = context2.Locations .Single(l => l.Name == "Walmart"); Assert.Equal(location.Name, customerActual.Name); }