public async void Script_With_Http_Reference_Is_Run()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings());

            await manager.ExecuteAsync(new List<IncludeScript> { new IncludeScript { Uri = "https://gist.githubusercontent.com/eswann/66796164c1904b6135ea/raw/5491642164a45ae34af2926137950de3249d1e91/gistfile1.txt", ScriptId = "testScript" } },
                new ExecutionOptions
                {
                    HostObjects = new List<HostObject> { new HostObject { Name = "subject", Target = subject } },
                });

            subject.Name.ShouldEqual("Name");
            subject.Count.ShouldEqual(10);
            subject.TestString.ShouldEqual("test string1");
        }
        public async void Script_With_Http_Include_Is_Included()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings());

            await manager.ExecuteAsync("testscript", "subject.Count = 10; subject.TestString = x;",
                new ExecutionOptions
                {
                    HostObjects = new List<HostObject> {new HostObject {Name = "subject", Target = subject}},
                    Scripts = new List<IncludeScript> { new IncludeScript { Uri = "https://gist.githubusercontent.com/eswann/3215f3afff3a602c0f3a/raw/a9ace53fca80fdcdefba60c4f7bf803bf5239905/gistfile1.txt", ScriptId = "testScript2" } }
                });

            subject.Name.ShouldEqual("Name");
            subject.Count.ShouldEqual(10);
            subject.TestString.ShouldEqual("test string1");
        }
        public async void Require_Named_With_Explicit_Name_Succeeds()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings { ScriptTimeoutMilliSeconds = 0 });

            await
                manager.ExecuteAsync("testscript",
                    @"var testObject = requireNamed('testRequire', 'https://gist.githubusercontent.com/eswann/3ff5ec2bcc63b7d2cdaa/raw/26e30f6a9761dbbe5634b2de1549c4a455b7a7d6/TestDiffNameRequire.js'); subject.Count = 10; subject.TestString = testObject.getText();",
                    new ExecutionOptions
                    {
                        HostObjects = new List<HostObject> { new HostObject { Name = "subject", Target = subject } },
                    });

            subject.Name.ShouldEqual("Name");
            subject.Count.ShouldEqual(10);
            subject.TestString.ShouldEqual("testText");
        }
        public async void Require_Specified_As_Script_HttpPath_Path_Is_Used()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings {ScriptTimeoutMilliSeconds = 0});

            await
                manager.ExecuteAsync("testscript",
                    @"var testObject = require('https://gist.githubusercontent.com/eswann/76ecaba02dee33cf26b4/raw/bcafe0a389c84ba44d6ee1661e66b2213aa2ffa0/testRequire'); subject.Count = 10; subject.TestString = testObject.getText();",
                    new ExecutionOptions
                    {
                        HostObjects = new List<HostObject> {new HostObject {Name = "subject", Target = subject}},
                    });

            subject.Name.ShouldEqual("Name");
            subject.Count.ShouldEqual(10);
            subject.TestString.ShouldEqual("testText");
        }
        public async void Multiple_Scripts_Types_Are_Run_First_To_Last()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings());

            await manager.ExecuteAsync(new List<IncludeScript>
                {
                    new IncludeScript {Uri = ".\\TestMainScript.js", ScriptId = "testScript"},
                    new IncludeScript {Code = "subject.TestString = 'test string3';", ScriptId = "testScript3"},
                    new IncludeScript {Uri = "https://gist.githubusercontent.com/eswann/62fc90e542f7697263db/raw/026c42ef0043a70a8c3b720e3026ecee9c691a06/gistfile1.txt", ScriptId = "TestScript4"}
                },
                new ExecutionOptions
                {
                    HostObjects = new List<HostObject> {new HostObject {Name = "subject", Target = subject}},
                });

            subject.Name.ShouldEqual("Name");
            subject.Count.ShouldEqual(20);
            subject.TestString.ShouldEqual("test string3");
        }
Beispiel #6
0
        public async void Require_Named_With_Explicit_Name_Succeeds()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings {
                ScriptTimeoutMilliSeconds = 0
            });

            await
            manager.ExecuteAsync("testscript",
                                 @"var testObject = requireNamed('testRequire', 'https://gist.githubusercontent.com/eswann/3ff5ec2bcc63b7d2cdaa/raw/26e30f6a9761dbbe5634b2de1549c4a455b7a7d6/TestDiffNameRequire.js'); subject.Count = 10; subject.TestString = testObject.getText();",
                                 new ExecutionOptions
            {
                HostObjects = new List <HostObject> {
                    new HostObject {
                        Name = "subject", Target = subject
                    }
                },
            });

            subject.Name.ShouldEqual("Name");
            subject.Count.ShouldEqual(10);
            subject.TestString.ShouldEqual("testText");
        }
        public async void Basic_Http_Get_Headers_Are_Retrieved()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings { ScriptTimeoutMilliSeconds = 0 });

            PackageHelpers.RegisterRequestPackages();

            manager.AddConsoleReference = true;
            var options = new ExecutionOptions();
            options.HostObjects.Add(new HostObject { Name = "subject", Target = subject });

            var scriptAwaiter = new ScriptAwaiter();
            options.HostObjects.Add(new HostObject { Name = "scriptAwaiter", Target = scriptAwaiter });

            var code = "var request = require('request');" +
                       "request({url: 'http://api.icndb.com/jokes/random/1', json: true}," +
                       " function (error, response, body) {subject.Response = response; subject.Headers = response.headers; scriptAwaiter.Callback();});";

            await manager.ExecuteAsync("testScript", code, options);
            await scriptAwaiter.T;

            subject.Headers.Count().ShouldBeGreaterThan(0);
        }
