public void VisitDependency_ShouldReturn_Success() { const string BRANCH = "feature/my_branch"; const bool FORCE = false; var instance = new DeleteBranchVisitor(BRANCH, FORCE); var code = instance.VisitDependency(Lib2Directory, Lib1Dependency); Assert.AreEqual(BRANCH, instance.BranchName, "Invalid branch name"); Assert.AreEqual(FORCE, instance.Force, "Invalid force flag"); Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code"); }
public void VisitProject_ShouldReturn_Success_WhenDeleteBranch_Fails() { const string BRANCH = "feature/my_branch"; const bool FORCE = false; var git = Container.Resolve <IGit>(); git.Arrange(g => g.DeleteBranch(Arg.AnyString, Arg.AnyBool)) .Returns(ReturnCode.FailedToRunGitCommand) .MustBeCalled(); var instance = new DeleteBranchVisitor(BRANCH, FORCE); var code = instance.VisitProject(Lib2Directory, Lib2Config); git.Assert(); Assert.AreEqual(ReturnCode.FailedToRunGitCommand, code, "Invalid Return Code"); Assert.AreEqual(Lib2Directory, git.WorkingDirectory, "Invalid working directory"); Assert.AreEqual(BRANCH, instance.BranchName, "Invalid branch name"); Assert.AreEqual(FORCE, instance.Force, "Invalid force flag"); }
/// <summary> /// Executes the command. /// </summary> /// <returns>The return code.</returns> public ReturnCode Execute() { bool[] flags = { _options.Delete, _options.ListMerged }; // only one mutually exclusive flag can be set. if (flags.Count(b => b) > 1) { return(ReturnCode.InvalidArguments); } // force delete can only be specified if delete is specified. if (!_options.Delete && _options.ForceDelete) { return(ReturnCode.InvalidArguments); } // if delete is specified the branch name must also be specified. if (_options.Delete && string.IsNullOrEmpty(_options.BranchName)) { return(ReturnCode.InvalidArguments); } if (_options.ListMerged && !string.IsNullOrEmpty(_options.BranchName)) { return(ReturnCode.InvalidArguments); } IVisitor visitor; string successMessage; Func <ReturnCode> postTraverse = null; if (_options.Delete) { visitor = new DeleteBranchVisitor(_options.BranchName, _options.ForceDelete); successMessage = $"Successfully deleted the {_options.BranchName} branch from all repositories."; } else if (_options.ListMerged) { visitor = new ListMergedBranchesVisitor(); successMessage = string.Empty; postTraverse = () => { _git.WorkingDirectory = _options.Directory; return(_git.ListMergedBranches()); }; } else if (!string.IsNullOrEmpty(_options.BranchName)) { visitor = new CreateBranchVisitor(_options.BranchName); successMessage = $"Successfully created the {_options.BranchName} branch in all repositories."; } else { visitor = new ListAllBranchesVisitor(); successMessage = string.Empty; postTraverse = () => { _git.WorkingDirectory = _options.Directory; return(_git.ListAllBranches()); }; } _algorithm.TraverseDependencies(visitor, _options.Directory); var code = visitor.ReturnCode; if (code == ReturnCode.Success && postTraverse != null) { var origColor = _console.ForegroundColor; _console.ForegroundColor = ConsoleColor.Green; _console.WriteLine("project:"); _console.WriteLine($" dir: {_options.Directory}"); _console.WriteLine(); _console.ForegroundColor = origColor; code = postTraverse(); } if (code == ReturnCode.Success) { _console.WriteLine(successMessage); } return(visitor.ReturnCode); }