예제 #1
0
        public static DatabaseController OpenSqLiteDriver(String @namespace = "") {
            var variables = new VariableController();

            var database = new DatabaseController() {
                Shared = {
                    Variables = variables
                }
            }.Execute() as DatabaseController;

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, VariableModel.NamespaceVariableName(@namespace, CommonVariableNames.DatabaseDriverName), "SQLite");

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, VariableModel.NamespaceVariableName(@namespace, CommonVariableNames.DatabaseMemory), true);

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.DatabaseConfigGroups, new List<String>() {
                @namespace
            });

            return database;
        }
예제 #2
0
        public void TestPackageGroupSetupLinear() {
            var variables = new VariableController();

            var @namespace = "";

            var packages = new PackagesController() {
                Shared = {
                    Variables = variables
                }
            }.Execute() as PackagesController;

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, VariableModel.NamespaceVariableName(@namespace, CommonVariableNames.PackagesRepositoryUri), "path-to-repository");

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.PackagesConfigGroups, new List<String>() {
                @namespace
            });

            Assert.IsNotEmpty(packages.Cache.Repositories);
            Assert.AreEqual("path-to-repository", packages.Cache.Repositories.FirstOrDefault().Uri);
        }
예제 #3
0
        /// <summary>
        /// Opens a database driver to a SQLite in-memory database
        /// </summary>
        /// <returns>this</returns>
        public static DatabaseController OpenDatabaseDriver() {
            VariableController variables = new VariableController();

            DatabaseController database = new DatabaseController() {
                Shared = {
                    Variables = variables
                }
            }.Execute() as DatabaseController;
            
            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.DatabaseDriverName, "SQLite");

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.DatabaseMemory, true);
            
            return database;
        }
예제 #4
0
        /// <summary>
        ///     Tests that setting the variables in a random order will still setup the push end points correctly.
        /// </summary>
        /// <param name="seed">A random number shouldn't be passed in, otherwise you won't be able to duplicate the results.</param>
        protected void TestEventsPushControllerMultipleEndPointsRandomVariableAssignment(int seed) {
            String pushConfigGroupNameOne = StringExtensions.RandomString(10);
            String pushConfigGroupNameTwo = StringExtensions.RandomString(10);

            var variables = new VariableController();

            var events = new EventsController();

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

            var groupVariables = new Dictionary<String, Object>() {
                {CommonVariableNames.EventsPushConfigGroups.ToString(), new List<String>() {
                    pushConfigGroupNameOne,
                    pushConfigGroupNameTwo
                }},
                {VariableModel.NamespaceVariableName(String.Empty, CommonVariableNames.EventsPushUri), "http://localhost/blank.php"},
                {VariableModel.NamespaceVariableName(String.Empty, CommonVariableNames.EventPushIntervalSeconds), 10},
                {VariableModel.NamespaceVariableName(pushConfigGroupNameOne, CommonVariableNames.EventsPushUri), "http://localhost/one.php"},
                {VariableModel.NamespaceVariableName(pushConfigGroupNameOne, CommonVariableNames.EventPushIntervalSeconds), 20},
                {VariableModel.NamespaceVariableName(pushConfigGroupNameTwo, CommonVariableNames.EventsPushUri), "http://localhost/two.php"},
                {VariableModel.NamespaceVariableName(pushConfigGroupNameTwo, CommonVariableNames.EventPushIntervalSeconds), 30}
            };

            var rand = new Random(seed);

            foreach (String groupVariableKey in groupVariables.Keys.OrderBy(key => rand.Next()).ToList()) {
                variables.Set(new Command() {
                    Origin = CommandOrigin.Local,
                    CommandType = CommandType.VariablesSet
                }, groupVariableKey, groupVariables[groupVariableKey]);
            }

            Assert.IsTrue(pushEvents.EndPoints.ContainsKey(String.Empty));
            Assert.AreEqual("http://localhost/blank.php", pushEvents.EndPoints[String.Empty].Uri.ToString());
            Assert.AreEqual(10, pushEvents.EndPoints[String.Empty].Interval);

            Assert.IsTrue(pushEvents.EndPoints.ContainsKey(pushConfigGroupNameOne));
            Assert.AreEqual("http://localhost/one.php", pushEvents.EndPoints[pushConfigGroupNameOne].Uri.ToString());
            Assert.AreEqual(20, pushEvents.EndPoints[pushConfigGroupNameOne].Interval);

            Assert.IsTrue(pushEvents.EndPoints.ContainsKey(pushConfigGroupNameTwo));
            Assert.AreEqual("http://localhost/two.php", pushEvents.EndPoints[pushConfigGroupNameTwo].Uri.ToString());
            Assert.AreEqual(30, pushEvents.EndPoints[pushConfigGroupNameTwo].Interval);
        }
