public void Execute_ShouldReturnError_WhenLoadFails()
        {
            var        console = Container.Resolve <IConsole>();
            var        factory = Container.Resolve <IGitDependFileFactory>();
            string     dir;
            ReturnCode loadCode = ReturnCode.GitRepositoryNotFound;

            factory.Arrange(f => f.LoadFromDirectory(Arg.AnyString, out dir, out loadCode))
            .Returns(null as GitDependFile);

            StringBuilder output = new StringBuilder();

            console.Arrange(c => c.WriteLine(Arg.AnyObject))
            .DoInstead((object obj) =>
            {
                output.AppendLine(obj.ToString());
            });

            var options  = new ConfigSubOptions();
            var instance = new ConfigCommand(options);

            var code = instance.Execute();

            Assert.AreEqual(ReturnCode.GitRepositoryNotFound, code, "Invalid Return Code");
            Assert.AreEqual(string.Empty, output.ToString());
        }
Esempio n. 2
0
        public void ShouldAddConfigurationVariables([Frozen] Mock <IApplicationConfiguration> applicationConfiguration,
                                                    [Frozen] Mock <IAppHarborClient> client,
                                                    [Frozen] Mock <TextWriter> writer,
                                                    ConfigCommand command, string applicationId)
        {
            applicationConfiguration.Setup(x => x.GetApplicationId()).Returns(applicationId);
            var configurationVariables = new List <ConfigurationVariable>
            {
                new ConfigurationVariable {
                    Key = "foo", Value = "bar"
                },
                new ConfigurationVariable {
                    Key = "baz", Value = "qux"
                },
            };

            client.Setup(x => x.GetConfigurationVariables(applicationId)).Returns(configurationVariables);

            command.Execute(new string[0]);

            foreach (var configurationVariable in configurationVariables)
            {
                writer.Verify(x => x.WriteLine("{0} => {1}", configurationVariable.Key, configurationVariable.Value));
            }
        }
        public void Execute_ShouldPrintExistingConfig_WhenConfigExistsInGitRepo()
        {
            var        console = Container.Resolve <IConsole>();
            var        factory = Container.Resolve <IGitDependFileFactory>();
            string     dir;
            ReturnCode loadCode = ReturnCode.Success;

            factory.Arrange(f => f.LoadFromDirectory(Arg.AnyString, out dir, out loadCode))
            .Returns(Lib2Config);

            StringBuilder output = new StringBuilder();

            console.Arrange(c => c.WriteLine(Arg.AnyObject))
            .DoInstead((object obj) =>
            {
                output.AppendLine(obj.ToString());
            });

            var options  = new ConfigSubOptions();
            var instance = new ConfigCommand(options);

            var code = instance.Execute();

            Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code");
            Assert.AreEqual(Lib2Config.ToString() + Environment.NewLine, output.ToString());
        }
        public void Config_Execute_ReturnsEmpty()
        {
            var console = new TestConsole(_output);
            var command = new ConfigCommand(console, (new Mock <ILogger <ConfigCommand> >()).Object);

            var message = command.Execute();

            Assert.Equal("", message);
        }
Esempio n. 5
0
        public void RemoveExistingEncryptedValue()
        {
            HostEnvironment.HostInteraction.Settings.SetEncryptedValue("TestSetting", "oldValue");
            var command = new ConfigCommand(HostEnvironment);

            command.Configure(null);

            _ = command.Execute("--setEncrypted TestSetting=".Split(" "));

            Assert.IsFalse(HostEnvironment.HostInteraction.Settings.TryGetValue("TestSetting", out _));
        }
Esempio n. 6
0
        public void SetExistingValue()
        {
            HostEnvironment.HostInteraction.Settings.SetValue("TestSetting", "oldValue");
            var command = new ConfigCommand(HostEnvironment);

            command.Configure(null);

            _ = command.Execute("--set TestSetting=testValue".Split(" "));

            Assert.IsTrue(HostEnvironment.HostInteraction.Settings.TryGetValue("TestSetting", out string value));
            Assert.AreEqual("testValue", value);
        }
Esempio n. 7
0
        public void SetNewEncryptedValue()
        {
            Assert.IsFalse(HostEnvironment.HostInteraction.Settings.TryGetValue("TestSetting", out _));
            var command = new ConfigCommand(HostEnvironment);

            command.Configure(null);

            _ = command.Execute("--setEncrypted TestSetting=testValue".Split(" "));

            Assert.IsTrue(HostEnvironment.HostInteraction.Settings.TryGetValue("TestSetting", out string value));
            Assert.AreNotEqual("testValue", value);
        }
