Наследование: MonoBehaviour
Пример #1
0
        public void RunsInCScript()
        {
            var script = new TestScript();

            script.AppendBlock(new JsHamcrestLibrary());

            Assert.DoesNotThrow(() => script.RunTest(ScriptResources.JsHamcrestSampleTest));
        }
Пример #2
0
        public void RunTestThrowsScriptExceptionBackToCaller()
        {
            var script = new TestScript();

            var ex = Assert.Throws<ScriptException>(() => script.RunTest("throw { message: 'My Script Exception' };"));

            Assert.Equal(ex.Message, "{\"message\":\"My Script Exception\"}");
        }
Пример #3
0
        public void RunsInCScript()
        {
            var script = new TestScript();

            script.AppendBlock(new JsonLibrary());

            Assert.Equal("\"1\"", script.RunTest("return JSON.stringify(JSON.parse('1'));"));
        }
Пример #4
0
        public void IgnoresMultipleRegistrations()
        {
            var script = new TestScript();

            script.AppendBlock(new JsonLibrary());
            script.AppendBlock(new JsonLibrary());

            Assert.Equal("\"1\"", script.RunTest("return JSON.stringify(1);"));
        }
Пример #5
0
	// Use this for initialization
	void Start () 
	{
		InputM = GetComponent<InputManager>();
		Movement = GetComponent<MovementManager>();
		Tester = GetComponent<TestScript>();

		isRunning = false;

	}
Пример #6
0
        public void IgnoresMultipleRegistrations()
        {
            var script = new TestScript();

            script.AppendBlock(new JsHamcrestLibrary());
            script.AppendBlock(new JsHamcrestLibrary());

            Assert.DoesNotThrow(() => script.RunTest(ScriptResources.JsHamcrestSampleTest));
        }
Пример #7
0
        public void TestActionsInScript()
        {
            // make some actions
            var a = new TestAction("a");
            var b = new TestAction("b");
            var c = new TestAction("c");
            var d = new TestAction("d");
            var e = new TestAction("e");
            var f = new TestAction("f");

            var seq = new TestScript("test");
            seq.Enqueue(new List<Action>() { a, b, c });

            // make sure they're all enqueued but only A is activated
            Assert.IsTrue(!seq.IsEmpty && seq.Head == a);
            Assert.IsTrue(a.IsEnqueued && a.IsActive);
            Assert.IsTrue(b.IsEnqueued && !b.IsActive);
            Assert.IsTrue(c.IsEnqueued && !c.IsActive);

            // stop A, this should dequeue it and activate B
            a.Stop(true);
            Assert.IsTrue(!seq.IsEmpty && seq.Head == b);
            Assert.IsTrue(!a.IsEnqueued && !a.IsActive);
            Assert.IsTrue( b.IsEnqueued &&  b.IsActive);
            Assert.IsTrue( c.IsEnqueued && !c.IsActive);

            // stop the script, this should pop B and C without activating the latter
            seq.Clear();
            Assert.IsTrue(seq.IsEmpty && seq.Head == null);
            Assert.IsTrue(!a.IsEnqueued && !a.IsActive && a.countActivate == 1 && a.countDeactivate == 1);
            Assert.IsTrue(!b.IsEnqueued && !b.IsActive && b.countActivate == 1 && b.countDeactivate == 1);
            Assert.IsTrue(!c.IsEnqueued && !c.IsActive && c.countActivate == 0 && c.countDeactivate == 0);

            // push two more
            seq.Enqueue(new List<Action>() { d, e });
            Assert.IsTrue(d.IsEnqueued &&  d.IsActive && d.countActivate == 1 && d.countDeactivate == 0);
            Assert.IsTrue(e.IsEnqueued && !e.IsActive && e.countActivate == 0 && e.countDeactivate == 0);

            // pop E from the end, this should not affect D, or activate/deactivate E
            seq.PopTail();
            Assert.IsTrue( d.IsEnqueued &&  d.IsActive && d.countActivate == 1 && d.countDeactivate == 0);
            Assert.IsTrue(!e.IsEnqueued && !e.IsActive && e.countActivate == 0 && e.countDeactivate == 0);

            // push F to the front, this should deactivate D but keep it in the queue
            seq.PushHead(f);
            Assert.IsTrue(f.IsEnqueued &&  f.IsActive && f.countActivate == 1 && f.countDeactivate == 0);
            Assert.IsTrue(d.IsEnqueued && !d.IsActive && d.countActivate == 1 && d.countDeactivate == 1);

            // now dequeue F from the front, this should pop it, and re-activate D
            seq.StopCurrentAction(true, null);
            Assert.IsTrue(!f.IsEnqueued && !f.IsActive && f.countActivate == 1 && f.countDeactivate == 1);
            Assert.IsTrue( d.IsEnqueued &&  d.IsActive && d.countActivate == 2 && d.countDeactivate == 1);
        }
