public void Create_excludes()
        {
            var product        = Pharmacie().First();
            var catalogProduct = product.CatalogProduct;
            var synonym        = new TestProductSynonym("test", product, price);

            synonym.Save();
            var producerSynonym = new TestProducerSynonym("test", null, price);

            producerSynonym.Save();
            var expression = new TestUnrecExp(synonym, producerSynonym);

            expression.Save();

            Load();
            resolver.ExcludeProducer(GetRow(expression));
            Save();

            var exlcudes = TestExclude.Queryable.Where(e => e.Price == price).ToList();

            Assert.That(exlcudes.Count, Is.EqualTo(1), "не создали исключение");
            var exclude = exlcudes.Single();

            Assert.That(exclude.ProducerSynonym, Is.EqualTo(expression.FirmCr));
            Assert.That(exclude.CatalogProduct.Id, Is.EqualTo(catalogProduct.Id));
            Assert.That(exclude.OriginalSynonym.Id, Is.EqualTo(expression.ProductSynonymId));
        }
        public void Create_different_synonym_on_same_base_synonym()
        {
            var producerSynonym = new TestProducerSynonym("Test", null, price);

            producerSynonym.Save();
            new TestAutomaticSynonym {
                ProducerSynonymId = producerSynonym.Id
            }.Create();

            var productsWithAssortment = Pharmacie().Take(30).ToList().Where(p => p.CatalogProduct.Producers.Count > 0);
            var first    = productsWithAssortment.First();
            var products = productsWithAssortment.Where(p => p.CatalogProduct.Producers.All(pr => pr.Id != first.CatalogProduct.Producers[0].Id)).Take(1).ToList();

            products.Add(first);

            var synonym1 = new TestProductSynonym(products[0].CatalogProduct.Name, products[0], price);

            synonym1.Save();
            var synonym2 = new TestProductSynonym(products[1].CatalogProduct.Name, products[1], price);

            synonym2.Save();
            var exp1 = new TestUnrecExp(synonym1, producerSynonym);

            exp1.Save();
            var exp2 = new TestUnrecExp(synonym2, producerSynonym);

            exp2.Save();
            var producer1 = synonym1.Product.CatalogProduct.Producers.First();
            var producer2 = synonym2.Product.CatalogProduct.Producers.First();

            Load();
            Resolve(exp1, producer1);
            Resolve(exp2, producer2);
            Save();

            session.Clear();
            var synonyms = session.Query <TestProducerSynonym>().Where(s => s.Price == price).ToList();

            Assert.That(synonyms.Count, Is.EqualTo(2), "должны были создать два разных синонима, создали только ({0})",
                        synonyms.Implode(s => s.Name));
            var producerSynonym1 = synonyms.FirstOrDefault(s => s.Producer.Id == producer1.Id);
            var producerSynonym2 = synonyms.FirstOrDefault(s => s.Producer.Id == producer2.Id);

            Assert.That(producerSynonym1.Name, Is.EqualTo(producerSynonym.Name));
            Assert.That(producerSynonym1.Producer.Id, Is.EqualTo(producer1.Id));
            Assert.That(producerSynonym2.Name, Is.EqualTo(producerSynonym.Name));
            Assert.That(producerSynonym2.Producer.Id, Is.EqualTo(producer2.Id));
            var logs = session.CreateSQLQuery("select OperatorName, OperatorHost" +
                                              " from Logs.SynonymFirmCrLogs where SynonymFirmCrCode = :id and Operation = 1")
                       .SetParameter("id", producerSynonym2.Id)
                       .List <object[]>();

            Assert.AreEqual(Environment.UserName.ToLower(), logs[0][0].ToString().ToLower());
            Assert.AreEqual(Environment.MachineName, logs[0][1]);
        }
        public void CreateForbiddenProducerName()
        {
            var rnd            = new Random();
            var producerName   = "testTest" + rnd.Next();
            var product        = new TestProduct("Тестовый Продукт");
            var catalogProduct = product.CatalogProduct;

            catalogProduct.Pharmacie = true;
            product.Save();
            var synonym = new TestProductSynonym("test", product, price);

            synonym.Save();
            var producerSynonym = new TestProducerSynonym(producerName, null, price);

            producerSynonym.Save();
            var expression = new TestUnrecExp(synonym, producerSynonym);

            expression.Save();
            var notFormExpression = new TestUnrecExp("newTest", producerName, price);

            notFormExpression.Save();
            Load();
            resolver.ForbidProducer(GetRow(expression));
            Save();

            var query = session.CreateSQLQuery(String.Format("SELECT count(*) FROM farm.ForbiddenProducers F where F.Name='{0}'", producerName));
            var count = query.UniqueResult();

            Assert.That(count, Is.GreaterThan(0));
            var exclude = session.Query <TestExclude>().Where(e => e.Price == price);

            Assert.That(exclude.Count(), Is.EqualTo(0));
            var unrec = session.Query <TestUnrecExp>().Where(e => e.FirmCr.ToLower() == producerName && e.Status == 1);

            Assert.That(unrec.Count(), Is.EqualTo(0));
            unrec = session.Query <TestUnrecExp>().Where(e => e.FirmCr.ToLower() == producerName);
            Assert.That(unrec.Count(), Is.GreaterThan(0));
        }