Ejemplo n.º 1
0
        public void TestValue() {
            var variables = new VariableController();

            ICommandResult result = variables.Tunnel(CommandBuilder.VariablesSet("key", "value").SetOrigin(CommandOrigin.Local));

            Assert.IsTrue(result.Success);
            Assert.AreEqual(CommandResultType.Success, result.CommandResultType);
            Assert.AreEqual("value", variables.Get("key", String.Empty));
        }
Ejemplo n.º 2
0
        public void TestCaseInsensitive() {
            var variables = new VariableController();

            ICommandResult result = variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "key",
                    "TestVariablesSetValueCaseInsensitive"
                })
            });

            Assert.IsTrue(result.Success);
            Assert.AreEqual(CommandResultType.Success, result.CommandResultType);
            Assert.AreEqual("TestVariablesSetValueCaseInsensitive", variables.Get("Key", String.Empty));
            Assert.AreEqual("TestVariablesSetValueCaseInsensitive", variables.Get("KEY", String.Empty));
            Assert.AreEqual("TestVariablesSetValueCaseInsensitive", variables.Get("keY", String.Empty));
            Assert.AreEqual("TestVariablesSetValueCaseInsensitive", variables.Get("Key", String.Empty));
        }
Ejemplo n.º 3
0
        public void TestValue() {
            var variables = new VariableController();

            // Set an archive variable
            ICommandResult result = variables.Tunnel(CommandBuilder.VariablesSetF("key", "value").SetOrigin(CommandOrigin.Local));

            // Validate that the command was successful and the key was set to the passed value.
            Assert.IsTrue(result.Success);
            Assert.AreEqual(CommandResultType.Success, result.CommandResultType);
            Assert.AreEqual("value", variables.Get("key", String.Empty));
            Assert.AreEqual("value", variables.FlashVariables.Values.First(v => v.Name == "key").ToType<String>());
        }
Ejemplo n.º 4
0
        public void TestParseMixedMultiple() {
            var variables = new VariableController();
            variables.ParseArguments(@"-key1 ""value1"" -key2 -key3 2".Wordify());

            VariableModel variableOne = variables.Get(new Command() {
                Origin = CommandOrigin.Local
            }, "key1").Now.Variables.First();
            VariableModel variableTwo = variables.Get(new Command() {
                Origin = CommandOrigin.Local
            }, "key2").Now.Variables.First();
            VariableModel variableThree = variables.Get(new Command() {
                Origin = CommandOrigin.Local
            }, "key3").Now.Variables.First();

            Assert.AreEqual("value1", variableOne.ToType(String.Empty));
            Assert.IsTrue(variableOne.Readonly);

            Assert.AreEqual(true, variableTwo.ToType(false));
            Assert.IsTrue(variableTwo.Readonly);

            Assert.AreEqual(2, variableThree.ToType(0));
            Assert.IsTrue(variableThree.Readonly);
        }
Ejemplo n.º 5
0
        public void TestOverrideExisting() {
            var variables = new VariableController();

            // Set an archive variable
            ICommandResult result = variables.Tunnel(CommandBuilder.VariablesSetF("key", "value").SetOrigin(CommandOrigin.Local));

            // Validate that initially setting the VariableModel is successful.
            Assert.IsTrue(result.Success);
            Assert.AreEqual(CommandResultType.Success, result.CommandResultType);
            Assert.AreEqual("value", variables.Get("key", String.Empty));
            Assert.AreEqual("value", variables.FlashVariables.Values.First(v => v.Name == "key").ToType<String>());

            result = variables.Tunnel(CommandBuilder.VariablesSetF("key", "changed value").SetOrigin(CommandOrigin.Local));

            // Validate that we changed changed an existing VariableModel value.
            Assert.IsTrue(result.Success);
            Assert.AreEqual(CommandResultType.Success, result.CommandResultType);
            Assert.AreEqual("changed value", variables.Get("key", String.Empty));
            Assert.AreEqual("changed value", variables.FlashVariables.Values.First(v => v.Name == "key").ToType<String>());
        }
Ejemplo n.º 6
0
        public void TestCommonNameValue() {
            var variables = new VariableController();

            // Set an archive variable
            variables.Tunnel(CommandBuilder.VariablesSetF(CommonVariableNames.MaximumProtocolConnections, "value").SetOrigin(CommandOrigin.Local));

            // Validate that the command was successful and the key was set to the passed value.
            Assert.AreEqual("value", variables.Get(CommonVariableNames.MaximumProtocolConnections, String.Empty));
            Assert.AreEqual("value", variables.FlashVariables.Values.First(v => v.Name == CommonVariableNames.MaximumProtocolConnections.ToString()).ToType<String>());
        }
