Exemple #1
0
        public void TestNotAlreadyInstalledReturnsFalse()
        {
            _mResolver.Setup(r => r.CheckInstalled()).Returns(false);
            UninstallCommand uninstallCommand = new UninstallCommand(_mResolver.Object, "", _mLogger.Object);

            Assert.False(uninstallCommand.Execute());
        }
Exemple #2
0
        public void TestResolveReturnsTrue()
        {
            _mResolver.Setup(r => r.CheckInstalled()).Returns(true);
            _mResolver.Setup(r => r.Remove()).Returns(true);
            UninstallCommand uninstallCommand = new UninstallCommand(_mResolver.Object, "", _mLogger.Object);

            Assert.True(uninstallCommand.Execute());
        }
        public void TestUninstall_NoLibraryToUninstall()
        {
            var command = new UninstallCommand(HostEnvironment);

            command.Configure(null);

            string contents = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": [
    {
      ""provider"": ""cdnjs"",
      ""library"": ""[email protected]"",
      ""destination"": ""wwwroot"",
      ""files"": [
        ""jquery.min.js"",
        ""core.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", "core.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", "core.js")));

            var logger = HostEnvironment.Logger as TestLogger;

            Assert.AreEqual("Library \"[email protected]\" is not installed. Nothing to uninstall", logger.Messages[logger.Messages.Count - 1].Value);

            string actualText = File.ReadAllText(libmanjsonPath);

            Assert.AreEqual(StringHelper.NormalizeNewLines(contents), StringHelper.NormalizeNewLines(actualText));
        }
        public void TestUninstall()
        {
            var command = new UninstallCommand(HostEnvironment);

            command.Configure(null);

            string contents = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": [
    {
      ""library"": ""[email protected]"",
      ""files"": [ ""jquery.min.js"", ""core.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", "core.js")));

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

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

            string expectedText = @"{
  ""version"": ""1.0"",
  ""defaultProvider"": ""cdnjs"",
  ""defaultDestination"": ""wwwroot"",
  ""libraries"": []
}";
            string actualText   = File.ReadAllText(libmanjsonPath);

            Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(actualText));
        }
Exemple #5
0
        static int Main(string[] args)
        {
            Logger logger = new Logger();
            var    app    = new CommandLineApplication();

            app.Name        = "dotnet get";
            app.FullName    = ".NET Core Tools Global Installer";
            app.Description = "Install and use command line tools built on .NET Core";
            app.HelpOption("-h|--help");
            app.VersionOption("-v|--version", GetAssemblyVersion());

            CommandOption verboseOption = app.Option("--verbose", "Enable verbose output", CommandOptionType.NoValue);

            app.OnExecute(() =>
            {
                app.ShowHelp();
                return(0);
            });

            app.Command("install", c =>
            {
                c.Description = "Installs a .NET Core tool";
                c.HelpOption("-h|--help");

                CommandArgument source = c.Argument("<SOURCE>", "The tool to install. Can be a NuGet package");

                c.OnExecute(() =>
                {
                    logger = new Logger(verboseOption.HasValue());
                    if (string.IsNullOrWhiteSpace(source.Value))
                    {
                        logger.LogError("<SOURCE> argument is required. Use -h|--help to see help");
                        return(1);
                    }

                    InstallCommand installCommand = new InstallCommand(source.Value, logger);
                    return(installCommand.Execute() ? 0 : 1);
                });
            });

            app.Command("update", c =>
            {
                c.Description = "Updates a .NET Core tool";
                c.HelpOption("-h|--help");

                CommandArgument source = c.Argument("<SOURCE>", "The tool to update.");

                c.OnExecute(() =>
                {
                    logger = new Logger(verboseOption.HasValue());
                    if (string.IsNullOrWhiteSpace(source.Value))
                    {
                        return(Update(logger) ? 0 : 1);
                    }

                    UpdateCommand updateCommand = new UpdateCommand(source.Value, logger);
                    return(updateCommand.Execute() ? 0 : 1);
                });
            });

            app.Command("list", c =>
            {
                c.Description = "Lists all installed .NET Core tools";
                c.HelpOption("-h|--help");

                c.OnExecute(() =>
                {
                    logger = new Logger(verboseOption.HasValue());
                    ListCommand listCommand = new ListCommand(logger);
                    return(listCommand.Execute() ? 0 : 1);
                });
            });

            app.Command("uninstall", c =>
            {
                c.Description = "Uninstalls a .NET Core tool";
                c.HelpOption("-h|--help");

                CommandArgument source = c.Argument("<SOURCE>", "The tool to uninstall.");

                c.OnExecute(() =>
                {
                    logger = new Logger(verboseOption.HasValue());
                    if (string.IsNullOrWhiteSpace(source.Value))
                    {
                        logger.LogError("<SOURCE> argument is required. Use -h|--help to see help");
                        return(1);
                    }

                    UninstallCommand uninstallCommand = new UninstallCommand(source.Value, logger);
                    return(uninstallCommand.Execute() ? 0 : 1);
                });
            });

            try
            {
                return(app.Execute(args));
            }
            catch (CommandParsingException ex)
            {
                logger.LogWarning(ex.Message);
                app.ShowHelp();
                return(1);
            }
        }
Exemple #6
0
        public void TestNoResolverReturnsFalse()
        {
            UninstallCommand uninstallCommand = new UninstallCommand("/", _mLogger.Object);

            Assert.False(uninstallCommand.Execute());
        }