Esempio n. 8
0
        public void Execute_WithOnlyInvalidPathFlag_FileDoesNotExist()
        {
            // Arrange
            string        testPath = "some config that does not exist";
            ConfigCommand command  = new ConfigCommand(false, false, testPath);

            testConfigHandler.Setup(m => m.DoesConfigExist(testPath)).Returns(false);

            // Act
            command.Execute(testConsole, testConfigHandler.Object, testConfig.Object, testPathResolver);

            // Assert
            Assert.IsTrue(testConsole.GetHistory().Contains("does not exist"));
        }
Esempio n. 9
0
        public void Execute_WithDeleteFlag_FileDoesNotExist()
        {
            // Arrange
            string        testPath      = "doesnotexist";
            ConfigCommand configCommand = new ConfigCommand(false, true, testPath);

            testConfigHandler.Setup(m => m.DoesConfigExist(testPath)).Returns(false);

            // Act
            configCommand.Execute(testConsole, testConfigHandler.Object, testConfig.Object, testPathResolver);

            // Assert
            Assert.IsTrue(testConsole.GetHistory().Contains("does not exist", System.StringComparison.OrdinalIgnoreCase));
        }
Esempio n. 10
0
        public void Execute_WithDeleteFlag_ShouldDeleteFile()
        {
            // Arrange
            string        testPath      = testFileSystem.AllFiles.First();
            ConfigCommand configCommand = new ConfigCommand(false, true, testPath);

            testConfigHandler.Setup(m => m.DoesConfigExist(testPath)).Returns(true);

            // Act
            configCommand.Execute(testConsole, testConfigHandler.Object, testConfig.Object, testPathResolver);

            // Assert
            testConfigHandler.Verify(m => m.DeleteConfig(testPath));
        }
Esempio n. 11
0
        public void Execute_WithConfigFlag_FileAlreadyExists()
        {
            // Arrange
            string        testPath      = testFileSystem.AllFiles.First();
            ConfigCommand configCommand = new ConfigCommand(true, false, testPath);

            testConfigHandler.Setup(m => m.DoesConfigExist(testPath)).Returns(true);

            // Act
            configCommand.Execute(testConsole, testConfigHandler.Object, testConfig.Object, testPathResolver);

            // Assert
            Assert.IsTrue(testConsole.GetHistory().Contains("already exists", System.StringComparison.OrdinalIgnoreCase));
        }
Esempio n. 12
0
        public void Execute_WithConfigFlag_ShouldCreateFile()
        {
            // Arrange
            const string  testPath      = "config.linker";
            ConfigCommand configCommand = new ConfigCommand(true, false, testPath);

            testConfigHandler.Setup(m => m.DoesConfigExist(testPath)).Returns(false);

            // Act
            configCommand.Execute(testConsole, testConfigHandler.Object, testConfig.Object, testPathResolver);

            // Assert
            testConfigHandler.Verify(m => m.SaveConfig(testConfig.Object, testPath));
        }
Esempio n. 13
0
        public void ReadExistingSetting_ShouldPrintValueOnly()
        {
            HostEnvironment.HostInteraction.Settings.SetValue("TestSetting", "testValue");
            var mockLogger = new Mock <ILogger>();

            mockLogger.Setup(log => log.Log(It.Is <string>(s => s.Equals("testValue", StringComparison.Ordinal)),
                                            It.Is <LogLevel>(l => l == LogLevel.Task)));
            HostEnvironment.Logger = mockLogger.Object;

            var command = new ConfigCommand(HostEnvironment);

            command.Configure(null);

            _ = command.Execute("TestSetting");

            mockLogger.Verify();
        }
Esempio n. 14
0
        public void Execute_WithOnlyPathFlag_WillPrintTotalLinks()
        {
            // Arrange
            string        testPath = testFileSystem.AllFiles.First();
            ConfigCommand command  = new ConfigCommand(false, false, testPath);

            testLinks.Add(testLinkElements[0]);

            testConfigHandler.Setup(m => m.LoadConfig(testPath)).Returns(testConfig.Object);
            testConfigHandler.Setup(m => m.DoesConfigExist(testPath)).Returns(true);

            // Act
            command.Execute(testConsole, testConfigHandler.Object, testConfig.Object, testPathResolver);

            // Assert
            Assert.IsTrue(testConsole.GetHistory().Contains("Total links: " + testLinks.Count));
        }
