public void ConvertDocumentLineTest()
        {
            PrepareTestDocumentLog();
            var assortPrice = _supplier.AddPrice("Ассортиментный", PriceType.Assortment);

            _client.Settings.AssortimentPrice = assortPrice;
            session.Save(_client.Settings);
            var synonym = new ProductSynonym("Тестовый синоним");

            session.Save(synonym);
            var prSynonym = new ProducerSynonym("Тестовый синоним");

            session.Save(prSynonym);
            var core = new Core {
                Code            = "0000",
                CodeCr          = "1111",
                CodeFirmCr      = (int)_producer.Id,
                Price           = assortPrice,
                ProducerSynonym = prSynonym,
                ProductSynonym  = synonym,
                ProductId       = (int)_product.Id,
                Quantity        = "1"
            };

            session.Save(core);
            session.Flush();
            _controller.Converted(_line.Id, _client.Id);

            Assert.That(_controller.PropertyBag["convertedLine"], Is.StringContaining("0000 Тестовый синоним"));
            Assert.That(_controller.PropertyBag["convertedLine"], Is.StringContaining("1111 Тестовый синоним"));
        }
        public void Success_price_delete()
        {
            var generator = new Random();
            var baseItems = supplier.Prices[0].Costs.Select(c => c.PriceItem.Id).ToList();

            Assert.That(baseItems.Count, Is.EqualTo(1));
            Save(supplier.Prices[0]);
            var price = supplier.AddPrice("forDelete");

            Save(price);
            session.CreateSQLQuery(string.Format("insert into ordersold.ordershead (RowId, PriceCode) value ({0}, {1})", generator.Next(10000), supplier.Prices[0].Id)).ExecuteUpdate();

            Open("managep.aspx?cc=" + supplier.Id);
            Click("Удалить");
            Click("Применить");

            session.Clear();
            var afterDeleting   = session.Query <PriceItem>().Where(i => baseItems.Contains(i.Id)).ToList();
            var ordersOldUpdate = session
                                  .CreateSQLQuery(string.Format("select count(RowId) from ordersold.ordershead where PriceCode ={0};", supplier.Prices[1].Id))
                                  .UniqueResult <long?>();

            Assert.AreEqual(afterDeleting.Count, 0);
            Assert.AreEqual(ordersOldUpdate, 1);
        }
        public Administrator Run()
        {
            using (new SessionScope()) {
                return(ArHelper.WithSession(s => {
                    //нужно только для того что бы запустить в браузере
                    var admin = Administrator.GetByName(Environment.UserName);
                    if (admin == null)
                    {
                        admin = Administrator.CreateLocalAdministrator();
                        s.Save(admin);
                    }

                    var origin = SecurityContext.GetAdministrator;
                    SecurityContext.GetAdministrator = () => admin;
                    var defaults = s.Query <DefaultValues>().First();
                    if (defaults.SmartOrderAssortmentPrice == null)
                    {
                        var payer = new Payer("Тестовый плательщик");
                        var homeRegion = s.Load <Region>(1UL);
                        var supplier = new Supplier(homeRegion, payer)
                        {
                            Name = "Тестовый поставщик",
                            FullName = "Тестовый поставщик",
                            ContactGroupOwner = new ContactGroupOwner(ContactGroupType.ClientManagers)
                        };
                        supplier.RegionalData.Add(new RegionalData {
                            Region = homeRegion, Supplier = supplier
                        });
                        defaults.SmartOrderAssortmentPrice = supplier.AddPrice("Базовый", PriceType.Assortment);
                        s.Save(supplier);
                    }
                    SecurityContext.GetAdministrator = origin;

                    if (!s.Query <ParseAlgorithm>().Any(p => p.Name == "DbfSource"))
                    {
                        s.Save(new ParseAlgorithm("DbfSource"));
                    }

                    return admin;
                }));
            }
        }
        public Supplier CreateSupplier(Action <Supplier> action = null)
        {
            var payer      = new Payer("Тестовый плательщик");
            var homeRegion = session.Load <Region>(1UL);
            var supplier   = new Supplier(homeRegion, payer)
            {
                Name              = "Тестовый поставщик",
                FullName          = "Тестовый поставщик",
                ContactGroupOwner = new ContactGroupOwner(ContactGroupType.ClientManagers)
            };

            supplier.RegionalData.Add(new RegionalData {
                Region = homeRegion, Supplier = supplier
            });
            supplier.AddPrice("Базовый");
            var user = new User(supplier.Payer, supplier);

            user.AssignDefaultPermission(session);
            user.Setup(session);
            action?.Invoke(supplier);
            return(supplier);
        }