From 06ee4d96e0ecebbc4e4e5530c9690d680b00809c Mon Sep 17 00:00:00 2001 From: Bernd Dongus Date: Fri, 19 Apr 2024 07:06:26 +0200 Subject: [PATCH] Deserialization of ResourceTranslations --- idee5.Globalization.Test/WebApiTests.cs | 27 +++++++++++++++++++ .../idee5.Globalization.Test.csproj | 2 ++ .../Models/ResourceTranslations.cs | 11 ++++++++ .../idee5.Globalization.csproj | 4 +-- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 idee5.Globalization.Test/WebApiTests.cs diff --git a/idee5.Globalization.Test/WebApiTests.cs b/idee5.Globalization.Test/WebApiTests.cs new file mode 100644 index 0000000..5943cb7 --- /dev/null +++ b/idee5.Globalization.Test/WebApiTests.cs @@ -0,0 +1,27 @@ +using idee5.Globalization.Models; + +using Microsoft.AspNetCore.Mvc.Testing; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using System.Net.Http; +using System.Net.Http.Json; +using System.Threading.Tasks; + +namespace idee5.Globalization.Test; +[TestClass] +public class WebApiTests { + [TestMethod] + public async Task CanReadResourceTranslations() { + // Arrange + await using var webapp = new WebApplicationFactory(); + using HttpClient client = webapp.CreateClient(); + + // Act + var response = await client.GetFromJsonAsync("/api/query/GetResourceKeyTranslations?ResourceSet=CommonTerms&Id=Maybe"); + + // Assert + Assert.IsNotNull(response); + Assert.AreEqual("CommonTerms", response.ResourceSet); + Assert.AreEqual(3, response.Translations.Length); + } +} diff --git a/idee5.Globalization.Test/idee5.Globalization.Test.csproj b/idee5.Globalization.Test/idee5.Globalization.Test.csproj index 0b392d9..bb19d1c 100644 --- a/idee5.Globalization.Test/idee5.Globalization.Test.csproj +++ b/idee5.Globalization.Test/idee5.Globalization.Test.csproj @@ -31,6 +31,7 @@ + @@ -44,6 +45,7 @@ + diff --git a/idee5.Globalization/Models/ResourceTranslations.cs b/idee5.Globalization/Models/ResourceTranslations.cs index f93123b..b91d6b6 100644 --- a/idee5.Globalization/Models/ResourceTranslations.cs +++ b/idee5.Globalization/Models/ResourceTranslations.cs @@ -5,6 +5,17 @@ namespace idee5.Globalization.Models; /// The resource translations /// public record ResourceTranslations : ResourceKey { + public ResourceTranslations() { + Translations = []; + } + public ResourceTranslations(string resourceSet, string id, string? industry, string? customer, Translation[] translations) { + ResourceSet = resourceSet; + Id = id; + Industry = industry; + Customer = customer; + Translations = translations; + } + public ResourceTranslations(ResourceKey original, Translation[] translations) : base(original) { Translations = translations ?? throw new ArgumentNullException(nameof(translations)); } diff --git a/idee5.Globalization/idee5.Globalization.csproj b/idee5.Globalization/idee5.Globalization.csproj index f3909cd..375cc01 100644 --- a/idee5.Globalization/idee5.Globalization.csproj +++ b/idee5.Globalization/idee5.Globalization.csproj @@ -13,9 +13,9 @@ Globalization extensions. Enables database support for localization resources and parlances for industries and customers.. idee5 © idee5 2016 - 2024 - 3.5.3 + 3.5.4 idee5, Globalization, Localization - Get translations for resource key added + Improved serialization support enable Bernd Dongus Globalization tool for parlances for industries and customers