Exemplo n.º 1
0
        public void ItRemembersValues()
        {
            var env = new EnvStore();

            Assert.IsNull(env["FOO"]);

            env["FOO"] = "bar";

            Assert.AreEqual("bar", env["FOO"]);
        }
Exemplo n.º 2
0
        public void BooleanValuesCanBeSet()
        {
            var env = new EnvStore();

            env.Set("FOO", true);
            env.Set("BAR", false);

            Assert.AreEqual("true", env["FOO"]);
            Assert.AreEqual("false", env["BAR"]);
        }
Exemplo n.º 3
0
        public void ItLoadsIntegers()
        {
            string source = @"
                BAZ=42
                BAR=059
                FOO=asd
            ";

            var env = EnvStore.Parse(source);

            Assert.AreEqual(42, env.GetInt("BAZ"));
            Assert.AreEqual(59, env.GetInt("BAR"));
            Assert.AreEqual(-1, env.GetInt("FOO", -1));
        }
Exemplo n.º 4
0
        private void DownloadEnvFile(EnvStore env)
        {
            // TODO: the .env file will be downloaded from the cloud

            // TODO: cache the env file between individual test runs
            // (download only once per the test suite execution
            // - use SetUpFixture, or OneTimeSetup)
            // cache only the downloaded string, but reset env for each test

            env["SESSION_DRIVER"]  = "arango";
            env["ARANGO_DRIVER"]   = "http";
            env["ARANGO_BASE_URL"] = "http://arango.unisave.local/";
            env["ARANGO_DATABASE"] = "db_Jj0Y3Fu6";
            env["ARANGO_USERNAME"] = "******";
            env["ARANGO_PASSWORD"] = "******";
        }
Exemplo n.º 5
0
        public void ItParsesText()
        {
            string source = @"
                FOO=bar
                BAZ=42
                APP = lorem ipsum
                # comment = nope
                HASH = # asd
            ";

            var env = EnvStore.Parse(source);

            Assert.AreEqual("bar", env["FOO"]);
            Assert.AreEqual("42", env["BAZ"]);
            Assert.AreEqual("lorem ipsum", env["APP"]);
            Assert.AreEqual(null, env["# comment"]);
            Assert.AreEqual("# asd", env["HASH"]);
        }
Exemplo n.º 6
0
        public void BooleanValuesCanBeRead()
        {
            var env = new EnvStore();

            env["TRUE_1"] = "true";
            env["TRUE_2"] = "True";
            env["TRUE_3"] = "TRUE";
            env["TRUE_4"] = "  TRue  ";
            env["TRUE_5"] = "1";
            env["TRUE_6"] = "  1 ";

            env["FALSE_1"] = "false";
            env["FALSE_2"] = "False";
            env["FALSE_3"] = "FALSE";
            env["FALSE_4"] = "  FALse  ";
            env["FALSE_5"] = "0";
            env["FALSE_6"] = "  0  ";

            env["MALFORMED_FALSE_1"] = "lorem ipsum";
            env["MALFORMED_FALSE_2"] = "123";
            env["MALFORMED_FALSE_3"] = "";
            env["MALFORMED_FALSE_4"] = "null";

            Assert.IsTrue(env.GetBool("TRUE_1"));
            Assert.IsTrue(env.GetBool("TRUE_2"));
            Assert.IsTrue(env.GetBool("TRUE_3"));
            Assert.IsTrue(env.GetBool("TRUE_4"));
            Assert.IsTrue(env.GetBool("TRUE_5"));
            Assert.IsTrue(env.GetBool("TRUE_6"));

            Assert.IsFalse(env.GetBool("FALSE_1"));
            Assert.IsFalse(env.GetBool("FALSE_2"));
            Assert.IsFalse(env.GetBool("FALSE_3"));
            Assert.IsFalse(env.GetBool("FALSE_4"));
            Assert.IsFalse(env.GetBool("FALSE_5"));
            Assert.IsFalse(env.GetBool("FALSE_6"));

            Assert.IsFalse(env.GetBool("MALFORMED_FALSE_1"));
            Assert.IsFalse(env.GetBool("MALFORMED_FALSE_2"));
            Assert.IsFalse(env.GetBool("MALFORMED_FALSE_3"));
            Assert.IsFalse(env.GetBool("MALFORMED_FALSE_4"));
        }
