public void DefineCommand() { IList <ICommand> commandlist = new List <ICommand>(); commandlist.Add(new SetVariableCommand("a", new ConstantExpression(1))); commandlist.Add(new SetVariableCommand("b", new ConstantExpression(2))); CompositeCommand commands = new CompositeCommand(commandlist); DefineCommand command = new DefineCommand("foo", null, commands); Assert.AreEqual("foo", command.Name); Assert.AreEqual(commands, command.Command); }
public void Run_ThrowsExeption_InputStringIsIncorrect() { // Arrange string variable = "var"; string number = "55test"; CommandContext context = new CommandContext(); var define = new DefineCommand(variable, number, context); // Act void result() => define.Run(); // Assert Assert.Throws <CommandExecutionException>(result); }
public void Run_Passes_InputStringIsDouble() { // Arrange string variable = "var"; string number = "55.5"; CommandContext context = new CommandContext(); var define = new DefineCommand(variable, number, context); // Act define.Run(); var variableFromDefines = context.PairsList.SingleOrDefault(p => p.Id == "var"); // Assert Assert.IsType <MutableKeyValuePair <string, object> >(variableFromDefines); }
public void ExecuteDefineCommand() { Context context = new Context(); IList <ICommand> commandlist = new List <ICommand>(); commandlist.Add(new SetVariableCommand("a", new ConstantExpression(1))); commandlist.Add(new SetVariableCommand("b", new ConstantExpression(2))); commandlist.Add(new ExpressionCommand(new VariableExpression("b"))); CompositeCommand commands = new CompositeCommand(commandlist); DefineCommand command = new DefineCommand("foo", null, commands); object result = command.Execute(context); Assert.IsNull(result); Assert.IsInstanceOfType(context.GetValue("foo"), typeof(DefinedMethod)); }
public void ParseSimpleDefineCommand() { Parser parser = new Parser("def foo\r\na=1\r\nb=1\r\nend\r\n"); ICommand command = parser.ParseCommand(); Assert.IsNotNull(command); Assert.IsInstanceOfType(command, typeof(DefineCommand)); DefineCommand defcommand = (DefineCommand)command; Assert.AreEqual("foo", defcommand.Name); Assert.IsNotNull(defcommand.Command); Assert.IsInstanceOfType(defcommand.Command, typeof(CompositeCommand)); CompositeCommand commands = (CompositeCommand)defcommand.Command; Assert.IsNotNull(commands.Commands); Assert.AreEqual(2, commands.Commands.Count()); Assert.IsNull(parser.ParseCommand()); }