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)); }
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)); }
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>()); }
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); }
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>()); }
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>()); }
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(); }
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()); }
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)); }
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); }
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); }
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")); }
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)); }
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); }