Exemplo n.º 1
0
        public void Cost_optimization_reset_fresh()
        {
            var supplier = TestSupplier.CreateNaked(session);

            supplier.CreateSampleCore(session);
            var supplier2 = TestSupplier.CreateNaked(session);

            supplier2.CreateSampleCore(session);
            var rule = new CostOptimizationRule(session.Load <Supplier>(supplier.Id), RuleType.MaxCost)
            {
                Diapasons   = { new CostOptimizationDiapason(0, decimal.MaxValue, 20) },
                Clients     = { session.Load <Client>(client.Id) },
                Concurrents = { session.Load <Supplier>(supplier2.Id) }
            };

            session.Save(rule);
            client.MaintainIntersection(session);
            client.Users[0].CleanPrices(session, supplier, supplier2);
            session.Flush();
            exporter.ExportDb();
            exporter.Confirm(new ConfirmRequest(requestLog.Id));

            supplier2.InvalidateCache(session, user.Id);

            Init(session.Load <AnalitfNetData>(user.Id).LastUpdateAt);
            exporter.ExportDb();
            var ids = ParseData("offers").Select(l => Convert.ToUInt64(l[0])).ToArray();

            Assert.IsTrue(ids.Contains(supplier.Prices[0].Core[0].Id), ids.Implode());
            var priceData = ParseData("prices").First(d => Convert.ToUInt32(d[0]) == supplier.Prices[0].Id);

            Assert.AreEqual(1, Convert.ToUInt32(priceData[17]));
        }
Exemplo n.º 2
0
        public void Cache_optimized_costs()
        {
            var supplier = TestSupplier.CreateNaked(session);
            var products = TestProduct.RandomProducts(session).Take(2).ToArray();

            supplier.CreateSampleCore(session, new[] { products[0] });
            var supplier2 = TestSupplier.CreateNaked(session);

            supplier2.CreateSampleCore(session, new[] { products[1] });
            var rule = new CostOptimizationRule(session.Load <Supplier>(supplier.Id), RuleType.MaxCost)
            {
                Diapasons   = { new CostOptimizationDiapason(0, decimal.MaxValue, 20) },
                Clients     = { session.Load <Client>(client.Id) },
                Concurrents = { session.Load <Supplier>(supplier2.Id) }
            };

            session.Save(rule);
            client.Users[0].CleanPrices(session, supplier, supplier2);
            client.MaintainIntersection(session);
            session.Flush();
            exporter.ExportDb();
            exporter.Confirm(new ConfirmRequest(requestLog.Id));

            var id     = supplier.Prices[0].Core[0].Id;
            var offers = ParseData("offers").ToArray();
            var offer  = offers.First(x => Convert.ToUInt64(x[0]) == id);

            Assert.AreEqual(120, Convert.ToDecimal(GetColumnValue("Offers", "Cost", offer), CultureInfo.InvariantCulture));

            //симулируем обновление прайс-листа
            supplier2.CreateSampleCore(session, new[] { products[0] }, new[] { supplier.Prices[0].Core[0].Producer });
            supplier2.InvalidateCache(session, user.Id);

            Init(session.Load <AnalitfNetData>(user.Id).LastUpdateAt);
            exporter.ExportDb();
            offers = ParseData("offers").ToArray();
            offer  = offers.First(x => Convert.ToUInt64(x[0]) == id);
            Assert.AreEqual(120, Convert.ToDecimal(GetColumnValue("Offers", "Cost", offer), CultureInfo.InvariantCulture));
        }
Exemplo n.º 3
0
        public void Cost_optimization()
        {
            var supplier = TestSupplier.CreateNaked(session);

            supplier.CreateSampleCore(session);
            var rule = new CostOptimizationRule(session.Load <Supplier>(supplier.Id), RuleType.MaxCost)
            {
                Diapasons = { new CostOptimizationDiapason(0, decimal.MaxValue, 20) },
                Clients   = { session.Load <Client>(client.Id) }
            };

            session.Save(rule);
            client.MaintainIntersection(session);
            client.Users[0].CleanPrices(session, supplier);
            session.Flush();
            exporter.ExportDb();
            var offers     = ParseData("offers");
            var offerData  = offers.First();
            var id         = Convert.ToUInt64(offerData[0]);
            var offer      = supplier.Prices[0].Core.First(c => c.Id == id);
            var resultCost = Convert.ToDecimal(GetColumnValue("Offers", "Cost", offerData), CultureInfo.InvariantCulture);

            Assert.AreEqual(offer.Costs[0].Cost * 1.2m, resultCost);
        }