Skip to content

Commit

Permalink
Deserialization of ResourceTranslations
Browse files Browse the repository at this point in the history
  • Loading branch information
bdongus committed Apr 19, 2024
1 parent 6c1b481 commit 06ee4d9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
27 changes: 27 additions & 0 deletions idee5.Globalization.Test/WebApiTests.cs
Original file line number Diff line number Diff line change
@@ -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<Web.Startup>();
using HttpClient client = webapp.CreateClient();

// Act
var response = await client.GetFromJsonAsync<ResourceTranslations>("/api/query/GetResourceKeyTranslations?ResourceSet=CommonTerms&Id=Maybe");

// Assert
Assert.IsNotNull(response);
Assert.AreEqual("CommonTerms", response.ResourceSet);
Assert.AreEqual(3, response.Translations.Length);
}
}
2 changes: 2 additions & 0 deletions idee5.Globalization.Test/idee5.Globalization.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<ItemGroup>
<PackageReference Include="idee5.Common.Data" version="2.3.0" />
<PackageReference Include="MELT" Version="0.9.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.4" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
Expand All @@ -44,6 +45,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\idee5.Globalization.EFCore\idee5.Globalization.EFCore.csproj" />
<ProjectReference Include="..\idee5.Globalization.Web\idee5.Globalization.Web.csproj" />
<ProjectReference Include="..\idee5.Globalization\idee5.Globalization.csproj" />
</ItemGroup>
<ItemGroup>
Expand Down
11 changes: 11 additions & 0 deletions idee5.Globalization/Models/ResourceTranslations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ namespace idee5.Globalization.Models;
/// The resource translations
/// </summary>
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));
}
Expand Down
4 changes: 2 additions & 2 deletions idee5.Globalization/idee5.Globalization.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
<Description>Globalization extensions. Enables database support for localization resources and parlances for industries and customers..</Description>
<Company>idee5</Company>
<Copyright>© idee5 2016 - 2024</Copyright>
<Version>3.5.3</Version>
<Version>3.5.4</Version>
<PackageTags>idee5, Globalization, Localization</PackageTags>
<PackageReleaseNotes>Get translations for resource key added</PackageReleaseNotes>
<PackageReleaseNotes>Improved serialization support</PackageReleaseNotes>
<Nullable>enable</Nullable>
<Authors>Bernd Dongus</Authors>
<Title>Globalization tool for parlances for industries and customers</Title>
Expand Down

0 comments on commit 06ee4d9

Please sign in to comment.