From 1bd70bd8e8c96c6a143c42eb75bdd4450730bdd7 Mon Sep 17 00:00:00 2001 From: Jon Clare Date: Mon, 26 Oct 2020 10:31:11 +0000 Subject: [PATCH] Upgrade test assemblies to .NET 5.0 to take advantage of serialization fixes that allow JSON to be deserialized into classes without default constructors --- .../Shopping.Domain.Tests.csproj | 2 +- .../Shopping.Infrastructure.Tests.csproj | 2 +- .../ShoppingCartInfrastructureTests.cs | 3 -- .../ItemAddedToShoppingCartConverter.cs | 37 ------------------- .../ShoppingCartCreatedConverter.cs | 32 ---------------- 5 files changed, 2 insertions(+), 74 deletions(-) delete mode 100644 src/Examples/Shopping.Infrastructure/JsonSerialization/ItemAddedToShoppingCartConverter.cs delete mode 100644 src/Examples/Shopping.Infrastructure/JsonSerialization/ShoppingCartCreatedConverter.cs diff --git a/src/Examples/Shopping.Domain.Tests/Shopping.Domain.Tests.csproj b/src/Examples/Shopping.Domain.Tests/Shopping.Domain.Tests.csproj index 6149c30..a3bc19b 100644 --- a/src/Examples/Shopping.Domain.Tests/Shopping.Domain.Tests.csproj +++ b/src/Examples/Shopping.Domain.Tests/Shopping.Domain.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp3.1 + net5.0 diff --git a/src/Examples/Shopping.Infrastructure.Tests/Shopping.Infrastructure.Tests.csproj b/src/Examples/Shopping.Infrastructure.Tests/Shopping.Infrastructure.Tests.csproj index c14fdae..40b016e 100644 --- a/src/Examples/Shopping.Infrastructure.Tests/Shopping.Infrastructure.Tests.csproj +++ b/src/Examples/Shopping.Infrastructure.Tests/Shopping.Infrastructure.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net5.0 Exe diff --git a/src/Examples/Shopping.Infrastructure.Tests/ShoppingCartInfrastructureTests.cs b/src/Examples/Shopping.Infrastructure.Tests/ShoppingCartInfrastructureTests.cs index 544b3c3..62fc81a 100644 --- a/src/Examples/Shopping.Infrastructure.Tests/ShoppingCartInfrastructureTests.cs +++ b/src/Examples/Shopping.Infrastructure.Tests/ShoppingCartInfrastructureTests.cs @@ -10,7 +10,6 @@ using Shopping.Domain.Aggregates; using Shopping.Domain.Commands; using Shopping.Domain.Events; -using Shopping.Infrastructure.JsonSerialization; namespace Shopping.Infrastructure.Tests { @@ -58,8 +57,6 @@ public async Task PersistedRoundTripTest() private static IEventSerializer CreateJsonSerializer(IEventTypeMapping eventTypeMapping) { var serializer = new JsonEventSerializer(); - serializer.RegisterConverter(new ShoppingCartCreatedConverter()); - serializer.RegisterConverter(new ItemAddedToShoppingCartConverter()); serializer.RegisterEventTypeMappings(eventTypeMapping); diff --git a/src/Examples/Shopping.Infrastructure/JsonSerialization/ItemAddedToShoppingCartConverter.cs b/src/Examples/Shopping.Infrastructure/JsonSerialization/ItemAddedToShoppingCartConverter.cs deleted file mode 100644 index dc840f0..0000000 --- a/src/Examples/Shopping.Infrastructure/JsonSerialization/ItemAddedToShoppingCartConverter.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Text.Json; -using System.Text.Json.Serialization; -using Shopping.Domain.Events; - -namespace Shopping.Infrastructure.JsonSerialization -{ - // HACK: Add a temporary manual converter. .NET Core 3.1 doesn't support constructors with parameters - public class ItemAddedToShoppingCartConverter : JsonConverter - { - public override ItemAddedToShoppingCart Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - reader.Read(); // Id property name - reader.Read(); // Id property value - var id = reader.GetGuid(); - - reader.Read(); // Item property name - reader.Read(); // Item property value - var item = reader.GetString(); - - // Read the rest of the object. We don't need any of this - while (reader.Read()) - { - } - - return new ItemAddedToShoppingCart(id, item); - } - - public override void Write(Utf8JsonWriter writer, ItemAddedToShoppingCart value, JsonSerializerOptions options) - { - writer.WriteStartObject(); - writer.WriteString("Id",value.Id); - writer.WriteString("Item", value.Item); - writer.WriteEndObject(); - } - } -} \ No newline at end of file diff --git a/src/Examples/Shopping.Infrastructure/JsonSerialization/ShoppingCartCreatedConverter.cs b/src/Examples/Shopping.Infrastructure/JsonSerialization/ShoppingCartCreatedConverter.cs deleted file mode 100644 index 0fd61be..0000000 --- a/src/Examples/Shopping.Infrastructure/JsonSerialization/ShoppingCartCreatedConverter.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -using System.Text.Json; -using System.Text.Json.Serialization; -using Shopping.Domain.Events; - -namespace Shopping.Infrastructure.JsonSerialization -{ - // HACK: Add a temporary manual converter. .NET Core 3.1 doesn't support constructors with parameters - public class ShoppingCartCreatedConverter : JsonConverter - { - public override ShoppingCartCreated Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - { - reader.Read(); // Id property name - reader.Read(); // Id property value - var id = reader.GetGuid(); - - // Read the rest of the object. We don't need any of this - while (reader.Read()) - { - } - - return new ShoppingCartCreated(id); - } - - public override void Write(Utf8JsonWriter writer, ShoppingCartCreated value, JsonSerializerOptions options) - { - writer.WriteStartObject(); - writer.WriteString("Id",value.Id); - writer.WriteEndObject(); - } - } -} \ No newline at end of file