Esempio n. 15
0
        public void ReadNonExistingSetting_ShouldLogError()
        {
            var command = new ConfigCommand(HostEnvironment);

            command.Configure(null);

            try
            {
                _ = command.Execute("TestSetting");
                Assert.Fail();
            }
            catch (AggregateException ae)
            {
                var ioe = ae.InnerException as InvalidOperationException;
                Assert.IsNotNull(ioe);
                string expected = string.Format(Resources.Text.ConfigCommand_Error_KeyNotFound, "TestSetting");
                Assert.AreEqual(expected, ioe.Message);
            }
        }
Esempio n. 16
0
        public void ReadAndWriteInSameInvocation_ShouldFailWithError()
        {
            var command = new ConfigCommand(HostEnvironment);

            command.Configure(null);

            try
            {
                _ = command.Execute("TestSetting --set TestSetting2=testValue".Split(" "));
                Assert.Fail();
            }
            catch (AggregateException ae)
            {
                var ioe = ae.InnerException as InvalidOperationException;
                Assert.IsNotNull(ioe);
                string expected = Resources.Text.ConfigCommand_Error_ConflictingParameters;
                Assert.AreEqual(expected, ioe.Message);
            }
        }
Esempio n. 17
0
        public void ShouldWriteIfThereAreNoConfigurationVariables([Frozen] Mock <TextWriter> writer, ConfigCommand command)
        {
            command.Execute(new string[0]);

            writer.Verify(x => x.WriteLine("No configuration variables are associated with this application"));
        }
Esempio n. 18
0
        public override void Run(string[] args)
        {
            options = new CmdParserOptionSet()
            {
                { "h|help", "Display this help information. To see online help, use: git help <command>", v => OfflineHelp() },

/*                { "replace-all", "Replaces all lines matching the key (and optionally the value_regex).", v => cmd.ReplaceAll = true},
 *              { "add", "Adds a new line to the option without altering any existing values.", v => cmd.Add = false},
 *              { "get", "Get the value for a given key", v => cmd.Get = true},
 *              { "get-all", "Like get, but can handle multiple values for the key.", v=> cmd.GetAll = true},
 *              { "get-regexp", "Like --get-all, but interprets the name as a regular expression", v => cmd.GetRegExp = true},
 *              { "global", "Use the per-user config file instead of the default.", v => cmd.Global = true},
 *              { "system", "Use the system-wide config file instead of the default.", v => cmd.System = true},
 *              { "f|file", "Use the given config file instead of the one specified by GIT_CONFIG", (string v) => cmd.File = v},
 *              { "remove-section", "Remove the given section from the configuration file", v => cmd.RemoveSection = true},
 *              { "rename-section", "Rename the given section to a new name", v => cmd.RenameSection = true},
 *              { "unset", "Remove the line matching the key from config file", v => cmd.UnSet = true},
 *              { "unset-all", "Remove all lines matching the key from config file", v => cmd.UnSetAll = true},*/
                { "l|list", "List all variables set in config file", v => cmd.List = true },

/*                { "bool", "Ensure that the output is true or false", v => cmd.Bool = true },
 *              { "int", "Ensure that the output is a simple decimal number", v => cmd.Int = true },
 *              { "bool-or-int", "Ensure that the output matches the format of either --bool or --int, as described above", v => cmd.BoolOrInt = true },
 *              { "z|null", "Always end values with null character instead of newlines", v => cmd.Null = true },
 *              { "get-colorbool", "Find the color setting for {name} and output as true or false", v => cmd.GetColorBool = true },
 *              { "get-color", "Find the color configured for {name}", v => cmd.GetColor = true },
 *              { "e|edit", "Opens an editor to modify the specified config file as --global, --system, or repository (default)", v => cmd.Edit = true },*/
            };

            try
            {
                List <String> arguments = ParseOptions(args);
                if (arguments.Count > 0)
                {
                    cmd.Arg1 = arguments[0];

                    if (arguments.Count > 1)
                    {
                        cmd.Arg2 = arguments[1];
                    }
                    else
                    {
                        cmd.Arg2 = "";
                    }

                    if (arguments.Count > 2)
                    {
                        cmd.Arg3 = arguments[2];
                    }
                    else
                    {
                        cmd.Arg3 = "";
                    }

                    cmd.Execute();
                }
                else if (cmd.List)
                {
                    cmd.Execute();
                }
                else
                {
                    OfflineHelp();
                }
            }
            catch (Exception e)
            {
                cmd.OutputStream.WriteLine(e.Message);
            }
        }