Beispiel #1
0
        public void ExecuteSetCommandWithComplexDotExpression()
        {
            BindingEnvironment environment = new BindingEnvironment();
            DotExpression      dot         = new DotExpression(new VariableExpression("foo"), "Address");
            DotExpression      dotexpr     = new DotExpression(dot, "Street");
            SetCommand         command     = new SetCommand(dotexpr, new ConstantExpression("bar"));

            command.Execute(environment);

            object obj = environment.GetValue("foo");

            Assert.IsNotNull(obj);
            Assert.IsInstanceOfType(obj, typeof(DynamicObject));

            DynamicObject dynobj = (DynamicObject)obj;

            object obj2 = dynobj.GetValue("Address");

            Assert.IsNotNull(obj2);
            Assert.IsInstanceOfType(obj2, typeof(DynamicObject));

            DynamicObject dynobj2 = (DynamicObject)obj2;

            Assert.AreEqual("bar", dynobj2.GetValue("Street"));
        }
Beispiel #2
0
        public void When_prepending_item_on_cache_will_prepend_to_data_already_on_cache()
        {
            var      buffer  = new byte[] { 1, 2, 3, 4 };
            ICommand command = new SetCommand();

            command.SetContext(GetStreamWithData(buffer));
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            wait.Reset();

            buffer = new byte[] { 5, 6, 7, 8 };
            MemoryStream stream = GetStreamWithData(buffer);

            command = new PrependCommand();
            command.SetContext(stream);
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            var item = (CachedItem)Cache.Get("foo");

            CollectionAssert.AreEqual(new byte[] { 5, 6, 7, 8, 1, 2, 3, 4, }, item.Buffer);
        }
Beispiel #3
0
        public void When_prepending_item_on_cache_will_reply_with_stored()
        {
            var      buffer  = new byte[] { 1, 2, 3, 4 };
            ICommand command = new SetCommand();

            command.SetContext(GetStreamWithData(buffer));
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            wait.Reset();

            buffer = new byte[] { 5, 6, 7, 8 };
            MemoryStream stream = GetStreamWithData(buffer);

            command = new PrependCommand();
            command.SetContext(stream);
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            Assert.AreEqual("STORED\r\n", ReadAll(6, stream));
        }