Ejemplo n.º 7
0
        public void TestPotatoCommandScopeNoScope() {
            var variables = new VariableController();

            var instance = (PotatoController)new PotatoController() {
                Shared = {
                    Variables = variables,
                    Security = new SecurityController(),
                    Events = new EventsController(),
                    Languages = new LanguageController()
                }
            }.Execute();

            ((ProtocolController)instance.Protocols).Protocols.Add(new ProtocolAssemblyMetadata() {
                Directory = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory),
                Assembly = new FileInfo("MockProtocol.dll"),
                ProtocolTypes = new List<IProtocolType>() {
                    new ProtocolType() {
                        Name = "Mock Protocol",
                        Provider = "Myrcon",
                        Type = "MockProtocol"
                    }
                }
            });

            instance.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.PotatoAddConnection,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "Myrcon",
                    "MockProtocol",
                    "1.1.1.1",
                    27516,
                    "password",
                    ""
                })
            });

            // Tests that there is at least one connection.
            Assert.AreEqual(1, instance.Connections.Count);

            ICommandResult result = instance.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "key",
                    "value"
                })
            });

            Assert.IsTrue(result.Success);
            Assert.AreEqual(CommandResultType.Success, result.CommandResultType);
            Assert.AreEqual("value", variables.Get("key", "default value"));

            instance.Dispose();
        }
Ejemplo n.º 8
0
        public void TestValueStringList() {
            var variables = new VariableController();

            // Set the value of a empty key
            ICommandResult result = variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet,
                Parameters = new List<ICommandParameter>() {
                    new CommandParameter() {
                        Data = {
                            Content = new List<String>() {
                                "key"
                            }
                        }
                    },
                    new CommandParameter() {
                        Data = {
                            Content = new List<String>() {
                                "value1",
                                "value2"
                            }
                        }
                    }
                }
            });

            Assert.IsTrue(result.Success);
            Assert.AreEqual(CommandResultType.Success, result.CommandResultType);
            Assert.IsNotNull(variables.Get<List<String>>("key"));
            Assert.AreEqual("value1", variables.Get<List<String>>("key").First());
            Assert.AreEqual("value2", variables.Get<List<String>>("key").Last());
        }
Ejemplo n.º 9
0
        public void TestReadOnly() {
            var variables = new VariableController();

            variables.VolatileVariables.TryAdd("key", new VariableModel() {
                Name = "key",
                Value = "value",
                Readonly = true
            });

            // Set the value of a empty key
            ICommandResult result = variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "key",
                    "modified value"
                })
            });

            // Validate that the command failed (can't have an empty key)
            Assert.IsFalse(result.Success);
            Assert.AreEqual(CommandResultType.Failed, result.CommandResultType);
            Assert.AreEqual("value", variables.Get("key", String.Empty));
        }
Ejemplo n.º 10
0
        public void TestParseSingleFlag() {
            var variables = new VariableController();
            variables.ParseArguments(@"-key".Wordify());

            VariableModel variableModel = variables.Get(new Command() {
                Origin = CommandOrigin.Local
            }, "key").Now.Variables.First();

            Assert.IsTrue(variableModel.ToType(false));
            Assert.IsTrue(variableModel.Readonly);
        }
Ejemplo n.º 11
0
        public void TestParseSingle() {
            var variables = new VariableController();
            variables.ParseArguments(@"-key ""value""".Wordify());

            VariableModel variableModel = variables.Get(new Command() {
                Origin = CommandOrigin.Local
            }, "key").Now.Variables.First();

            Assert.AreEqual("value", variableModel.ToType(String.Empty));
            Assert.IsTrue(variableModel.Readonly);
        }
Ejemplo n.º 12
0
        public void TesValueValidTypeCast() {
            var variables = new VariableController();

            variables.VolatileVariables.TryAdd("key", new VariableModel() {
                Name = "key",
                Value = new VariableModel() {
                    Name = "key",
                    Value = "10"
                }
            });

            Assert.AreEqual(10, variables.Get<int>("key"));
        }
Ejemplo n.º 13
0
        public void TestInvalidTypeCastWithDefault() {
            var variables = new VariableController();

            variables.VolatileVariables.TryAdd("key", new VariableModel() {
                Name = "key",
                Value = new VariableModel() {
                    Name = "key",
                    Value = "10!"
                }
            });

            Assert.AreEqual(10, variables.Get("key", 10));
        }
Ejemplo n.º 14
0
        public void TestValueComplexValue() {
            var variables = new VariableController();

            variables.VolatileVariables.TryAdd("key", new VariableModel() {
                Name = "key",
                Value = new VariableComplexValue() {
                    PropertyOne = 1,
                    PropertyTwo = "two"
                }
            });

            VariableComplexValue value = variables.Get(new Command() {
                Origin = CommandOrigin.Local
            }, "key").Now.Variables.First().ToType<VariableComplexValue>();

            Assert.AreEqual(1, value.PropertyOne);
            Assert.AreEqual("two", value.PropertyTwo);
        }