コード例 #1
0
        public void SkipPriceRecalculationEndTime()
        {
            Mock <IPricingRepository> repo = new Mock <IPricingRepository>();
            int      logIdResult           = 123;
            string   actionExpected        = "Dish Pricing Calculation Skipped";
            string   actionResult          = string.Empty;
            DateTime dtResult = DateTime.MinValue;
            int      productIdResult;
            DateTime messageTime = DateTime.UtcNow;

            repo.Setup(x => x.GetLastMsmqStartTime(0)).Returns(() => { return(Task.FromResult <MsmqLog>(new MsmqLog()
                {
                    EndTime = DateTime.UtcNow.AddHours(1)
                })); });
            repo.Setup(x => x.CreateMsmqLog(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <DateTime>())).Callback <string, int, int, int, int, int, DateTime>((string action, int productId, int groupid, int pbandId, int setid, int unitId, DateTime dt) => {
                actionResult    = action;
                dtResult        = dt;
                productIdResult = productId;
            }).Returns(() => { return(Task.FromResult <int>(logIdResult)); });

            IPriceEngine engine = new PriceEngine(repo.Object);
            var          result = engine.GlobalRecalculation(true, messageTime).Result;

            Assert.Empty(result);
            Assert.Equal(actionExpected, actionResult);
            Assert.Equal(messageTime, dtResult);
            Assert.Equal(messageTime, dtResult);
        }
コード例 #2
0
        public void PriceRecalculationStoreSaveFailed()
        {
            Mock <IPricingRepository> repo = new Mock <IPricingRepository>();
            int      logIdResult           = 123;
            string   actionExpected        = "Dish Pricing Calculation";
            string   actionResult          = string.Empty;
            DateTime dtResult = DateTime.MinValue;
            int      productIdResult;
            DateTime messageTime = DateTime.UtcNow;

            repo.Setup(x => x.GetLastMsmqStartTime(0)).Returns(() => { return(Task.FromResult <MsmqLog>(new MsmqLog()
                {
                    StartTime = DateTime.UtcNow.AddHours(-1)
                })); });
            repo.Setup(x => x.CreateMsmqLog(It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <DateTime>())).Callback <string, int, int, int, int, int, DateTime>((string action, int productId, int groupid, int pbandId, int setid, int unitId, DateTime dt) => {
                actionResult    = action;
                dtResult        = dt;
                productIdResult = productId;
            }).Returns(() => { return(Task.FromResult <int>(logIdResult)); });

            List <ProductGroupPrice> privateItems = new List <ProductGroupPrice>();

            privateItems.Add(new ProductGroupPrice()
            {
                GroupId = 0, Price = 123.321m, ProductId = 1122
            });

            List <DbPrice> expectedPrices = new List <DbPrice>();

            expectedPrices.Add(new DbPrice()
            {
                ProductId = 1122, Price = 123.321m
            });

            List <Product> products = new List <Product>();

            products.Add(new Product()
            {
                ScopeId = 3, ProductId = 1122
            });

            repo.Setup(x => x.GetProducts()).Returns(() => { return(Task.FromResult <IEnumerable <Product> >(products)); });
            repo.Setup(x => x.GetProductParts()).Returns(() => { return(Task.FromResult <IEnumerable <ProductPart> >(new List <ProductPart>())); });
            repo.Setup(x => x.GetGroupProductPricesByGroup(It.IsAny <int>())).Returns(() => { return(Task.FromResult <IEnumerable <ProductGroupPrice> >(privateItems)); });

            repo.Setup(x => x.InsertPrices(It.IsAny <Dictionary <int, decimal> >(), It.Is <int?>(g => !g.HasValue), It.Is <int>(l => l == 123), It.Is <DateTime>(d => d == messageTime))).Returns(false);
            bool expectedSave = false;
            bool currentSave  = true;

            repo.Setup(x => x.UpdateMsmqLog(It.IsAny <DateTime>(), It.Is <int>(l => l == 123), It.Is <bool>(b => !b))).Returns(() => Task.FromResult <int>(1)).Callback((DateTime dt, int logid, bool success) => { currentSave = success; });

            IPriceEngine engine = new PriceEngine(repo.Object);
            var          result = engine.GlobalRecalculation(true, messageTime).Result;

            Assert.Equal(expectedSave, currentSave);
            Assert.Equal(actionExpected, actionResult);
            Assert.NotEmpty(result);
            Assert.Equal(expectedPrices, result);
        }
コード例 #3
0
        public async virtual void GlobalPriceRecalculationNoStorage(ITestOutputHelper output)
        {
            IPriceEngine engine = new PriceEngine(_pricingRepository);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            _customerDbRepository.ClearPrices();

            //act
            var prices = await engine.GlobalRecalculation(false, System.DateTime.UtcNow);

            sw.Stop();
            output.WriteLine($"Total Prices {prices.Count() }");
            output.WriteLine($"Total Seconds {sw.Elapsed.TotalSeconds }");
        }
コード例 #4
0
        public void PriceRecalculationNoStore()
        {
            Mock <IPricingRepository> repo = new Mock <IPricingRepository>();
            DateTime messageTime           = DateTime.UtcNow;

            repo.Setup(x => x.GetLastMsmqStartTime(0)).Returns(() => { return(Task.FromResult <MsmqLog>(new MsmqLog()
                {
                    StartTime = DateTime.UtcNow.AddHours(-1)
                })); });

            repo.Setup(x => x.GetProducts()).Returns(() => { return(Task.FromResult <IEnumerable <Product> >(new List <Product>())); });
            repo.Setup(x => x.GetProductParts()).Returns(() => { return(Task.FromResult <IEnumerable <ProductPart> >(new List <ProductPart>())); });
            repo.Setup(x => x.GetGroupProductPricesByGroup(It.IsAny <int>())).Returns(() => { return(Task.FromResult <IEnumerable <ProductGroupPrice> >(new List <ProductGroupPrice>())); });

            IPriceEngine engine = new PriceEngine(repo.Object);
            var          result = engine.GlobalRecalculation(false, messageTime).Result;

            Assert.Empty(result);
        }
コード例 #5
0
        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() }");
        }
コード例 #6
0
        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}");
        }