예제 #1
0
        public void TestUpdateCommand()
        {
            var command = new UpdateCommand(HostEnvironment);

            command.Configure(null);

            string contents = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": [
    {
      ""library"": ""[email protected]"",
      ""files"": [ ""jquery.min.js"", ""jquery.js"" ]
    }
  ]
}";

            string libmanjsonPath = Path.Combine(WorkingDir, "libman.json");

            File.WriteAllText(libmanjsonPath, contents);

            var restoreCommand = new RestoreCommand(HostEnvironment);

            restoreCommand.Configure(null);

            restoreCommand.Execute();

            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js")));
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js")));

            int result = command.Execute("jquery");

            Assert.AreEqual(0, result);
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js")));
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js")));

            string actualText = File.ReadAllText(libmanjsonPath);

            string expectedText = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": [
    {
      ""library"": ""[email protected]"",
      ""files"": [
        ""jquery.min.js"",
        ""jquery.js""
      ]
    }
  ]
}";

            Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(actualText));
        }
예제 #2
0
        public void TestUpdateCommand_InvalidLibraryName()
        {
            var command = new UpdateCommand(HostEnvironment);

            command.Configure(null);

            string contents = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": [
    {
      ""library"": ""[email protected]"",
      ""files"": [
        ""jquery.min.js"",
        ""jquery.js""
      ]
    }
  ]
}";

            string libmanjsonPath = Path.Combine(WorkingDir, "libman.json");

            File.WriteAllText(libmanjsonPath, contents);

            var restoreCommand = new RestoreCommand(HostEnvironment);

            restoreCommand.Configure(null);

            restoreCommand.Execute();

            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js")));
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js")));

            int result = command.Execute("[email protected]");

            Assert.AreEqual(0, result);
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js")));
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js")));

            var    logger  = HostEnvironment.Logger as TestLogger;
            string message = "No library found with name \"[email protected]\" to update.\r\nPlease specify a library name without the version information to update.";

            Assert.AreEqual(StringHelper.NormalizeNewLines(message), StringHelper.NormalizeNewLines(logger.Messages.Last().Value));

            string actualText = File.ReadAllText(libmanjsonPath);

            Assert.AreEqual(StringHelper.NormalizeNewLines(contents), StringHelper.NormalizeNewLines(actualText));
        }
예제 #3
0
        public void TestUpdateCommand_InvalidUpdatedLibrary()
        {
            var command = new UpdateCommand(HostEnvironment);

            command.Configure(null);

            string contents = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": [
    {
      ""library"": ""[email protected]"",
      ""files"": [ ""jquery.min.js"", ""jquery.js"" ]
    }
  ]
}";

            string libmanjsonPath = Path.Combine(WorkingDir, "libman.json");

            File.WriteAllText(libmanjsonPath, contents);

            var restoreCommand = new RestoreCommand(HostEnvironment);

            restoreCommand.Configure(null);

            restoreCommand.Execute();

            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js")));
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js")));

            int result = command.Execute("jquery", "--to", "[email protected]");

            Assert.IsFalse(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js")));
            Assert.IsFalse(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js")));

            string actualText = File.ReadAllText(libmanjsonPath);

            Assert.AreEqual(StringHelper.NormalizeNewLines(contents), StringHelper.NormalizeNewLines(actualText));

            var logger = HostEnvironment.Logger as TestLogger;

            Assert.AreEqual(LogLevel.Error, logger.Messages.Last().Key);

            string expectedMessage = "Failed to update \"jquery\" to \"[email protected]\"";

            Assert.IsTrue(logger.Messages.Any(m => m.Value == expectedMessage));
        }
예제 #4
0
        public void TestUpdateCommand_AlreadyUpToDate()
        {
            var command = new UpdateCommand(HostEnvironment);

            command.Configure(null);

            string contents = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": [
    {
      ""library"": ""[email protected]"",
      ""files"": [ ""jquery.min.js"", ""jquery.js"" ]
    }
  ]
}";

            string libmanjsonPath = Path.Combine(WorkingDir, "libman.json");

            File.WriteAllText(libmanjsonPath, contents);

            var restoreCommand = new RestoreCommand(HostEnvironment);

            restoreCommand.Configure(null);

            restoreCommand.Execute();

            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js")));
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js")));

            int result = command.Execute("jquery");

            Assert.AreEqual(0, result);
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js")));
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js")));

            string actualText = File.ReadAllText(libmanjsonPath);

            Assert.AreEqual(StringHelper.NormalizeNewLines(contents), StringHelper.NormalizeNewLines(actualText));

            var logger = HostEnvironment.Logger as TestLogger;

            Assert.AreEqual("The library \"jquery\" is already up to date", logger.Messages.Last().Value);
        }
예제 #5
0
        public void Select_host()
        {
            var emptyServerUrl = InitHelper.RandomPort();
            var cfg            = new HttpSelfHostConfiguration(emptyServerUrl)
            {
                IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always,
                HostNameComparisonMode   = HostNameComparisonMode.Exact
            };
            var server = new HttpSelfHostServer(cfg);

            disposable.Add(server);
            server.OpenAsync().Wait();

            clientConfig = clientConfig.Clone();
            var normalServerUrl = clientConfig.BaseUrl;

            clientConfig.AltUri = emptyServerUrl + "," + normalServerUrl;
            var cmd = new UpdateCommand();

            disposable.Add(cmd);
            cmd.Configure(settings, clientConfig);
            Assert.AreEqual(normalServerUrl, cmd.ConfigureHttp().ToString());
        }
예제 #6
0
        public void TestUpdateCommand_AlreadyUpToDate()
        {
            var command = new UpdateCommand(HostEnvironment);

            command.Configure(null);

            string contents = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": [
  ]
}";

            string libmanjsonPath = Path.Combine(WorkingDir, "libman.json");

            File.WriteAllText(libmanjsonPath, contents);

            var installCommand = new InstallCommand(HostEnvironment);

            installCommand.Configure(null);
            installCommand.Execute("jquery --files jquery.min.js --files jquery.js".Split(' '));

            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js")));
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js")));

            int result = command.Execute("jquery");

            Assert.AreEqual(0, result);
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.min.js")));
            Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "wwwroot", "jquery.js")));

            var logger = HostEnvironment.Logger as TestLogger;

            Assert.AreEqual("The library \"jquery\" is already up to date", logger.Messages.Last().Value);
        }
예제 #7
0
        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);
        }