상속: CommandBase
예제 #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");
        }
예제 #2
0
        public void Evaluate(IEnumerable <object> statements)
        {
            BeginScope();

            foreach (var statement in statements)
            {
                if (statement is Branch)
                {
                    Branch branch = (Branch)statement;

                    var branchCommand = new BranchCommand(branch.Left, branch.Right);
                    branchCommand.Run(this);
                }
                else if (statement is EndBranch)
                {
                    var endBranchCommand = new EndBranchCommand();
                    endBranchCommand.Run(this);
                }

                /* Todo: This breaks the pattern because we can't roll
                 *  up these commands into a list before looping through to run them.
                 */
                else if (SkipLines)
                {
                    var doNothingCommand = new DoNothingCommand();
                    doNothingCommand.Run(this);
                }

                else if (statement is CreateVariable)
                {
                    var createVariable = (CreateVariable)statement;

                    var createVariableCommand = new CreateVariableCommand(createVariable.Name,
                                                                          createVariable.Value);

                    createVariableCommand.Run(this);
                }
                else if (statement is Assignment)
                {
                    var assignment = (Assignment)statement;

                    var assignmentCommand = new AssignmentCommand(assignment.Name,
                                                                  assignment.Value);

                    assignmentCommand.Run(this);
                }
                else if (statement is MethodCall)
                {
                    var methodCall = (MethodCall)statement;

                    var methodCallCommand = new MethodCallCommand("print",
                                                                  methodCall.Arguments);

                    methodCallCommand.Run(this);
                }
            }

            EndScope();
        }
예제 #3
0
        public void TestLoadCommand()
        {
            IProjectNode project = ProjectSerializer.LoadString("rule root {\nbranch plural Plural-Form\n}\n", null, null);

            BranchCommand cmd = (BranchCommand)(project.Children[0].Children[0].Children[0]);

            Assert.AreEqual("plural", cmd.Name);
            Assert.AreEqual("Plural-Form", cmd.Rule);
        }
예제 #4
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");
        }
예제 #5
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");
        }
예제 #6
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");
        }
예제 #7
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");
        }
예제 #8
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");
        }
예제 #9
0
        public void Execute()
        {
            if (!CanExecute)
            {
                throw new InvalidOperationException("Cannot execute in the current state");
            }

            if (CurrentLine != null)
            {
                Command cmd;
                switch (CurrentLine.Instruction)
                {
                case MoveInstruction _:
                    cmd = new MoveCommand(this);
                    break;

                case ArithmeticInstruction _:
                    cmd = new ArithmeticCommand(this);
                    break;

                case BranchInstruction _:
                    cmd = new BranchCommand(this);
                    break;

                case HaltInstruction _:
                    cmd = new HaltCommand(this);
                    break;

                case StoreInstruction _:
                    cmd = new StoreCommand(this);
                    break;

                case LoadInstruction _:
                    cmd = new LoadCommand(this);
                    break;

                case NoOperation _:
                    cmd = new NoCommand(this);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                cmd.Execute();
            }
        }
예제 #10
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");
        }
예제 #11
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");
        }
예제 #12
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");
        }
예제 #13
0
        public void DashBranch(List <string> branchItems)
        {
            IHalationCommand cmd = new BranchCommand(Halation.CurrentSelectedLine, this.GetIndent(Halation.CurrentSelectedLine), Halation.currentCodePackage, branchItems);

            HalationInvoker.Dash(Halation.currentScriptName, cmd);
        }
예제 #14
0
        public void CreateBranchCommand()
        {
            var command = new BranchCommand(@"C:\Users\jeffr\Documents\EChest\Big Blocks\Resource Packs\FormatTest");

            command.Create("test_branch2");
        }