public void Check_SetAssortimentInfo()
        {
            var file = "14356_4.dbf";

            var log = CreateTestLog(file);

            var product = new TestProduct("тестовый товар");

            product.SaveAndFlush();
            var productSynonym = new TestProductSynonym("Коринфар таб п/о 10мг № 50", product, price);

            productSynonym.SaveAndFlush();

            var producer = new TestProducer {
                Name = "Тестовый производитель"
            };

            producer.SaveAndFlush();

            var producerSynonym = new TestProducerSynonym {
                Price    = price,
                Name     = "Плива Хрватска д.о.о./АВД фарма ГмбХ и Ко КГ",
                Producer = producer
            };

            producerSynonym.SaveAndFlush();

            var core = new TestCore(productSynonym, producerSynonym)
            {
                Price    = price,
                Code     = "1234567",
                Quantity = "0",
                Period   = "01.01.2015"
            };

            core.SaveAndFlush();

            core = new TestCore(productSynonym, producerSynonym)
            {
                Price    = price,
                Code     = "111111",
                Quantity = "0",
                Period   = "01.01.2015"
            };
            core.SaveAndFlush();

            settings.IsConvertFormat    = true;
            settings.AssortimentPriceId = price.Id;
            settings.SaveAndFlush();
            FlushAndCommit();

            var service = new WaybillService();
            var ids     = service.ParseWaybill(new[] { log.Id });

            var doc = Document.Find(ids.Single());

            Assert.That(doc.Lines.Count, Is.EqualTo(1));
            Assert.IsTrue(doc.Lines[0].ProductEntity != null);
            Assert.That(doc.Lines[0].ProductEntity.Id, Is.EqualTo(product.Id));
            Assert.That(doc.Lines[0].ProducerId, Is.EqualTo(producer.Id));

            var resultDoc = DocumentReceiveLog.Queryable.Single(d => d.Address.Id == address.Id && !d.IsFake);
            var files     = Directory.GetFiles(waybillsPath, "*.dbf");

            Assert.That(files.Count(), Is.EqualTo(2), files.Implode());

            var data = Dbf.Load(resultDoc.GetFileName(), Encoding.GetEncoding(866));

            Assert.IsTrue(data.Columns.Contains("id_artis"));
            Assert.That(data.Rows[0]["id_artis"], Is.EqualTo("111111"));
            Assert.IsTrue(data.Columns.Contains("name_artis"));
            Assert.That(data.Rows[0]["name_artis"], Is.EqualTo("Коринфар таб п/о 10мг № 50"));
            Assert.IsTrue(data.Columns.Contains("przv_artis"));
            Assert.That(data.Rows[0]["przv_artis"], Is.EqualTo("Плива Хрватска д.о.о./АВД фарма ГмбХ и Ко КГ"));
        }
        public void Check_SetProductId_if_synonym_exists()
        {
            var file = "14356_4.dbf";

            var log = CreateTestLog(file);

            var product = new TestProduct("тестовый товар");

            product.SaveAndFlush();

            var productSynonym = new TestSynonym {
                ProductId = product.Id,
                Synonym   = "Коринфар таб п/о 10мг № 50",
                PriceCode = (int?)price.Id
            };

            productSynonym.SaveAndFlush();

            productSynonym = new TestSynonym {
                ProductId = null,
                Synonym   = "Коринфар таб п/о 10мг № 50",
                PriceCode = (int?)price.Id
            };

            var producer1 = new TestProducer {
                Name = "Тестовый производитель"
            };

            producer1.SaveAndFlush();

            var producer2 = new TestProducer {
                Name = "Тестовый производитель"
            };

            producer2.SaveAndFlush();

            var producerSynonym = new TestProducerSynonym {
                Price    = price,
                Name     = "Плива Хрватска д.о.о./АВД фарма ГмбХ и Ко КГ",
                Producer = null
            };

            producerSynonym.SaveAndFlush();

            producerSynonym = new TestProducerSynonym {
                Price    = price,
                Name     = "Плива Хрватска д.о.о./АВД фарма ГмбХ и Ко КГ",
                Producer = producer1
            };
            producerSynonym.SaveAndFlush();

            producerSynonym = new TestProducerSynonym {
                Price    = price,
                Name     = "Плива Хрватска д.о.о./АВД фарма ГмбХ и Ко КГ",
                Producer = producer2
            };
            producerSynonym.SaveAndFlush();
            FlushAndCommit();

            var service = new WaybillService();
            var ids     = service.ParseWaybill(new[] { log.Id });

            var waybill = TestWaybill.Find(ids.Single());

            Assert.That(waybill.Lines.Count, Is.EqualTo(1));
            Assert.IsTrue(waybill.Lines[0].CatalogProduct != null);
            Assert.That(waybill.Lines[0].CatalogProduct.Id, Is.EqualTo(product.Id));
            Assert.That(waybill.Lines[0].ProducerId, Is.EqualTo(producer1.Id));
        }