public void CookieDocumentSet() { Script.RunTest(@" cookieContainer.setCookie('MyCookie', 'Chocolate Chip'); assert.equal('MyCookie=' + escape('Chocolate Chip') + ';path=/', document.cookie); "); }
public void ReturnEmptyStringIfCookiesNotSet() { Script.RunTest(@" document.cookie = ''; assert.equal('', cookieContainer.getCookie('MyCookie')); "); }
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); } }
public void RunsInCScript() { var script = new TestScript(); script.AppendBlock(new JsHamcrestLibrary()); Assert.DoesNotThrow(() => script.RunTest(ScriptResources.JsHamcrestSampleTest)); }
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\"}"); }
public void RunsInCScript() { var script = new TestScript(); script.AppendBlock(new JsonLibrary()); Assert.Equal("\"1\"", script.RunTest("return JSON.stringify(JSON.parse('1'));")); }
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\"}"); }
public void IgnoresMultipleRegistrations() { var script = new TestScript(); script.AppendBlock(new JsonLibrary()); script.AppendBlock(new JsonLibrary()); Assert.Equal("\"1\"", script.RunTest("return JSON.stringify(1);")); }
public void IgnoresMultipleRegistrations() { var script = new TestScript(); script.AppendBlock(new JsHamcrestLibrary()); script.AppendBlock(new JsHamcrestLibrary()); Assert.DoesNotThrow(() => script.RunTest(ScriptResources.JsHamcrestSampleTest)); }
public void RunTestIncludesDefaultDebuggerStatementByDefault() { var cscriptCommand = new FakeCScriptCommand(); var script = new TestScript(cscriptCommand); script.RunTest("return true;"); Assert.True(cscriptCommand.ScriptContainedDebuggerStatement); }
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); }
public void RunTestDoesNotIncludeDefaultDebuggerStatementIfSuppressed() { var cscriptCommand = new FakeCScriptCommand(); var script = new TestScript(cscriptCommand) { IncludeDefaultBreakpoint = false }; script.RunTest("return true;"); Assert.False(cscriptCommand.ScriptContainedDebuggerStatement); }
public void RunTestIncludesDefaultDebuggerStatementIfRequested() { var cscriptCommand = new FakeCScriptCommand(); var script = new TestScript(cscriptCommand) { IncludeDefaultBreakpoint = true }; script.RunTest("return true;"); Assert.True(cscriptCommand.ScriptContainedDebuggerStatement); }
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); }
public void TestUnit(string res, string method) { _commonTestScript.RunTest($"assert.equal('{res}', new testCommand().{method}());"); }
public void TestCount(string input, string exp) { TestScript.RunTest($"assert.equal({exp}, CountFromString('{input}'));"); }
protected Object RunTest(String scriptBlock) { return JsonConvert.DeserializeObject(Script.RunTest(scriptBlock)); }
public void RunTestReturnsNullWhenNoReturnSpecified() { var script = new TestScript(); Assert.Equal("null", script.RunTest("var result = 'Success!';")); }
public void RunTestReturnsValueWhenExplicitReturnSpecified() { var script = new TestScript(); Assert.Equal("\"Success!\"", script.RunTest("return 'Success!';")); }