/// <summary>
        /// Create a GitModule with mockable GitExecutable
        /// </summary>
        /// <param name="path">Path to the module</param>
        /// <param name="executable">The mock executable</param>
        /// <returns>The GitModule</returns>
        private GitModule GetGitModuleWithExecutable(IExecutable executable, string path = "")
        {
            var module = new GitModule(path);

            typeof(GitModule).GetField("_gitExecutable", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(module, executable);
            var cmdRunner = new GitCommandRunner(executable, () => GitModule.SystemEncoding);

            typeof(GitModule).GetField("_gitCommandRunner", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(module, cmdRunner);

            return(module);
        }
Beispiel #2
0
        public void GetGitStatus_Test()
        {
            string     directory = Environment.CurrentDirectory;
            IGitRunner gitRunner = new GitCommandRunner(directory);
            //string expectedUser = "******";
            MockTaskLogger logger     = new MockTaskLogger("GitCommandRunner");
            GitInfo        status     = GetCommitInfo.GetGitStatus(gitRunner, logger);
            string         logEntries = string.Join('\n', logger.LogEntries.Select(e => e.ToString()));

            Assert.IsFalse(string.IsNullOrEmpty(status.Branch), $"Branch should not be null/empty.\n{logEntries}");
            Assert.IsFalse(string.IsNullOrEmpty(status.Modified), $"'Modified' should not be null/empty.\n{logEntries}");
            Assert.IsTrue(status.Modified == "Unmodified" || status.Modified == "Modified", $"'Modified' has an unrecognized value.\n{logEntries}");
            Assert.IsFalse(string.IsNullOrWhiteSpace(status.GitUser), $"GitUser should not be null/empty.\n{logEntries}");
            //Assert.AreEqual(expectedUser, status.GitUser);
        }
Beispiel #3
0
        public void SetUp()
        {
            if (_referenceRepository is null)
            {
                _referenceRepository = new ReferenceRepository();
            }
            else
            {
                _referenceRepository.Reset();
            }

            _commands = new GitUICommands(_referenceRepository.Module);

            // mock git executable
            _gitExecutable = new MockExecutable();
            typeof(GitModule).GetField("_gitExecutable", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(_commands.Module, _gitExecutable);
            var cmdRunner = new GitCommandRunner(_gitExecutable, () => GitModule.SystemEncoding);

            typeof(GitModule).GetField("_gitCommandRunner", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(_commands.Module, cmdRunner);
        }
        public void SetUp()
        {
            if (_referenceRepository == null)
            {
                _referenceRepository = new ReferenceRepository();
            }
            else
            {
                _referenceRepository.Reset();
            }

            _commands = new GitUICommands(_referenceRepository.Module);

            // mock git executable
            _gitExecutable = new MockExecutable();
            typeof(GitModule).GetField("_gitExecutable", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(_commands.Module, _gitExecutable);
            var cmdRunner = new GitCommandRunner(_gitExecutable, () => GitModule.SystemEncoding);

            typeof(GitModule).GetField("_gitCommandRunner", BindingFlags.Instance | BindingFlags.NonPublic)
            .SetValue(_commands.Module, cmdRunner);

            var uiCommandsSource = Substitute.For <IGitUICommandsSource>();

            uiCommandsSource.UICommands.Returns(x => _commands);

            // the following assignment of _commitInfo.UICommandsSource will already call this command
            _gitExecutable.StageOutput("for-each-ref --sort=-taggerdate --format=\"%(refname)\" refs/tags/", "");

            _commitInfo = new GitUI.CommitInfo.CommitInfo
            {
                UICommandsSource = uiCommandsSource
            };

            // let the async call be executed before the mockup of _gitExecutable will be changed
            AsyncTestHelper.WaitForPendingOperations(AsyncTestHelper.UnexpectedTimeout);
        }