Beispiel #1
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));
        }
Beispiel #2
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"]);
        }
Beispiel #3
0
 public void ItParsesNull()
 {
     Assert.DoesNotThrow(() => {
         EnvStore.Parse(null);
     });
 }
Beispiel #4
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;
            }
        }