Пример #1
0
        public void ScriptContent_type_is_formatted()
        {
            var script   = new ScriptContent("alert('hello');");
            var mimeType = Formatter.PreferredMimeTypeFor(script.GetType());

            var formattedValue = new FormattedValue(
                mimeType,
                script.ToDisplayString(mimeType));

            formattedValue.MimeType.Should().Be("text/html");
            formattedValue.Value.Should().Be(@"<script type=""text/javascript"">alert('hello');</script>");
        }
        public void ScriptContent_type_with_possible_html_characters_is_not_HTML_encoded()
        {
            var scriptText = "if (true && false) { alert('hello with embedded <>\" escapes'); };";
            var script     = new ScriptContent(scriptText);
            var mimeType   = Formatter.GetPreferredMimeTypeFor(script.GetType());

            var formattedValue = new FormattedValue(
                mimeType,
                script.ToDisplayString(mimeType));

            formattedValue.MimeType.Should().Be("text/html");
            formattedValue.Value.Should().Be($"<script type=\"text/javascript\">{scriptText}</script>");
        }
        public void js_wrapping_formatter_fails_if_apiUri_is_not_configured_within_the_configured_timeout()
        {
            var frontendEnvironment = new HtmlNotebookFrontedEnvironment();

            CommandLineParser.SetUpFormatters(frontendEnvironment, new StartupOptions(httpPort: new HttpPort(4242)), 1.Seconds());
            var script   = new ScriptContent("alert('hello');");
            var mimeType = Formatter.GetPreferredMimeTypeFor(script.GetType());

            Action formatting = () => script.ToDisplayString(mimeType);

            formatting.Should()
            .Throw <TimeoutException>()
            .Which
            .Message
            .Should().Be("Timeout resolving the kernel's HTTP endpoint. Please try again.");
        }
        public void ScriptContent_type_is_formatted()
        {
            var script   = new ScriptContent("alert('hello');");
            var mimeType = Formatter.PreferredMimeTypeFor(script.GetType());

            var formattedValue = new FormattedValue(
                mimeType,
                script.ToDisplayString(mimeType));

            formattedValue.MimeType.Should().Be("text/html");
            formattedValue.Value.Should().Be($@"<script type=""text/javascript"">if (typeof window.createDotnetInteractiveClient === typeof Function) {{
createDotnetInteractiveClient('http://12.12.12.12:4242/').then(function (interactive) {{
let notebookScope = getDotnetInteractiveScope('http://12.12.12.12:4242/');
alert('hello');
}});
}}</script>");
        }
Пример #5
0
        public void ScriptContent_type_is_wrapped_when_http_and_the_frontendEnvironment_is_JupyterFrontedEnvironment()
        {
            var frontendEnvironment = new HtmlNotebookFrontedEnvironment(new Uri("http://12.12.12.12:4242"));

            CommandLineParser.SetUpFormatters(frontendEnvironment, new StartupOptions(httpPort: new HttpPort(4242)), 10.Seconds());
            var script   = new ScriptContent("alert('hello');");
            var mimeType = Formatter.GetPreferredMimeTypeFor(script.GetType());

            var formattedValue = new FormattedValue(
                mimeType,
                script.ToDisplayString(mimeType));

            formattedValue.MimeType.Should().Be("text/html");
            formattedValue.Value.Should().Be(@"<script type=""text/javascript"">if (typeof window.createDotnetInteractiveClient === typeof Function) {
createDotnetInteractiveClient('http://12.12.12.12:4242/').then(function (interactive) {
let notebookScope = getDotnetInteractiveScope('http://12.12.12.12:4242/');
alert('hello');
});
}</script>");
        }