Exemple #1
0
        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 ShowConfigCommand(options);

            var code = instance.Execute();

            Assert.AreEqual(ReturnCode.GitRepositoryNotFound, code, "Invalid Return Code");
            Assert.AreEqual(string.Empty, output.ToString());
        }
Exemple #2
0
        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 ShowConfigCommand(options);

            var code = instance.Execute();

            Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code");
            Assert.AreEqual(Lib2Config.ToString() + Environment.NewLine, output.ToString());
        }
Exemple #3
0
        /// <summary>
        /// Refreshes the client configuration information by calling the Mercurial command line
        /// client and asking it to report the current configuration.
        /// </summary>
        public void Refresh()
        {
            lock (_Configuration)
            {
                _Configuration.Clear();
                var command = new ShowConfigCommand();
                NonPersistentClient.Execute(command);

                foreach (ConfigurationEntry entry in command.Result.ToArray())
                {
                    Dictionary <string, string> section;
                    if (!_Configuration.TryGetValue(entry.Section, out section))
                    {
                        section = new Dictionary <string, string>();
                        _Configuration[entry.Section] = section;
                    }
                    section[entry.Name] = entry.Value;
                }
            }
        }
        /// <summary>
        /// Refreshes the client configuration information by calling the Mercurial command line
        /// client and asking it to report the current configuration.
        /// </summary>
        /// <param name="currentWorkingDirectory">Path to repo passed through --cwd param to Mercurial</param>
        public void Refresh(string currentWorkingDirectory = null)
        {
            lock (_Configuration)
            {
                _Configuration.Clear();
                var command = new ShowConfigCommand();
                if (currentWorkingDirectory != null)
                {
                    command.AddArgument($"--cwd {currentWorkingDirectory}");
                }
                NonPersistentClient.Execute(command);

                foreach (ConfigurationEntry entry in command.Result.ToArray())
                {
                    Dictionary <string, string> section;
                    if (!_Configuration.TryGetValue(entry.Section, out section))
                    {
                        section = new Dictionary <string, string>();
                        _Configuration[entry.Section] = section;
                    }
                    section[entry.Name] = entry.Value;
                }
            }
        }