Пример #1
0
        public void TestDispose() {
            var variables = new VariableController();

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

            variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSetA,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "ArchiveKey",
                    "value"
                })
            });

            VariableModel volatileVariable = variables.VolatileVariables.Values.First();

            variables.Dispose();

            // Test that all the lists and data within each item has been nulled.
            Assert.IsNull(variables.VolatileVariables);

            Assert.IsNull(volatileVariable.Name);
            Assert.IsNull(volatileVariable.Value);
        }
Пример #2
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));
        }
Пример #3
0
        public void TestEmptyKeyValue() {
            var variables = new VariableController();

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

            // Validate that the command failed
            Assert.IsFalse(result.Success);
            Assert.AreEqual(CommandResultType.InvalidParameter, result.CommandResultType);
        }
Пример #4
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>());
        }
Пример #5
0
        public void TestInsufficientPermission() {
            var variables = new VariableController();

            ICommandResult result = variables.Tunnel(CommandBuilder.VariablesSetF("key", "value").SetAuthentication(new CommandAuthenticationModel() {
                Username = "******"
            }).SetOrigin(CommandOrigin.Remote));

            // Validate the command failed because we don't have permissions to execute it.
            Assert.IsFalse(result.Success);
            Assert.AreEqual(CommandResultType.InsufficientPermissions, result.CommandResultType);
        }
Пример #6
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>());
        }
Пример #7
0
        public void TestEmptyKeyValue() {
            var variables = new VariableController();

            // 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>() {
                    String.Empty,
                    "value"
                })
            });

            // Validate that the command failed (can't have an empty key)
            Assert.IsFalse(result.Success);
            Assert.AreEqual(CommandResultType.InvalidParameter, result.CommandResultType);
            Assert.AreEqual(0, variables.VolatileVariables.Count);
        }
Пример #8
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));
        }
Пример #9
0
        public void TestValue() {
            var variables = new VariableController();

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

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

            Assert.IsTrue(result.Success);
            Assert.AreEqual(CommandResultType.Success, result.CommandResultType);
            Assert.AreEqual("value", result.Now.Variables.First().ToType(String.Empty));
        }
Пример #10
0
        public void TestRemovesArchiveVariable() {
            var variables = new VariableController();

            // Set a archive variable.
            variables.Tunnel(CommandBuilder.VariablesSetA("key", "value").SetOrigin(CommandOrigin.Local));

            // Set a flash value
            variables.Tunnel(CommandBuilder.VariablesSetF("key", "value").SetOrigin(CommandOrigin.Local));

            // Validate archive value exists and flash value does not.
            Assert.IsEmpty(variables.ArchiveVariables);
            Assert.IsNotEmpty(variables.FlashVariables);
        }
Пример #11
0
        public void TestVariablesSetPriorToPushEventsControllerExecution() {
            String pushConfigGroupName = StringExtensions.RandomString(10);

            var variables = new VariableController();
            variables.Tunnel(CommandBuilder.VariablesSet(VariableModel.NamespaceVariableName(pushConfigGroupName, CommonVariableNames.EventsPushUri), "http://localhost/pushme.php").SetOrigin(CommandOrigin.Local));
            variables.Tunnel(CommandBuilder.VariablesSet(VariableModel.NamespaceVariableName(pushConfigGroupName, CommonVariableNames.EventPushIntervalSeconds), "20").SetOrigin(CommandOrigin.Local));
            variables.Tunnel(CommandBuilder.VariablesSet(CommonVariableNames.EventsPushConfigGroups, pushConfigGroupName).SetOrigin(CommandOrigin.Local));

            var events = new EventsController();

            var pushEvents = (PushEventsController)new PushEventsController() {
                Shared = {
                    Variables = variables,
                    Events = events
                }
            }.Execute();

            Assert.IsTrue(pushEvents.EndPoints.ContainsKey(pushConfigGroupName));
            Assert.AreEqual("http://localhost/pushme.php", pushEvents.EndPoints[pushConfigGroupName].Uri.ToString());
            Assert.AreEqual(20, pushEvents.EndPoints[pushConfigGroupName].Interval);
        }
Пример #12
0
        public void TestInsufficientPermission() {
            var variables = new VariableController() {
                Shared = {
                    Security = new SecurityController().Execute() as SecurityController
                }
            };

            ICommandResult result = variables.Tunnel(new Command() {
                Authentication = {
                    Username = "******"
                },
                Origin = CommandOrigin.Remote,
                CommandType = CommandType.VariablesSet,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "key",
                    "value"
                })
            });

            Assert.IsFalse(result.Success);
            Assert.AreEqual(CommandResultType.InsufficientPermissions, result.CommandResultType);
        }
Пример #13
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());
        }
Пример #14
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));
        }
Пример #15
0
        public void TestValueCommonName() {
            var variables = new VariableController();

            variables.VolatileVariables.TryAdd(CommonVariableNames.MaximumProtocolConnections.ToString().ToLowerInvariant(), new VariableModel() {
                Name = CommonVariableNames.MaximumProtocolConnections.ToString(),
                Value = "value"
            });

            var value = variables.Tunnel(CommandBuilder.VariablesGet(CommonVariableNames.MaximumProtocolConnections).SetOrigin(CommandOrigin.Local)).Now.Variables.First().ToType<String>();

            Assert.AreEqual("value", value);
        }
Пример #16
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>());
        }
Пример #17
0
        public void TestValueEmptyKey() {
            var variables = new VariableController();

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

            ICommandResult result = variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesGet,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    String.Empty
                })
            });

            Assert.IsFalse(result.Success);
            Assert.AreEqual(CommandResultType.InvalidParameter, result.CommandResultType);
        }