Exemplo n.º 7
0
        public virtual void SetUp()
        {
            // create testing client application
            ClientApp = new ClientApplication(
                UnisavePreferences.LoadOrCreate()
                );

            // prepare environment
            var env = new EnvStore();

            DownloadEnvFile(env);

            // create testing backend application
            App = Bootstrap.Boot(
                GetGameAssemblyTypes(),
                env,
                new SpecialValues()
                );

            // execute backend code locally
            ClientApp.Singleton <FacetCaller>(
                _ => new TestingFacetCaller(App, ClientApp)
                );

            // logging should go direct, we don't want to wait for app disposal
            // for writing logs to special values
            // HACK: this is a hack, see the ClientSideLog class for more
            App.Singleton <ILog>(_ => new ClientSideLog());

            // bind facades
            Facade.SetApplication(App);
            ClientFacade.SetApplication(ClientApp);

            // start with a blank slate
            ClientApp.Resolve <ClientSessionIdRepository>().StoreSessionId(null);
            ClearDatabase();
        }
Exemplo n.º 8
0
        public void BasicOperationsWork()
        {
            var env = new EnvStore();

            env["FOO"] = "bar";
            env["BAZ"] = "42";

            Assert.AreEqual("bar", env.GetString("FOO"));
            Assert.AreEqual(42, env.GetInt("BAZ"));
            Assert.AreEqual("42", env.GetString("BAZ"));

            Assert.AreEqual("nope", env.GetString("NOPE", "nope"));
            Assert.AreEqual(null, env.GetString("NOPE"));

            Assert.AreEqual(0, env.GetInt("NOPE"));
            Assert.AreEqual(66, env.GetInt("NOPE", 66));

            Assert.IsTrue(env.Has("FOO"));
            Assert.IsTrue(env.Has("BAZ"));

            Assert.IsFalse(env.Has("NOPE"));
            Assert.IsFalse(env.Has("foo"));
            Assert.IsFalse(env.Has("baz"));
        }
Exemplo n.º 9
0
 public void ItParsesNull()
 {
     Assert.DoesNotThrow(() => {
         EnvStore.Parse(null);
     });
 }
Exemplo n.º 10
0
        /// <summary>
        /// Main entrypoint to the framework execution
        /// Given executionParameters it starts some action which results.
        /// in a returned value or an exception.
        ///
        /// Input and output are serialized as JSON strings.
        /// </summary>
        public static string Start(
            string executionParametersAsJson,
            Type[] gameAssemblyTypes
            )
        {
            if (someExecutionIsRunning)
            {
                throw new InvalidOperationException(
                          "You cannot start the framework from within the framework."
                          );
            }

            someExecutionIsRunning = true;

            var executionStopwatch = Stopwatch.StartNew();

            try
            {
                PrintGreeting();

                var executionParameters = ExecutionParameters
                                          .Parse(executionParametersAsJson);

                var specialValues = new SpecialValues();

                JsonObject result = HandleExceptionSerialization(
                    specialValues,
                    () => {
                    // NOTE: this place is where a test/emulation
                    // is started. Simply boot the application and
                    // then directly call proper kernel (method handler).

                    var env = EnvStore.Parse(executionParameters.EnvSource);

                    JsonValue methodResult;

                    using (var app = Bootstrap.Boot(
                               gameAssemblyTypes,
                               env,
                               specialValues
                               ))
                    {
                        Facade.SetApplication(app);

                        methodResult = ExecuteProperMethod(
                            executionParameters,
                            app
                            );

                        Facade.SetApplication(null);
                    }

                    return(new JsonObject()
                           .Add("result", "ok")
                           .Add("returned", methodResult)
                           .Add("special", specialValues.ToJsonObject()));
                }
                    );

                executionStopwatch.Stop();
                result["special"].AsJsonObject["executionDuration"]
                    = executionStopwatch.ElapsedMilliseconds / 1000.0;

                return(result.ToString());
            }
            finally
            {
                someExecutionIsRunning = false;
            }
        }