예제 #5
0
        public void TestPotatoAddConnectionExceedMaximumConnectionLimit() {
            var variables = new VariableController();
            var instance = (PotatoController)new PotatoController() {
                Shared = {
                    Variables = variables
                }
            }.Execute();

            // Lower the maximum connections to nothing
            variables.Set(new Command() {
                Origin = CommandOrigin.Local
            }, CommonVariableNames.MaximumProtocolConnections, 0);

            ICommandResult result = instance.Tunnel(CommandBuilder.PotatoAddConnection("Myrcon", "MockProtocol", "1.1.1.1", 27516, "password", "").SetOrigin(CommandOrigin.Local));

            Assert.IsFalse(result.Success);
            Assert.AreEqual(CommandResultType.LimitExceeded, result.CommandResultType);
            Assert.AreEqual(0, instance.Connections.Count);

            instance.Dispose();
        }
예제 #6
0
        public void TestEventsPushControllerDispose() {
            var variables = new VariableController();

            var events = new EventsController();

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

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.EventsPushUri, "http://localhost/pushme.php");

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.EventPushIntervalSeconds, 10);

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.EventPushInclusiveNames, new List<String>() { "EventName" });

            // Validate the end point has been added.
            Assert.IsTrue(pushEvents.EndPoints.ContainsKey(String.Empty));
            Assert.AreEqual("http://localhost/pushme.php", pushEvents.EndPoints[String.Empty].Uri.ToString());
            Assert.AreEqual(10, pushEvents.EndPoints[String.Empty].Interval);

            events.Log(new GenericEvent() {
                Name = "EventName",
                Message = "Yo."
            });

            Assert.AreEqual(1, pushEvents.EndPoints[String.Empty].EventsStream.Count);

            pushEvents.Dispose();

            Assert.IsNull(pushEvents.EndPoints);
            Assert.IsNull(pushEvents.Tasks);
        }
예제 #7
0
        public void TestEventsPushControllerSingleEndPointNoNamespace() {
            var variables = new VariableController();

            var events = new EventsController();

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

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.EventsPushUri, "http://localhost/pushme.php");

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.EventPushIntervalSeconds, 20);

            Assert.IsTrue(pushEvents.EndPoints.ContainsKey(String.Empty));
            Assert.AreEqual("http://localhost/pushme.php", pushEvents.EndPoints[String.Empty].Uri.ToString());
            Assert.AreEqual(20, pushEvents.EndPoints[String.Empty].Interval);
        }
예제 #8
0
        public void TestEventsPushControllerNamespacedSingleEndPointForwardSetting() {
            String pushConfigGroupName = StringExtensions.RandomString(10);

            var variables = new VariableController();

            var events = new EventsController();

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

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, VariableModel.NamespaceVariableName(pushConfigGroupName, CommonVariableNames.EventsPushUri), "http://localhost/pushme.php");

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, VariableModel.NamespaceVariableName(pushConfigGroupName, CommonVariableNames.EventPushIntervalSeconds), 20);

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.EventsPushConfigGroups, new List<String>() {
                pushConfigGroupName
            });

            Assert.IsTrue(pushEvents.EndPoints.ContainsKey(pushConfigGroupName));
            Assert.AreEqual("http://localhost/pushme.php", pushEvents.EndPoints[pushConfigGroupName].Uri.ToString());
            Assert.AreEqual(20, pushEvents.EndPoints[pushConfigGroupName].Interval);
        }
예제 #9
0
        public void TestEventsPushControllerIntervalTickedEventsPushed() {
            var requestWait = new AutoResetEvent(false);
            var variables = new VariableController();

            var events = new EventsController();

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

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.EventsPushUri, "http://localhost/pushme.php");

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.EventPushIntervalSeconds, 1);

            variables.Set(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet
            }, CommonVariableNames.EventPushInclusiveNames, new List<String>() { "EventName" });

            // Validate the end point has been added.
            Assert.IsTrue(pushEvents.EndPoints.ContainsKey(String.Empty));
            Assert.AreEqual("http://localhost/pushme.php", pushEvents.EndPoints[String.Empty].Uri.ToString());
            Assert.AreEqual(1, pushEvents.EndPoints[String.Empty].Interval);

            events.Log(new GenericEvent() {
                Name = "EventName",
                Message = "Yo."
            });

            pushEvents.EndPoints[String.Empty].PushCompleted += sender => requestWait.Set();

            Assert.IsTrue(requestWait.WaitOne(5000));
            Assert.AreEqual(0, pushEvents.EndPoints[String.Empty].EventsStream.Count);
        }