Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Microsoft.DotNet.Interactive.FSharp/FSharpKernelHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
namespace Microsoft.DotNet.Interactive.FSharp

open Microsoft.DotNet.Interactive
open Microsoft.AspNetCore.Html

module FSharpKernelHelpers =
let display (value: obj) =
Kernel.display value
let HTML (value: string) =
HtmlString value
let Javascript (content: string) =
Kernel.Javascript content
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ private static ConcurrentDictionary<Type, ITypeFormatter> DefaultFormatters() =>
t.WriteTo(writer, HtmlEncoder.Default);
}),

[typeof(HtmlString)] = new HtmlFormatter<PocketView>((view, writer) => view.WriteTo(writer, HtmlEncoder.Default)),
[typeof(HtmlString)] = new HtmlFormatter<HtmlString>((view, writer) => view.WriteTo(writer, HtmlEncoder.Default)),

[typeof(JsonString)] = new HtmlFormatter<PocketView>((view, writer) => view.WriteTo(writer, HtmlEncoder.Default)),
[typeof(JsonString)] = new HtmlFormatter<JsonString>((view, writer) => view.WriteTo(writer, HtmlEncoder.Default)),

[typeof(PocketView)] = new HtmlFormatter<PocketView>((view, writer) => view.WriteTo(writer, HtmlEncoder.Default)),

Expand Down
2 changes: 1 addition & 1 deletion Microsoft.DotNet.Interactive.Rendering/HtmlFormatter{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public override void Format(T instance, TextWriter writer)
_format(instance, writer);
}

public override string MimeType => "text/html";
public override string MimeType => HtmlFormatter.MimeType;

public static ITypeFormatter<T> Create(bool includeInternals = false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static ITypeFormatter<T> Create(bool includeInternals = false)
return Default;
}

public override string MimeType => "text/plain";
public override string MimeType => PlainTextFormatter.MimeType;

public override void Format(T instance, TextWriter writer)
{
Expand Down
9 changes: 9 additions & 0 deletions Microsoft.DotNet.Interactive.Tests/AssertionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,14 @@ public static AndWhichConstraint<ObjectAssertions, T> ContainSingle<T>(

return new AndWhichConstraint<ObjectAssertions, T>(subject.Should(), subject);
}

public static AndConstraint<GenericCollectionAssertions<IKernelEvent>> NotContainErrors(
this GenericCollectionAssertions<IKernelEvent> should) =>
should
.NotContain(e => e is ErrorProduced)
.And
.NotContain(e => e is CommandParseFailure)
.And
.NotContain(e => e is CommandFailed);
}
}
26 changes: 26 additions & 0 deletions WorkspaceServer.Tests/Kernel/LanguageKernelRenderingTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Linq;
using System.Reactive.Linq;
using System.Threading.Tasks;
Expand All @@ -10,6 +11,7 @@
using Microsoft.DotNet.Interactive.Commands;
using Microsoft.DotNet.Interactive.Events;
using Microsoft.DotNet.Interactive.Rendering;
using Microsoft.DotNet.Interactive.Tests;
using Pocket;
using Xunit;
using Xunit.Abstractions;
Expand Down Expand Up @@ -175,6 +177,30 @@ public async Task Value_display_and_update_are_in_right_order(Language language)
valueEvents.Last().Should().BeOfType<DisplayedValueUpdated>();
}

[Theory]
[InlineData(Language.CSharp, "display(HTML(\"<b>hi!</b>\"));")]
[InlineData(Language.FSharp, "display(HTML(\"<b>hi!</b>\"))")]
public async Task HTML_helper_emits_HTML_which_is_not_encoded_and_has_the_text_html_mime_type(
Language language,
string code)
{
var kernel = CreateKernel(language);

var events = kernel.KernelEvents.ToSubscribedList();

await kernel.SubmitCodeAsync(code);

events.Should().NotContainErrors();

events.Should()
.ContainSingle<DisplayedValueProduced>()
.Which
.FormattedValues
.Should()
.ContainSingle(f => f.Value.Equals("<b>hi!</b>") &&
f.MimeType == "text/html");
}

[Theory]
[InlineData(Language.CSharp)]
[InlineData(Language.FSharp)]
Expand Down
2 changes: 1 addition & 1 deletion WorkspaceServer/Packaging/PackageRestoreContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task<AddNugetResult> AddPackage(
{
var requestedPackage = new NugetPackageReference(packageName, packageVersion, restoreSources);

if (!String.IsNullOrEmpty(packageName) && _nugetPackageReferences.TryGetValue(requestedPackage, out var _))
if (!string.IsNullOrEmpty(packageName) && _nugetPackageReferences.TryGetValue(requestedPackage, out var _))
{
return new AddNugetPackageResult(false, requestedPackage);
}
Expand Down