示例#1
0
        public void Clear_ads()
        {
            var cfg = new Config.Config {
                RootDir = "test-tmp"
            };

            cleaner.WatchDir(cfg.RootDir);
            var adUpdateDir = Path.Combine(cfg.UpdateTmpDir, "ads");

            FileHelper.CreateDirectoryRecursive(adUpdateDir);
            File.WriteAllText(Path.Combine(adUpdateDir, "delete.me"), "");

            var ads = cfg.KnownDirs(new Settings()).First(d => d.Name == "ads");

            FileHelper.CreateDirectoryRecursive(ads.Dst);
            File.WriteAllText(Path.Combine(ads.Dst, "2block.gif"), "");

            new UpdateCommand().Move(ads);
            Assert.AreEqual("test-tmp\\ads\\delete.me", Directory.GetFiles(ads.Dst).Implode());
        }
示例#2
0
        public void Load_files()
        {
            var source = new CertificateSource {
                SourceClassName = typeof(AvestaSource).Name,
                LookupUrl       = new Uri(Path.GetFullPath("test-cert")).ToString(),
            };

            session.DeleteEach(session.Query <CertificateSource>().Where(s => s.SourceClassName == source.SourceClassName));
            FileHelper.InitDir("test-cert");
            cleaner.WatchDir("test-cert");

            var certFile = "test-cert\\Декларация.tif";

            File.WriteAllText(certFile, "");

            session.Save(source);
            session.Save(new CertificateSourceCatalog {
                CertificateSource = source,
                SupplierCode      = "jsodfij1",
                SerialNumber      = "012011",
                OriginFilePath    = @"\Декларация.tif",
            });
            var loader = new AvestaSource(cleaner);
            var line   = new DocumentLine {
                ProductEntity = new Product(),
                Code          = "jsodfij1",
                SerialNumber  = "012011",
            };
            var task = new CertificateTask(source, line);

            Assert.IsTrue(loader.CertificateExists(line));
            var files = loader.GetCertificateFiles(task, session);

            Assert.IsNull(line.CertificateError);
            Assert.AreEqual(1, files.Count);
        }
        public void Migrate()
        {
            var priceId    = localSession.Query <Price>().First().Id.PriceId;
            var supplierId = localSession.Query <Supplier>().First().Id;
            var addressId  = localSession.Query <Address>().First().Id;

            Directory.GetFiles(".", "*.txt").Each(File.Delete);
            FileHelper.InitDir("in\\update");
            localSession.Clear();
            DbHelper.Drop();
            using (var sanityCheck = new SanityCheck(clientConfig))
                sanityCheck.Check(true);

            using (var cleaner = new FileCleaner()) {
                var cmd = new UpdateCommand();
                cmd.Configure(settings, clientConfig);
                cmd.Process(() => {
                    cmd.Download();
                    var dir = Directory.CreateDirectory("in\\update");
                    cleaner.WatchDir(dir.FullName);
                    new DirectoryInfo(clientConfig.UpdateTmpDir).EnumerateFiles().Each(x => {
                        x.MoveTo(Path.Combine(dir.FullName, x.Name));
                    });
                    //идентфикаторы в тестовых данных
                    return(UpdateResult.OK);
                });

                cmd = new UpdateCommand();
                cmd.Configure(settings, clientConfig);
                cmd.Process(() => {
                    new DirectoryInfo("../../Assets/").EnumerateFiles().Each(x => cleaner.Watch(x.CopyTo(x.Name, true).FullName));
                    cmd.Migrate();
                    return(UpdateResult.OK);
                });
            }
            //идентификаторы не совпадают тк данные для переноса статичные, подделываем id для проверки
            localSession.CreateSQLQuery(@"
update Prices set PriceId = 7537 where PriceId = :priceId;
update Suppliers set Id = 234 where Id = :supplierId;
update Addresses set Id =  2575 where Id = :addressId")
            .SetParameter("priceId", priceId)
            .SetParameter("supplierId", supplierId)
            .SetParameter("addressId", addressId)
            .ExecuteUpdate();

            settings = localSession.Query <Settings>().First();
            Assert.IsNotNull(settings.Password);
            Assert.AreEqual(Taxation.Nds, settings.Waybills[0].Taxation);
            var map = localSession.Query <DirMap>().First(x => x.Supplier.Id == 18089);

            Assert.AreEqual(".\\Загрузка\\Предельные цены производителей", map.Dir);

            var order = localSession.Query <Order>().First();

            Assert.IsNotNull(order.Price);
            Assert.IsNotNull(order.Address);
            Assert.That(order.Lines[0].ResultCost, Is.GreaterThan(0));
            Assert.That(order.Lines[0].Producer, Is.Not.Null.Or.Empty);

            var sentOrder = localSession.Query <SentOrder>().First();

            Assert.IsNotNull(sentOrder.Price);
            Assert.IsNotNull(sentOrder.Address);
            Assert.That(sentOrder.Lines[0].ResultCost, Is.GreaterThan(0));
            Assert.That(sentOrder.Lines[0].Producer, Is.Not.Null.Or.Empty);

            var waybill = localSession.Query <Waybill>().First(x => x.Id == 39153110);

            Assert.IsNotNull(waybill.Supplier);
            Assert.IsNotNull(waybill.Address);
            var line = waybill.Lines.FirstOrDefault(x => x.SerialNumber == "10891996");

            Assert.AreEqual(35, line.MaxRetailMarkup);
            Assert.AreEqual(678.50, line.RetailCost);
            Assert.AreEqual(35, line.RetailMarkup);
            Assert.AreEqual(35, line.RealRetailMarkup);

            line = waybill.Lines.FirstOrDefault(x => x.SerialNumber == "10137353" &&
                                                x.Product.Contains("Ацетилсалициловой"));
            Assert.AreEqual(29.99m, line.RetailMarkup);
            Assert.AreEqual(70.21m, line.RealRetailMarkup);
            Assert.AreEqual(613.70m, line.RetailCost);

            line = waybill.Lines.FirstOrDefault(x => x.SerialNumber == "017022014");
            Assert.AreEqual(21.36m, line.RetailMarkup);
            Assert.AreEqual(49.99m, line.RealRetailMarkup);
            Assert.AreEqual(540.80m, line.RetailCost);

            line = waybill.Lines.FirstOrDefault(x => x.SerialNumber == "156014");
            Assert.AreEqual(77.63m, line.RetailMarkup);
            Assert.AreEqual(82.03m, line.RealRetailMarkup);
            Assert.AreEqual(500m, line.RetailCost);
        }