public async virtual void ProductPriceRecalculation(ITestOutputHelper output, int productId) { IPriceEngine engine = new PriceEngine(_pricingRepository); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); var result = _customerDbRepository.ExecutePriceRecalculation(productId, 0, 0, 0, 0); sw.Stop(); output.WriteLine($"Old price recalculation takes {sw.Elapsed.TotalSeconds} seconds."); //acknoledge sw.Restart(); var dbPrices = result.ToList(); var dt = System.DateTime.UtcNow; //act var prices = await engine.Recalculation(productId, false, dt); sw.Stop(); output.WriteLine($"New price recalculation takes {sw.Elapsed.TotalSeconds} seconds."); //Assert.Equal(dbPrices.Count, prices.Count()); var priceToUpdate = engine.ComparePrices(dbPrices, prices).ToList(); Assert.Empty(priceToUpdate); var pricesToDelete = engine.ComparePrices(prices, dbPrices).ToList(); Assert.Empty(pricesToDelete); output.WriteLine($"Total Prices {prices.Count() }"); }
public void PriceRecalculationPriceComparison() { Mock <IPricingRepository> repo = new Mock <IPricingRepository>(); IPriceEngine engine = new PriceEngine(repo.Object); List <DbPrice> existingPrices = new List <DbPrice>(); existingPrices.Add(new DbPrice() { GroupId = 1, ProductId = 1, Price = 1m }); existingPrices.Add(new DbPrice() { GroupId = 2, ProductId = 1, Price = 1m }); List <DbPrice> newPrices = new List <DbPrice>(); newPrices.Add(new DbPrice() { GroupId = 1, ProductId = 1, Price = 1m }); newPrices.Add(new DbPrice() { GroupId = 2, ProductId = 1, Price = 1m }); var result = engine.ComparePrices(existingPrices, newPrices); Assert.Empty(result); newPrices.Add(new DbPrice() { GroupId = 3, ProductId = 1, Price = 1m }); result = engine.ComparePrices(existingPrices, newPrices); Assert.Single(result); existingPrices.Add(new DbPrice() { GroupId = 3, ProductId = 1, Price = 1.1m }); result = engine.ComparePrices(existingPrices, newPrices); Assert.Single(result); existingPrices.Add(new DbPrice() { GroupId = 4, ProductId = 1, Price = 1m }); result = engine.ComparePrices(existingPrices, newPrices); Assert.Single(result); result = engine.ComparePrices(newPrices, existingPrices); Assert.Equal(2, result.Count()); }
public async virtual void GlobalPriceRecalculation(ITestOutputHelper output) { IPriceEngine engine = new PriceEngine(_pricingRepository); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); //var result = _pricingRepository.GetPrices().Where(g => g.GroupId == 225); //var prices = engine.GlobalRecalculation().Where(g => g.GroupId == 225).ToList(); _customerDbRepository.ClearPrices(); //var result = await _pricingRepository.GetPrices(); var result = _customerDbRepository.ExecutePriceRecalculation(0, 0, 0, 0, 0); sw.Stop(); output.WriteLine($"Old price recalculation takes {sw.Elapsed.TotalSeconds} seconds."); //acknoledge sw.Restart(); var dbPrices = result.ToList(); //act var prices = await engine.GlobalRecalculation(false, System.DateTime.UtcNow); sw.Stop(); output.WriteLine($"New price recalculation takes {sw.Elapsed.TotalSeconds} seconds."); Assert.Equal(dbPrices.Count, prices.Count()); var priceToUpdate = engine.ComparePrices(dbPrices, prices).ToList(); Assert.Empty(priceToUpdate); var pricesToDelete = engine.ComparePrices(prices, dbPrices).ToList(); Assert.Empty(pricesToDelete); output.WriteLine($"Total Prices {prices.Count() }"); }
static void Main(string[] args) { //var cnStr = "Initial Catalog=SCNET_Tish_Price_Test;Data Source=ie1scqaidb01.northeurope.cloudapp.azure.com;User ID=sl_web_user; Password=reddevil;"; //var cnStr = "Initial Catalog=SCNET_trg;Data Source=ie1scqaidb01.northeurope.cloudapp.azure.com;User ID=sl_web_user; Password=reddevil;"; //var cnStr = "Initial Catalog=SCNET_marstons;Data Source=ie1scqaidb01.northeurope.cloudapp.azure.com;User ID=sl_web_user; Password=reddevil;"; //var cnStr = "Initial Catalog=SCNET_trg;Data Source=.\\sqlexpress;User ID=sl_web_user; Password=reddevil;"; var cnStr = "Initial Catalog=SCNET_marstons;Data Source=.\\sqlexpress;User ID=sl_web_user; Password=reddevil;"; //var t = new RecalculationTests(cnStr); //t.RecipePriceRecalculations(); //return; Common.Repository.PricingRepository pr = new Common.Repository.PricingRepository(cnStr, 360); //var groupPrices2 = pr.GetGroupProductPricesByProduct(0, 455751, 0, 0, 0); //var prices = pr.GetPrices(); IPriceEngine engine = new PriceEngine(pr); //var prices = engine.CalculatePrices(0, 152596, 0, 0, 0); //var prices = engine.CalculatePrices(0, 0, 0, 1, 0); //var prices = engine.CalculatePrices(0, 0, 0, 0, 369); var prices = engine.GlobalRecalculation(false, System.DateTime.UtcNow).Result; //var prices = engine.CalculatePrices(0, 0, 0, 0, 0).ToList(); var taskPrices = pr.GetPrices().Result; var dbPrices = taskPrices.OrderBy(x => x.ProductId).ToList(); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); var priceToUpdate = engine.ComparePrices(dbPrices, prices).ToList(); var pricesToDelete = engine.ComparePrices(prices, dbPrices).ToList(); sw.Stop(); System.Diagnostics.Trace.WriteLine($"prices to update - {priceToUpdate.Count}"); System.Diagnostics.Trace.WriteLine($"prices to delete - {pricesToDelete.Count}"); System.Diagnostics.Trace.WriteLine($"Total Comparison time - {sw.Elapsed.TotalSeconds}"); }