Пример #8
0
        public void AlwaysAppendBlockToExistingScript()
        {
            var block1 = new ScriptBlock("var x = 0;");
            var block2 = new ScriptBlock("var y = 1;");
            var block3 = new ScriptBlock("var z = 2;");
            var script = new TestScript();

            script.AppendBlock(block1);
            script.AppendBlock(block2);
            script.AppendBlock(block3);

            Assert.Equal(block1 + Environment.NewLine + block2 + Environment.NewLine + block3 + Environment.NewLine, script.ToString());
        }
Пример #9
0
        public void Test(TestCase testCase)
        {
            var script = new TestScript { IncludeDefaultBreakpoint = false };

            // Append required JavaScript libraries.
            script.AppendBlock(new JsAssertLibrary());

            // Append required JavaScript Files.
            script.AppendFile(@"..\..\dateExtensions.js");
            script.AppendFile(@"..\..\cookieContainer.js");
            script.AppendFile(testCase.TestFile);

            // Run 'Test'.
            script.RunTest(testCase);
        }
Пример #10
0
        public void Setup()
        {
            Script = new TestScript { IncludeDefaultBreakpoint = false };

            // Append required JavaScript libraries.
            Script.AppendBlock(new JsAssertLibrary());

            // Append required JavaScript Files.
            Script.AppendFile(@"..\..\dateExtensions.js");
            Script.AppendFile(@"..\..\cookieContainer.js");
            Script.AppendFile(@"..\..\whenSettingCookies.js");

            // Setup JavaScript Context
            Script.AppendBlock(@"
                                 var document = {};
                                 var cookieContainer = new CookieContainer(document);
                               ");
        }
Пример #11
0
        public void AlwaysAppendIncludeToExistingScript()
        {
            using (var tempFile1 = new TempFile())
            using (var tempFile2 = new TempFile())
            using (var tempFile3 = new TempFile())
            {
                var script = new TestScript();

                script.AppendFile(tempFile1.FileName);
                script.AppendFile(tempFile2.FileName);
                script.AppendFile(tempFile3.FileName);

                Assert.Equal(String.Format(
                  @"<script language='JavaScript' src='{0}'></script>{3}<script language='JavaScript' src='{1}'></script>{3}<script language='JavaScript' src='{2}'></script>{3}",
                  tempFile1.FileName,
                  tempFile2.FileName,
                  tempFile3.FileName,
                  Environment.NewLine
                ), script.ToString());
            }
        }
Пример #12
0
        public void TestActionStartupAndUpdate()
        {
            // make some actions
            var a = new TestAction("a");
            var b = new TestAction("b");
            var c = new TestAction("c", true); // this one stops before first update
            var seq = new TestScript("test", a, b, c);

            Assert.IsTrue(a.IsEnqueued && a.IsActive && !a.IsStarted);
            Assert.IsTrue(a.countUpdate == 0);

            // fake an update cycle
            seq.OnUpdate();

            Assert.IsTrue(a.IsEnqueued && a.IsActive && a.IsStarted);
            Assert.IsTrue(a.countUpdate == 1);

            // stop. this will remove and deactivate A, and activate B,
            // but not start it yet until an update
            a.Stop(true);
            Assert.IsTrue(!a.IsEnqueued && !a.IsActive && !a.IsStarted);
            Assert.IsTrue( b.IsEnqueued &&  b.IsActive && !b.IsStarted);
            Assert.IsTrue(a.countUpdate == 1);
            Assert.IsTrue(b.countUpdate == 0);

            seq.OnUpdate();
            Assert.IsTrue(b.IsEnqueued && b.IsActive && b.IsStarted);
            Assert.IsTrue(b.countUpdate == 1);

            // stop b. this will activate c, which will stop itself before first update
            b.Stop(true);
            Assert.IsTrue(c.IsEnqueued && c.IsActive && !c.IsStarted);
            Assert.IsTrue(c.countUpdate == 0);
            seq.OnUpdate();
            Assert.IsTrue(!c.IsEnqueued && !c.IsActive && !c.IsStarted);
            Assert.IsTrue(c.countUpdate == 0); // this update never got a chance to run
        }
Пример #13
0
        public void RunTestReturnsNullWhenNoReturnSpecified()
        {
            var script = new TestScript();

            Assert.Equal("null", script.RunTest("var result = 'Success!';"));
        }
Пример #14
0
 public void AddToTestScripts(TestScript testScript)
 {
     base.AddObject("TestScripts", testScript);
 }
Пример #15
0
 public static TestScript CreateTestScript(int id)
 {
     TestScript testScript = new TestScript();
     testScript.ID = id;
     return testScript;
 }
Пример #16
0
	void Awake()
	{
		instance = this;
	}
Пример #17
0
        public void RunTestIncludesDefaultDebuggerStatementByDefault()
        {
            var cscriptCommand = new FakeCScriptCommand();
            var script = new TestScript(cscriptCommand);

            script.RunTest("return true;");

            Assert.True(cscriptCommand.ScriptContainedDebuggerStatement);
        }
Пример #18
0
 protected JavaScriptTestBase(Boolean includeDefaultBreakpoint)
 {
     Script = new TestScript { IncludeDefaultBreakpoint = includeDefaultBreakpoint };
 }
 // Use this for initialization
 void Awake()
 {
     Instance = this;
     pMove = player.GetComponent<TestScript>();
 }
Пример #20
0
 private void Awake()
 {
     Instance = this;
     controller = GetComponent<CharacterController>();
 }
Пример #21
0
        public void RunTestDoesNotIncludeDefaultDebuggerStatementIfSuppressed()
        {
            var cscriptCommand = new FakeCScriptCommand();
            var script = new TestScript(cscriptCommand) { IncludeDefaultBreakpoint = false };

            script.RunTest("return true;");

            Assert.False(cscriptCommand.ScriptContainedDebuggerStatement);
        }
Пример #22
0
        public void RunTestReturnsValueWhenExplicitReturnSpecified()
        {
            var script = new TestScript();

            Assert.Equal("\"Success!\"", script.RunTest("return 'Success!';"));
        }
Пример #23
0
        public void TestStopOnFailure()
        {
            // make some scripts

            var a = new TestAction("a");
            var b = new TestAction("b");
            var c = new TestAction("c");
            var abc = new TestScript("abc", a, b, c);
            var d = new TestAction("d");
            var e = new TestAction("e");
            var f = new TestAction("f");
            var def = new TestScript("def", d, e, f);

            var q = new ScriptQueue();
            q.Enqueue(new List<Script>() { abc, def });

            q.OnUpdate();
            Assert.IsTrue(a.IsEnqueued && a.IsActive && a.IsStarted);

            // if we stop just action a with the failure flag set, it should stop the entire script
            // and advance to the next one
            abc.StopCurrentAction(false, null);

            Assert.IsTrue(!a.IsEnqueued && !a.IsActive);
            Assert.IsTrue(!abc.IsEnqueued && !abc.IsActive);
            Assert.IsTrue(def.IsActive && d.IsActive);

            // similary stopping the script will just remove it
            def.StopScript(false, null);
            Assert.IsTrue(!def.IsActive && !d.IsActive);
        }
Пример #24
0
        public void TestScriptsInQueue()
        {
            // make some scripts

            var a = new TestAction("a");
            var b = new TestAction("b");
            var c = new TestAction("c");
            var abc = new TestScript("abc", a, b, c);
            var empty = new TestScript("empty");
            var d = new TestAction("d");
            var e = new TestAction("e");
            var f = new TestAction("f");
            var def = new TestScript("def", d, e, f );

            var q = new ScriptQueue();
            q.Enqueue(new List<Script>() { abc, empty, def });

            // verify the first script and action are active
            Assert.IsTrue(!q.IsEmpty && q.Head == abc && q.Head.Head == a);
            Assert.IsTrue(  abc.IsEnqueued &&  abc.IsActive);
            Assert.IsTrue(empty.IsEnqueued && !empty.IsActive);
            Assert.IsTrue(  def.IsEnqueued && !def.IsActive);

            // stop the first action, keeps the same script active
            a.Stop(true);
            Assert.IsTrue(!q.IsEmpty && q.Head == abc && q.Head.Head == b);

            // finish off actions. this will remove ABC from the queue
            b.Stop(true);
            c.Stop(true);
            Assert.IsTrue(!q.IsEmpty && q.Head != abc);
            Assert.IsTrue(abc.countActivate == 1 && abc.countDeactivate == 1);

            // the Empty script was activated but then immediately removed, because it's empty
            Assert.IsTrue(!empty.IsEnqueued && !empty.IsActive);
            Assert.IsTrue(empty.countActivate == 1 && empty.countDeactivate == 1);

            // and let's make sure that DEF is the active one now
            Assert.IsTrue(!q.IsEmpty && q.Head == def && q.Head.Head == d);
            Assert.IsTrue(  !abc.IsEnqueued &&   !abc.IsActive);
            Assert.IsTrue(!empty.IsEnqueued && !empty.IsActive);
            Assert.IsTrue(   def.IsEnqueued &&    def.IsActive);
            Assert.IsTrue(def.countActivate == 1 && def.countDeactivate == 0);

            // then if we force-stop DEF, it should clean out of the queue completely
            def.StopScript(true, null);
            Assert.IsTrue(q.IsEmpty && q.Head == null);
            Assert.IsTrue(!def.IsEnqueued && !def.IsActive);
            Assert.IsTrue(def.countActivate == 1 && def.countDeactivate == 1);
        }
Пример #25
0
        public void RunTestIncludesDefaultDebuggerStatementIfRequested()
        {
            var cscriptCommand = new FakeCScriptCommand();
            var script = new TestScript(cscriptCommand) { IncludeDefaultBreakpoint = true };

            script.RunTest("return true;");

            Assert.True(cscriptCommand.ScriptContainedDebuggerStatement);
        }
Пример #26
0
        public void TestQueueUpdate()
        {
            // make some scripts

            var a = new TestAction("a");
            var b = new TestAction("b");
            var c = new TestAction("c");
            var abc = new TestScript("abc", a, b, c);
            var d = new TestAction("d");
            var e = new TestAction("e");
            var f = new TestAction("f");
            var def = new TestScript("def", d, e, f);

            var q = new ScriptQueue();
            q.Enqueue(new List<Script>() { abc, def });

            Assert.IsTrue(a.IsEnqueued && a.IsActive && !a.IsStarted);

            // fake a queue update
            q.OnUpdate();

            Assert.IsTrue(a.IsEnqueued && a.IsActive && a.IsStarted);

            // stop the script. the first action in the next script
            // will be activated, but won't be started until another update
            q.StopCurrentScript(true, null);
            Assert.IsTrue(!abc.IsEnqueued && !abc.IsActive && !a.IsActive && !a.IsStarted);
            Assert.IsTrue(def.IsEnqueued && def.IsActive && d.IsActive && !d.IsStarted);

            q.OnUpdate();
            Assert.IsTrue(def.IsEnqueued && def.IsActive && d.IsActive && d.IsStarted);

            // clear everything. no more updates
            q.StopAllScripts(true, null);
            Assert.IsTrue(!def.IsEnqueued && !def.IsActive && !d.IsActive && !d.IsStarted);
            Assert.IsTrue(q.IsEmpty);
        }