public void ScriptContent_type_is_formatted() { 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"">alert('hello');</script>"); }
public void JArray_is_formatted_as_application_json() { var obj = JArray.FromObject(new object[] { "one", 1 }); var mimeType = Formatter.GetPreferredMimeTypeFor(obj.GetType()); mimeType.Should().Be(JsonFormatter.MimeType); obj.ToDisplayString(JsonFormatter.MimeType) .Should() .Be(@"[""one"",1]"); }
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 MathString_type_is_formatted() { var latex = new MathString(@"F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx"); var mimeType = Formatter.GetPreferredMimeTypeFor(latex.GetType()); var formattedValue = new FormattedValue( mimeType, latex.ToDisplayString(mimeType)); formattedValue.MimeType.Should().Be("text/latex"); formattedValue.Value.Should().Be(@"$$F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx$$"); }
public void JObject_is_formatted_as_application_json() { var obj = JObject.FromObject(new { value = 123, OtherValue = 456 }); var mimeType = Formatter.GetPreferredMimeTypeFor(obj.GetType()); var output = obj.ToDisplayString(JsonFormatter.MimeType); mimeType.Should().Be(JsonFormatter.MimeType); output .Should() .Be(@"{""value"":123,""OtherValue"":456}"); }
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_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>"); }