public void InsertStocksThenListsWithStocksTest() { Clear(); using (var context = new DummyContext()) { foreach (var stock in DummyFactory.Stocks) { context.Stocks.Add(stock); } context.SaveChanges(); } using (var context = new DummyContext()) { foreach (var listWithStocks in DummyFactory.ListsWithStocks) { foreach (var stock in listWithStocks.Stocks) { context.Stocks.Attach(stock); } context.StockLists.AddOrUpdate(listWithStocks); } context.SaveChanges(); } AssertEf.AssertStocks(DummyFactory.StocksWithLists); AssertEf.AssertLists(DummyFactory.ListsWithStocks); }
public void InsertCountryTest() { Clear(); using (var context = new DummyContext()) { Stopwatch stopwatch = Stopwatch.StartNew(); context.Countries.AddOrUpdate(DummyFactory.Country); context.SaveChanges(); Console.WriteLine("dummyContext.Countries.AddOrUpdate(_country); took: " + stopwatch.ElapsedMilliseconds + " ms"); Assert.DoesNotThrow(() => context.Countries.Single(x => x.Id == DummyFactory.Country.Id)); } }
public void InsertEmptyListsTest() { Clear(); using (var context = new DummyContext()) { Stopwatch stopwatch = Stopwatch.StartNew(); context.StockLists.Add(DummyFactory.List1); context.StockLists.Add(DummyFactory.List2); context.SaveChanges(); Console.WriteLine("dummyContext.StockLists.AddOrUpdate(stockList); took: " + stopwatch.ElapsedMilliseconds + " ms"); } AssertEf.AssertLists(DummyFactory.Lists); }
private static void Clear() { using (var context = new DummyContext()) { var country = context.Countries.SingleOrDefault(x => x.Id == DummyFactory.Country.Id); if (country != null) context.Countries.Remove(country); foreach (var stockList in DummyFactory.Lists) { var removeList = context.StockLists.SingleOrDefault(x => x.Id == stockList.Id); if (removeList != null) context.StockLists.Remove(removeList); } foreach (var stock in DummyFactory.Stocks) { var removeStock = context.Stocks.SingleOrDefault(x => x.Id == stock.Id); if (removeStock != null) context.Stocks.Remove(removeStock); } context.SaveChanges(); } }
public void LoopAddCountriesTest() { Stopwatch stopwatch = Stopwatch.StartNew(); for (int i = 0; i < 10; i++) { stopwatch.Restart(); using (var dummyContext = new DummyContext()) { dummyContext.Countries.Add(new Country { Id = i.ToString(), Name = i.ToString() }); dummyContext.SaveChanges(); } Console.WriteLine("Adding {0} took {1} ms", i, stopwatch.ElapsedMilliseconds); } }
public void InsertStocksWithoutListsTest() { Clear(); using (var context = new DummyContext()) { foreach (var stock in DummyFactory.Stocks) { context.Stocks.AddOrUpdate(stock); } context.SaveChanges(); } AssertEf.AssertStocks(DummyFactory.Stocks); }