Beispiel #8
0
        public async void Require_Specified_As_Script_HttpPath_Path_Is_Used()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings {
                ScriptTimeoutMilliSeconds = 0
            });

            await
            manager.ExecuteAsync("testscript",
                                 @"var testObject = require('https://gist.githubusercontent.com/eswann/76ecaba02dee33cf26b4/raw/bcafe0a389c84ba44d6ee1661e66b2213aa2ffa0/testRequire'); subject.Count = 10; subject.TestString = testObject.getText();",
                                 new ExecutionOptions
            {
                HostObjects = new List <HostObject> {
                    new HostObject {
                        Name = "subject", Target = subject
                    }
                },
            });

            subject.Name.ShouldEqual("Name");
            subject.Count.ShouldEqual(10);
            subject.TestString.ShouldEqual("testText");
        }
Beispiel #9
0
        public async void TestLog1()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings {
                ScriptTimeoutMilliSeconds = 0
            });

            manager.AddConsoleReference = true;
            LogPackageHelpers.RegisterPackage(manager.RequireManager);

            var options = new ExecutionOptions();

            options.HostObjects.Add(new HostObject {
                Name = "subject", Target = subject
            });
            var code = "var logFactory = require('javascript_log_factory');" +
                       "subject.Name = '111';" +
                       "var log = this.logFactory.create({trace:true});" +
                       //"subject.StatusCode = content.ExecuteNonQuery(\"update school set address ='1' where id = 1\");";
                       "try{ aa.ttt =1}catch(err){log.info(err)}";

            await manager.ExecuteAsync("testScript", code, options);
        }
Beispiel #10
0
        public async void Script_With_Http_Reference_Is_Run()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings());

            await manager.ExecuteAsync(new List <IncludeScript> {
                new IncludeScript {
                    Uri = "https://gist.githubusercontent.com/eswann/66796164c1904b6135ea/raw/5491642164a45ae34af2926137950de3249d1e91/gistfile1.txt", ScriptId = "testScript"
                }
            },
                                       new ExecutionOptions
            {
                HostObjects = new List <HostObject> {
                    new HostObject {
                        Name = "subject", Target = subject
                    }
                },
            });

            subject.Name.ShouldEqual("Name");
            subject.Count.ShouldEqual(10);
            subject.TestString.ShouldEqual("test string1");
        }
Beispiel #11
0
        public async void Script_With_Http_Include_Is_Included()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings());

            await manager.ExecuteAsync("testscript", "subject.Count = 10; subject.TestString = x;",
                                       new ExecutionOptions
            {
                HostObjects = new List <HostObject> {
                    new HostObject {
                        Name = "subject", Target = subject
                    }
                },
                Scripts = new List <IncludeScript> {
                    new IncludeScript {
                        Uri = "https://gist.githubusercontent.com/eswann/3215f3afff3a602c0f3a/raw/a9ace53fca80fdcdefba60c4f7bf803bf5239905/gistfile1.txt", ScriptId = "testScript2"
                    }
                }
            });

            subject.Name.ShouldEqual("Name");
            subject.Count.ShouldEqual(10);
            subject.TestString.ShouldEqual("test string1");
        }
Beispiel #12
0
        public async void TestSql1()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings {
                ScriptTimeoutMilliSeconds = 0
            });

            SqlPackageHelpers.RegisterPackage(manager.RequireManager, new AntOrmDbExecutor());

            manager.AddConsoleReference = true;
            var options = new ExecutionOptions();

            options.HostObjects.Add(new HostObject {
                Name = "subject", Target = subject
            });
            var code = "var dbFactory = require('javascript_sql_factory');" +
                       "var content = this.dbFactory.create({name:'testorm',type:'mysql'});" +
                       //"subject.StatusCode = content.ExecuteNonQuery(\"update school set address ='1' where id = 1\");";
                       "var arr = content.insert(\"insert into school (name,address,datachange_lasttime) values (@name,@address,now())\",{name:'test111',address:'wowowo'});";

            await manager.ExecuteAsync("testScript", code, options);

            subject.StatusCode.ShouldEqual(0);
        }
        public async void TestSql1()
        {
            var subject = new TestObject();
            var manager = new RuntimeManager(new ManualManagerSettings {
                ScriptTimeoutMilliSeconds = 0
            });

            SqlPackageHelpers.RegisterPackage(manager.RequireManager, new AntOrmDbExecutor());

            manager.AddConsoleReference = true;
            var options = new ExecutionOptions();

            options.HostObjects.Add(new HostObject {
                Name = "subject", Target = subject
            });
            var code = "var dbFactory = require('javascript_sql_factory');" +
                       "var content = this.dbFactory.create('testorm','mysql');" +
                       //"subject.StatusCode = content.ExecuteNonQuery(\"update school set address ='1' where id = 1\");";
                       "var arr = content.query(\"SELECT  DataChange_LastTime FROM school LIMIT 1\");Console.WriteLine(arr.ToString('yyyy-MM-dd'))";

            await manager.ExecuteAsync("testScript", code, options);

            subject.StatusCode.ShouldEqual(0);
        }