diff --git a/src/Components/WebAssembly/Build/src/targets/BuiltInBclLinkerDescriptor.xml b/src/Components/WebAssembly/Build/src/targets/BuiltInBclLinkerDescriptor.xml index 3275831dca..6d3091310f 100644 --- a/src/Components/WebAssembly/Build/src/targets/BuiltInBclLinkerDescriptor.xml +++ b/src/Components/WebAssembly/Build/src/targets/BuiltInBclLinkerDescriptor.xml @@ -24,4 +24,15 @@ + + + + + + + diff --git a/src/Components/test/E2ETest/Tests/JsonSerializationTest.cs b/src/Components/test/E2ETest/Tests/JsonSerializationTest.cs new file mode 100644 index 0000000000..c9d4de62eb --- /dev/null +++ b/src/Components/test/E2ETest/Tests/JsonSerializationTest.cs @@ -0,0 +1,39 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using BasicTestApp; +using Microsoft.AspNetCore.Components.E2ETest.Infrastructure; +using Microsoft.AspNetCore.Components.E2ETest.Infrastructure.ServerFixtures; +using Microsoft.AspNetCore.E2ETesting; +using OpenQA.Selenium; +using Xunit; +using Xunit.Abstractions; + +namespace Microsoft.AspNetCore.Components.E2ETest.Tests +{ + public class JsonSerializationTest : ServerTestBase> + { + public JsonSerializationTest( + BrowserFixture browserFixture, + ToggleExecutionModeServerFixture serverFixture, + ITestOutputHelper output) + : base(browserFixture, serverFixture, output) + { + } + + protected override void InitializeAsyncCore() + { + Navigate(ServerPathBase, noReload: _serverFixture.ExecutionMode == ExecutionMode.Client); + Browser.MountTestComponent(); + Browser.Exists(By.Id("json-serialization-cases")); + } + + [Fact] + public void JsonSerializationCasesWork() + { + Browser.Equal("Lord Smythe", () => Browser.FindElement(By.Id("deserialized-name")).Text); + Browser.Equal("68", () => Browser.FindElement(By.Id("deserialized-age")).Text); + Browser.Equal("Vexed", () => Browser.FindElement(By.Id("deserialized-mood")).Text); + } + } +} diff --git a/src/Components/test/testassets/BasicTestApp/Index.razor b/src/Components/test/testassets/BasicTestApp/Index.razor index 7f82e2ed93..85dfc1f22f 100644 --- a/src/Components/test/testassets/BasicTestApp/Index.razor +++ b/src/Components/test/testassets/BasicTestApp/Index.razor @@ -46,6 +46,7 @@ + diff --git a/src/Components/test/testassets/BasicTestApp/JsonSerializationCases.razor b/src/Components/test/testassets/BasicTestApp/JsonSerializationCases.razor new file mode 100644 index 0000000000..7f1b227f58 --- /dev/null +++ b/src/Components/test/testassets/BasicTestApp/JsonSerializationCases.razor @@ -0,0 +1,35 @@ +@using System.Text.Json +@using System.Text.Json.Serialization + +

JSON serialization cases

+ +

+ Most aspects of System.Text.Json don't need to be tested here, as that's an external library. However some cases + are worth verifying under WebAssembly/linking specifically. +

+ +

Name: @deserializedPerson.Name

+

Age: @deserializedPerson.Age

+

Mood: @deserializedPerson.Mood

+ +@code { + Person deserializedPerson; + + protected override void OnInitialized() + { + // Round-trip some data + var input = new Person { Name = "Lord Smythe", Age = 68, Mood = EmotionalState.Vexed }; + var serializedJson = JsonSerializer.Serialize(input); + deserializedPerson = JsonSerializer.Deserialize(serializedJson); + } + + public class Person + { + public string Name { get; set; } + public int Age { get; set; } + public EmotionalState Mood { get; set; } + } + + [JsonConverter(typeof(JsonStringEnumConverter))] + public enum EmotionalState { Sombre, Vexed, Irate, Tormented } +}