Beispiel #1
0
        public void Execute_ShouldReturn_Success_WhenDeleteBranch_Succeeds()
        {
            var algorithm = Container.Resolve <IDependencyVisitorAlgorithm>();

            var options = new BranchSubOptions()
            {
                Delete      = true,
                ForceDelete = true,
                BranchName  = "feature/test_branch"
            };

            algorithm.Arrange(a => a.TraverseDependencies(Arg.IsAny <IVisitor>(), Arg.AnyString))
            .DoInstead((IVisitor visitor, string directory) =>
            {
                var deleteVisitor = visitor as DeleteBranchVisitor;
                Assert.IsNotNull(deleteVisitor, "The visitor should be of type DeleteBranchVisitor");
                Assert.AreEqual(deleteVisitor.BranchName, options.BranchName, "Invalid branch name");
                Assert.AreEqual(deleteVisitor.Force, options.ForceDelete, "Invalid force flag");
                visitor.ReturnCode = ReturnCode.Success;
            });


            var instance = new BranchCommand(options);
            var code     = instance.Execute();

            Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code");
        }
Beispiel #2
0
 /// <summary>
 /// Creates a enw <see cref="BranchCommand"/>
 /// </summary>
 /// <param name="options">The <see cref="BranchSubOptions"/> that controls the behavior of this command.</param>
 public BranchCommand(BranchSubOptions options)
 {
     _options   = options;
     _git       = DependencyInjection.Resolve <IGit>();
     _algorithm = DependencyInjection.Resolve <IDependencyVisitorAlgorithm>();
     _console   = DependencyInjection.Resolve <IConsole>();
 }
Beispiel #3
0
        public void Execute_ShouldReturn_InvalidArguments_WhenDeleteIsSpecifiedWithoutTheBranchName()
        {
            var options = new BranchSubOptions()
            {
                Delete     = true,
                BranchName = string.Empty
            };
            var instance = new BranchCommand(options);
            var code     = instance.Execute();

            Assert.AreEqual(ReturnCode.InvalidArguments, code, "Invalid Return Code");
        }
Beispiel #4
0
        public void Execute_ShouldReturn_InvalidArguments_WhenForceDeleteIsPresentWithoutDelete()
        {
            var options = new BranchSubOptions()
            {
                Delete      = false,
                ForceDelete = true
            };
            var instance = new BranchCommand(options);
            var code     = instance.Execute();

            Assert.AreEqual(ReturnCode.InvalidArguments, code, "Invalid Return Code");
        }
Beispiel #5
0
        public void Execute_ShouldReturn_InvalidArguments_WhenMultipleMutuallyExclusiveArgumentsArePresent()
        {
            var options = new BranchSubOptions()
            {
                Delete     = true,
                ListMerged = true
            };
            var instance = new BranchCommand(options);
            var code     = instance.Execute();

            Assert.AreEqual(ReturnCode.InvalidArguments, code, "Invalid Return Code");
        }
Beispiel #6
0
        public void Execute_ShouldReturn_InvalidArguments_WhenListMergedIsSpecifiedWithABranchName()
        {
            var options = new BranchSubOptions()
            {
                ListMerged = true,
                BranchName = "feature/test_branch"
            };
            var instance = new BranchCommand(options);
            var code     = instance.Execute();

            Assert.AreEqual(ReturnCode.InvalidArguments, code, "Invalid Return Code");
        }
Beispiel #7
0
        public void Execute_ShouldReturnError_WhenTraverseDependencies_Fails()
        {
            var algorithm = Container.Resolve <IDependencyVisitorAlgorithm>();

            algorithm.Arrange(a => a.TraverseDependencies(Arg.IsAny <IVisitor>(), Arg.AnyString))
            .DoInstead((IVisitor visitor, string directory) =>
            {
                visitor.ReturnCode = ReturnCode.FailedToRunGitCommand;
            });

            var options  = new BranchSubOptions();
            var instance = new BranchCommand(options);
            var code     = instance.Execute();

            Assert.AreEqual(ReturnCode.FailedToRunGitCommand, code, "Invalid Return Code");
        }
Beispiel #8
0
        public void Execute_ShouldReturn_Success_WhenListAllBranches_Succeeds()
        {
            var algorithm = Container.Resolve <IDependencyVisitorAlgorithm>();

            algorithm.Arrange(a => a.TraverseDependencies(Arg.IsAny <IVisitor>(), Arg.AnyString))
            .DoInstead((IVisitor visitor, string directory) =>
            {
                var listAllBranchesVisitor = visitor as ListAllBranchesVisitor;
                Assert.IsNotNull(listAllBranchesVisitor, "The visitor should be of type ListAllBranchesVisitor");
                visitor.ReturnCode = ReturnCode.Success;
            });

            var options  = new BranchSubOptions();
            var instance = new BranchCommand(options);
            var code     = instance.Execute();

            Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code");
        }
Beispiel #9
0
        public void Execute_ShouldReturn_Error_WhenListMerged_Fails()
        {
            var algorithm = Container.Resolve <IDependencyVisitorAlgorithm>();

            algorithm.Arrange(a => a.TraverseDependencies(Arg.IsAny <IVisitor>(), Arg.AnyString))
            .DoInstead((IVisitor visitor, string directory) =>
            {
                var mergedBranchesVisitor = visitor as ListMergedBranchesVisitor;
                Assert.IsNotNull(mergedBranchesVisitor, "The visitor should be of type ListMergedBranchesVisitor");
                visitor.ReturnCode = ReturnCode.FailedToRunGitCommand;
            });

            var options = new BranchSubOptions()
            {
                ListMerged = true
            };
            var instance = new BranchCommand(options);
            var code     = instance.Execute();

            Assert.AreEqual(ReturnCode.FailedToRunGitCommand, code, "Invalid Return Code");
        }
Beispiel #10
0
        public void Execute_ShouldReturn_Success_WhenCreateBranch_Succeeds()
        {
            const string BRANCH_NAME = "feature/test_branch";

            var algorithm = Container.Resolve <IDependencyVisitorAlgorithm>();

            algorithm.Arrange(a => a.TraverseDependencies(Arg.IsAny <IVisitor>(), Arg.AnyString))
            .DoInstead((IVisitor visitor, string directory) =>
            {
                var createBranchVisitor = visitor as CreateBranchVisitor;
                Assert.IsNotNull(createBranchVisitor, "The visitor should be of type CreateBranchVisitor");
                Assert.AreEqual(BRANCH_NAME, createBranchVisitor.BranchName, "Invalid branch name");
                visitor.ReturnCode = ReturnCode.Success;
            });

            var options = new BranchSubOptions()
            {
                BranchName = BRANCH_NAME
            };
            var instance = new BranchCommand(options);
            var code     = instance.Execute();

            Assert.AreEqual(ReturnCode.Success, code, "Invalid Return Code");
        }