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

            client.MaintainIntersection(session);
            var price   = supplier.Prices[0];
            var product = session.Query <TestProduct>().First(p => !p.CatalogProduct.Hidden);
            var synonym = price.AddProductSynonym(product.CatalogProduct.Name, product);
            var core1   = new TestCore(synonym)
            {
                Quantity = "1500"
            };
            var core2 = new TestCore(synonym)
            {
                Quantity = "200"
            };

            session.Save(core1);
            session.Save(core2);
            core1.AddCost(100);
            core2.AddCost(150);
            session.Flush();
            session.Save(core1);
            session.Save(core2);

            exporter.Export();

            var offers = exporter.Result.First(t => t.ArchiveFileName.EndsWith("offers.txt"));
            var text   = File.ReadAllText(offers.LocalFileName);

            Assert.That(text, Does.Contain(core1.Id.ToString()));
            Assert.That(text, Does.Contain(core2.Id.ToString()));
        }
Ejemplo n.º 2
0
        private TestPrice CreateMaxProduceCosts(ISession session, TestSupplier supplier)
        {
            var source = supplier.Prices[0].Core.Where(c => c.Product.CatalogProduct.VitallyImportant);

            var holder = TestSupplier.CreateNaked(session);

            holder.Name = "Предельные цены производителей";
            var price    = holder.Prices[0];
            var synonyms = source.GroupBy(c => new { c.Product, c.Producer })
                           .Select(g => Tuple.Create(g.Key.Product.CatalogProduct.Name, g.Key.Product, g.Key.Producer.Name, g.Key.Producer));
            var random = new Random();

            foreach (var data in synonyms)
            {
                var productSynonymValue = data.Item1;
                if (price.ProductSynonyms.Any(s => s.Name == productSynonymValue))
                {
                    productSynonymValue += " " + random.Next(100000).ToString();
                }
                var producerSynonymValue = data.Item3;
                if (price.ProducerSynonyms.Any(s => s.Name == producerSynonymValue))
                {
                    producerSynonymValue += " " + random.Next(10000).ToString();
                }

                var productSynonym  = price.AddProductSynonym(productSynonymValue, data.Item2);
                var producerSynonym = price.AddProducerSynonym(producerSynonymValue, data.Item4);
                var core            = new TestCore(productSynonym, producerSynonym)
                {
                    Price    = price,
                    Quantity = "10",
                };
                session.Save(core);
                core.AddCost((decimal)(random.NextDouble() * 10000));
                price.Core.Add(core);
                session.Save(core);
            }

            price.Costs[0].PriceItem.RowCount = price.Core.Count;
            return(price);
        }
Ejemplo n.º 3
0
        public void CreateSampleCore(ISession session, TestSupplier supplier, double maxCost = 10000)
        {
            var price                 = supplier.Prices[0];
            var random                = new Random();
            var producers             = session.Query <TestProducer>().Take(1000).ToList();
            var productWithProperties = session.Query <TestProduct>().Where(p => p.Properties != "").Take(50).ToArray();
            var products              = session.Query <TestProduct>().Fetch(p => p.CatalogProduct).Where(p => !p.CatalogProduct.Hidden).Take(1000).ToList();

            var maxProducer = producers.Count();
            var maxProduct  = products.Count();

            var randomProducts  = Generator.Random(maxProduct).Select(i => products.Skip(i).Take(1).First());
            var randomProducers = Generator.Random(maxProducer).Select(i => producers.Skip(i).Take(1).First());

            var synonyms         = new List <Tuple <string, TestProduct, string, TestProducer> >();
            var productForCreate = mandatory.Concat(randomProducts.Take(20))
                                   .Concat(randomProducts.Where(p => p.CatalogProduct.VitallyImportant).Take(7))
                                   .Concat(randomProducts.Where(p => p.CatalogProduct.MandatoryList).Take(3))
                                   .Concat(randomProducts.Where(p => p.CatalogProduct.MandatoryList && p.CatalogProduct.VitallyImportant).Take(2))
                                   .Concat(Random(productWithProperties).Take(2))
                                   .Concat(randomProducts.Where(p => p.CatalogProduct.Narcotic || p.CatalogProduct.Toxic || p.CatalogProduct.Other || p.CatalogProduct.Combined).Take(1))
                                   .Concat(products.Where(p => products.Count(c => c.CatalogProduct == p.CatalogProduct) > 1).Take(3));

            foreach (var product in productForCreate)
            {
                var producer = randomProducers.First();
                synonyms.Add(Tuple.Create(product.CatalogProduct.Name, product, producer.Name, producer));
            }
            foreach (var data in synonyms)
            {
                var productSynonymValue = data.Item1;
                if (price.ProductSynonyms.Any(s => s.Name == productSynonymValue))
                {
                    productSynonymValue += " " + random.Next();
                }
                var producerSynonymValue = data.Item3;
                if (price.ProducerSynonyms.Any(s => s.Name == producerSynonymValue))
                {
                    producerSynonymValue += " " + random.Next();
                }

                var productSynonym  = price.AddProductSynonym(productSynonymValue, data.Item2);
                var producerSynonym = price.AddProducerSynonym(producerSynonymValue, data.Item4);
                var core            = new TestCore(productSynonym, producerSynonym)
                {
                    Price    = price,
                    Quantity = random.Next(1, 10 * 1000).ToString(),
                    Junk     = random.Next(100) < 5,
                };
                core.Exp    = DateTime.Today.AddMonths(random.Next(7, 60));
                core.Period = core.Exp.Value.ToShortDateString();
                //в 30% случаев товар имеет штрих код
                if (random.Next(2) == 0)
                {
                    core.EAN13 = String.Join("", Enumerable.Range(0, 13).Select(_ => random.Next(9)));
                }
                //в 10% случаев есть ндс
                if (random.Next(9) == 0)
                {
                    core.NDS = 10;
                }
                session.Save(core);
                core.AddCost((decimal)(random.NextDouble() * maxCost));
                price.Core.Add(core);
                session.Save(core);
            }

            price.Costs[0].PriceItem.RowCount = price.Core.Count;
        }