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

            await manager.ExecuteAsync(new List<IncludeScript> { new IncludeScript { Code = "subject.Count = 10; subject.TestString = 'test string1';", 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_File_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 = ".\\TestIncludeScript.js", ScriptId = "testScript2"}}
                });

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

            var engine = 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 = ".\\TestIncludeScript.js", ScriptId = "testScript2" } }
                });

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

            RequireManager.RegisterPackage(new RequiredPackage { PackageId = "testRequire", ScriptUri = ".\\TestRequire.js" });

            await manager.ExecuteAsync("testscript",
                    "var testObject = require('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 ExecutionOptions
                {
                    HostObjects = new List<HostObject> {new HostObject {Name = "subject", Target = subject}},
                });

            subject.Name.ShouldEqual("Name");
            subject.Count.ShouldEqual(10);
            subject.TestString.ShouldEqual("test string3");
        }
        public async void Script_Referencing_Specific_Type_Executes()
        {

            var manager = new RuntimeManager(new ManualManagerSettings());

            var hostType = new HostType
            {
                Name = "MathStuff",
                Type = typeof(System.Math)
            };

            var subject = new TestObject();

            await manager.ExecuteAsync("test", "subject.Result = MathStuff.Pow(10,2);", 
                new List<HostObject> { new HostObject { Name = "subject", Target = subject } }, 
                new List<HostType> { hostType });

            subject.Result.ShouldEqual(100);

        }
Exemple #7
0
        public async void Script_Referencing_Specific_Type_Executes()
        {
            var manager = new RuntimeManager(new ManualManagerSettings());

            var hostType = new HostType
            {
                Name = "MathStuff",
                Type = typeof(System.Math)
            };

            var subject = new TestObject();

            await manager.ExecuteAsync("test", "subject.Result = MathStuff.Pow(10,2);",
                                       new List <HostObject> {
                new HostObject {
                    Name = "subject", Target = subject
                }
            },
                                       new List <HostType> {
                hostType
            });

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

            await
                manager.ExecuteAsync("testscript",
                    @"var testObject = require('.\\TestRequire.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_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', '.\\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");
        }