Beispiel #4
0
        public void When_prepending_item_on_cache_will_not_modify_flags()
        {
            var      buffer  = new byte[] { 1, 2, 3, 4 };
            ICommand command = new SetCommand();

            command.SetContext(GetStreamWithData(buffer));
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            wait.Reset();

            buffer = new byte[] { 5, 6, 7, 8 };
            MemoryStream stream = GetStreamWithData(buffer);

            command = new PrependCommand();
            command.SetContext(stream);
            command.Init("foo", "15", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            var item = (CachedItem)Cache.Get("foo");

            Assert.AreEqual(1, item.Flags);
        }
Beispiel #5
0
        public void ExecuteSetCommand()
        {
            SetCommand command = new SetCommand("foo", new ConstantExpression("bar"));
            Machine    machine = new Machine();

            command.Execute(machine.Environment);

            Assert.AreEqual("bar", machine.Environment.GetValue("foo"));
        }
Beispiel #6
0
        public void ExecuteSetCommand()
        {
            BindingEnvironment environment = new BindingEnvironment();
            ICommand           command     = new SetCommand("one", new ConstantExpression(1));

            command.Execute(environment);

            Assert.AreEqual(1, environment.GetValue("one"));
        }
Beispiel #7
0
        public void ExecuteSetCommandWithVariable()
        {
            BindingEnvironment environment = new BindingEnvironment();
            SetCommand         command     = new SetCommand(new VariableExpression("foo"), new ConstantExpression("bar"));

            command.Execute(environment);

            Assert.AreEqual("bar", environment.GetValue("foo"));
        }
        public void ConfigSet_SetAll_Execute_ReturnsSuccess()
        {
            var console = new TestConsole(_output, "config value edited");
            var command = new SetCommand(_engineConfig.Object, console, (new Mock <ILogger <SetCommand> >()).Object);

            var message = command.Execute();

            Assert.Equal("config value edited", _configs["config1"]);
            Assert.Equal("Config values have been saved successfully.", message);
        }
Beispiel #9
0
        public void SetCommand()
        {
            Context context = new Context();

            Assert.IsNull(context.GetValue("foo"));
            SetCommand command = new SetCommand("foo", new ConstantExpression("bar"));

            command.Execute(context);
            Assert.AreEqual("bar", context.GetValue("foo"));
        }
Beispiel #10
0
        public void SetVariable()
        {
            IExpression        expression  = new ConstantExpression(1);
            BindingEnvironment environment = new BindingEnvironment();
            ICommand           command     = new SetCommand("spam", expression);

            command.Execute(environment);

            Assert.AreEqual(1, environment.GetValue("spam"));
        }
        private void SetItem()
        {
            var          buffer  = new byte[] { 1, 2, 3, 4 };
            MemoryStream stream  = GetStreamWithData(buffer);
            var          command = new SetCommand();

            command.SetContext(stream);
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();
        }
Beispiel #12
0
        public void ExecuteSetCommandWithObjectProperty()
        {
            Machine    machine   = new Machine();
            TextWriter outwriter = new StringWriter();

            machine.Environment.SetValue("machine", machine);
            machine.Environment.SetValue("out", outwriter);

            DotExpression dotexpr = new DotExpression(new VariableExpression("machine"), "Out");
            SetCommand    command = new SetCommand(dotexpr, new VariableExpression("out"));

            command.Execute(machine.Environment);

            Assert.AreEqual(machine.Out, outwriter);
        }
Beispiel #13
0
        public void When_adding_item_will_reply_that_it_was_stored()
        {
            var          buffer  = new byte[] { 1, 2, 3, 4 };
            MemoryStream stream  = GetStreamWithData(buffer);
            var          command = new SetCommand();

            command.SetContext(stream);
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            Assert.AreEqual("STORED\r\n", ReadAll(6, stream));
        }
        public void DebugContextRaisingSettingValueEvent()
        {
            IContext     context = new Context();
            DebugContext debug   = new DebugContext(context);

            string varname  = null;
            object varvalue = null;

            debug.SettingValue += (name, value) => { varname = name; varvalue = value; };

            ICommand command = new SetCommand("foo", new ConstantExpression("bar"));

            command.Execute(debug);

            Assert.AreEqual("foo", varname);
            Assert.AreEqual("bar", varvalue);
        }
Beispiel #15
0
        public void When_item_end_in_just_LF_will_send_error()
        {
            var buffer = new byte[] { 1, 2, 3, 4, 10 };
            var stream = new MemoryStream();

            stream.Write(buffer, 0, 5);
            stream.Position = 0;
            var command = new SetCommand();

            command.SetContext(stream);
            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            Assert.AreEqual("CLIENT_ERROR Data section should end with a line break (\\r\\n)\r\n", ReadAll(5, stream));
        }
Beispiel #16
0
        public void When_setting_item_will_put_it_in_cache()
        {
            var buffer  = new byte[] { 1, 2, 3, 4 };
            var command = new SetCommand();

            command.SetContext(GetStreamWithData(buffer));

            command.Init("foo", "1", "6000", "4");

            command.FinishedExecuting += () => { wait.Set(); };
            command.Execute();
            wait.WaitOne();

            var cachedItem = (CachedItem)Cache.Get("foo");

            Assert.IsNotNull(cachedItem);
            CollectionAssert.AreEqual(buffer, cachedItem.Buffer);
            Assert.AreEqual(1, cachedItem.Flags);
        }
        public void ConfigSet_Execute_ReturnsSuccess(string configName, string configValue)
        {
            var console = new TestConsole(_output);
            var command = new SetCommand(_engineConfig.Object, console, (new Mock <ILogger <SetCommand> >()).Object)
            {
                ConfigName  = configName,
                ConfigValue = configValue
            };

            var message = command.Execute();

            if (!string.IsNullOrEmpty(configName) && !string.IsNullOrEmpty(configValue))
            {
                Assert.Equal(configValue, _configs[configName]);
                Assert.Equal($"The value of \"{configName}\" has been set to \"{configValue}\".", message);
            }
            else
            {
                Assert.Equal("", message);
            }
        }
Beispiel #18
0
        public static void GetVariables(IDictionary <string, string> vars, string commandsText)
        {
            IEnumerable <string> commands = GetCommands(commandsText);

            string[] args;
            string   name;
            var      setCommand = new SetCommand();

            foreach (string command in commands)
            {
                ParseCommand(command, out args, out name);
                if (name == setCommand.Name)
                {
                    ICommandResult result = setCommand.Execute(vars, args);
                    if (!result.Success)
                    {
                        throw new PatchCommandException(string.Format("Error while retrieving patch info.\nSet command args: {1}\nError text: {2}",
                                                                      string.Join(", ", args), result.ErrorText));
                    }
                }
            }
        }