Пример #1
0
        public void CookieDocumentSet()
        {
            Script.RunTest(@"
                             cookieContainer.setCookie('MyCookie', 'Chocolate Chip');

                             assert.equal('MyCookie=' + escape('Chocolate Chip') + ';path=/', document.cookie);
                           ");
        }
Пример #2
0
        public void ReturnEmptyStringIfCookiesNotSet()
        {
            Script.RunTest(@"
                             document.cookie = '';

                             assert.equal('', cookieContainer.getCookie('MyCookie'));
                           ");
        }
Пример #3
0
 protected String RunTest(String context, String action)
 {
     try
     {
         // The action will always be the function name to call; must invoke function with (); to run test.
         return(Script.RunTest(String.Format("return {0}();", action)));
     }
     catch (ScriptException ex)
     {
         // StackTrace intentionally thrown away as it contains no meaninful information; exception details are in message.
         throw new ScriptException(context + '.' + action + Environment.NewLine + ex.Message);
     }
 }
Пример #4
0
        public void RunsInCScript()
        {
            var script = new TestScript();

            script.AppendBlock(new JsHamcrestLibrary());

            Assert.DoesNotThrow(() => script.RunTest(ScriptResources.JsHamcrestSampleTest));
        }
Пример #5
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\"}");
        }
Пример #6
0
        public void RunsInCScript()
        {
            var script = new TestScript();

            script.AppendBlock(new JsonLibrary());

            Assert.Equal("\"1\"", script.RunTest("return JSON.stringify(JSON.parse('1'));"));
        }
Пример #7
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\"}");
        }
Пример #8
0
        public void RunsInCScript()
        {
            var script = new TestScript();

            script.AppendBlock(new JsHamcrestLibrary());

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

            script.AppendBlock(new JsonLibrary());

            Assert.Equal("\"1\"", script.RunTest("return JSON.stringify(JSON.parse('1'));"));
        }
Пример #10
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);"));
        }
Пример #11
0
        public void IgnoresMultipleRegistrations()
        {
            var script = new TestScript();

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

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

            script.RunTest("return true;");

            Assert.True(cscriptCommand.ScriptContainedDebuggerStatement);
        }
Пример #13
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);"));
        }
Пример #14
0
        public void IgnoresMultipleRegistrations()
        {
            var script = new TestScript();

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

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

            var result = script.RunTest(@"
return [{ a: 1 }, { a: 2 }, { a: 3 }].filter(function (l) { return l.a >= 2; }).length;
            ");

            Assert.Equal("2", result);
        }
Пример #16
0
        public void RunTestDoesNotIncludeDefaultDebuggerStatementIfSuppressed()
        {
            var cscriptCommand = new FakeCScriptCommand();
            var script         = new TestScript(cscriptCommand)
            {
                IncludeDefaultBreakpoint = false
            };

            script.RunTest("return true;");

            Assert.False(cscriptCommand.ScriptContainedDebuggerStatement);
        }
Пример #17
0
        public void RunTestIncludesDefaultDebuggerStatementIfRequested()
        {
            var cscriptCommand = new FakeCScriptCommand();
            var script         = new TestScript(cscriptCommand)
            {
                IncludeDefaultBreakpoint = true
            };

            script.RunTest("return true;");

            Assert.True(cscriptCommand.ScriptContainedDebuggerStatement);
        }
Пример #18
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);
        }
Пример #19
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);
        }
Пример #20
0
 public void TestUnit(string res, string method)
 {
     _commonTestScript.RunTest($"assert.equal('{res}', new testCommand().{method}());");
 }
Пример #21
0
 public void TestCount(string input, string exp)
 {
     TestScript.RunTest($"assert.equal({exp}, CountFromString('{input}'));");
 }
Пример #22
0
 protected Object RunTest(String scriptBlock)
 {
     return JsonConvert.DeserializeObject(Script.RunTest(scriptBlock));
 }
Пример #23
0
        public void RunTestDoesNotIncludeDefaultDebuggerStatementIfSuppressed()
        {
            var cscriptCommand = new FakeCScriptCommand();
            var script = new TestScript(cscriptCommand) { IncludeDefaultBreakpoint = false };

            script.RunTest("return true;");

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

            Assert.Equal("null", script.RunTest("var result = 'Success!';"));
        }
Пример #25
0
        public void RunTestReturnsValueWhenExplicitReturnSpecified()
        {
            var script = new TestScript();

            Assert.Equal("\"Success!\"", script.RunTest("return 'Success!';"));
        }
Пример #26
0
        public void RunTestIncludesDefaultDebuggerStatementByDefault()
        {
            var cscriptCommand = new FakeCScriptCommand();
            var script = new TestScript(cscriptCommand);

            script.RunTest("return true;");

            Assert.True(cscriptCommand.ScriptContainedDebuggerStatement);
        }
Пример #27
0
        public void RunTestIncludesDefaultDebuggerStatementIfRequested()
        {
            var cscriptCommand = new FakeCScriptCommand();
            var script = new TestScript(cscriptCommand) { IncludeDefaultBreakpoint = true };

            script.RunTest("return true;");

            Assert.True(cscriptCommand.ScriptContainedDebuggerStatement);
        }
Пример #28
0
        public void RunTestReturnsNullWhenNoReturnSpecified()
        {
            var script = new TestScript();

            Assert.Equal("null", script.RunTest("var result = 'Success!';"));
        }
Пример #29
0
        public void RunTestReturnsValueWhenExplicitReturnSpecified()
        {
            var script = new TestScript();

            Assert.Equal("\"Success!\"", script.RunTest("return 'Success!';"));
        }