From 86b78731b2468db837ed218b6cb991e59abf40c5 Mon Sep 17 00:00:00 2001 From: axunonb Date: Wed, 3 Jul 2024 09:19:10 +0200 Subject: [PATCH] Add net80 as target framework * Add net80 as target framework * Update nuget packages to latests * Update unit test to use the constraint model * Bump version to v2.1.0 --- .github/workflows/build_test.yml | 14 ++--- .../Axuno.TextTemplating.Tests.csproj | 14 +++-- .../TemplateDefinitionTests.cs | 10 +-- .../TemplateRendererTests.cs | 63 ++++++++++--------- .../TextTemplatingOptionsTests.cs | 4 +- ...alizedTemplateContentReaderFactoryTests.cs | 6 +- .../VirtualFileTemplateContributorTests.cs | 27 ++++---- .../Axuno.TextTemplating.csproj | 31 +++------ Src/TextTemplatingDemo/Program.cs | 28 ++++----- .../TextTemplatingDemo.csproj | 6 +- 10 files changed, 102 insertions(+), 101 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index f06bd8b..db44669 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -16,19 +16,19 @@ jobs: name: Build runs-on: ${{ matrix.os }} env: - version: '2.0.1' - versionFile: '2.0.1' - packDotNetVersion: '6' + version: '2.1.0' + versionFile: '2.1.0' + packDotNetVersion: '8' strategy: matrix: os: [ ubuntu-latest ] - dotnet-version: [ '3.x', '6.x' ] + dotnet-version: [ '3.x', '6.x', '8.0' ] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup .NET - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ matrix.dotnet-version }} - name: Restore dependencies @@ -44,7 +44,7 @@ jobs: dotnet build ./Src/TextTemplating.sln /verbosity:minimal --configuration release /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg /p:ContinuousIntegrationBuild=true /p:PackageOutputPath=${{ github.workspace }}/artifacts/ /p:Version=${{ env.version }} /p:FileVersion=${{ env.versionFile }} dotnet pack ./Src/TextTemplating.sln /verbosity:minimal --configuration release - name: Upload Artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 if: startsWith(matrix.dotnet-version, env.packDotNetVersion) with: name: Packages_${{ env.version }} diff --git a/Src/Axuno.TextTemplating.Tests/Axuno.TextTemplating.Tests.csproj b/Src/Axuno.TextTemplating.Tests/Axuno.TextTemplating.Tests.csproj index ad58da2..95e48d6 100644 --- a/Src/Axuno.TextTemplating.Tests/Axuno.TextTemplating.Tests.csproj +++ b/Src/Axuno.TextTemplating.Tests/Axuno.TextTemplating.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net8.0 true ..\Axuno.TextTemplating\Axuno.TextTemplating.snk axuno gGmbH @@ -16,10 +16,14 @@ - - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/Src/Axuno.TextTemplating.Tests/TemplateDefinitionTests.cs b/Src/Axuno.TextTemplating.Tests/TemplateDefinitionTests.cs index 6fa4a79..9a567d6 100644 --- a/Src/Axuno.TextTemplating.Tests/TemplateDefinitionTests.cs +++ b/Src/Axuno.TextTemplating.Tests/TemplateDefinitionTests.cs @@ -19,18 +19,18 @@ public TemplateDefinitionTests() public void Should_Retrieve_Template_Definition_By_Name() { var welcomeEmailTemplate = _templateDefinitionManager.Get(Templates.WelcomeEmail); - Assert.AreEqual(Templates.WelcomeEmail, welcomeEmailTemplate?.Name); - Assert.IsFalse(welcomeEmailTemplate?.IsInlineLocalized); + Assert.That(welcomeEmailTemplate?.Name, Is.EqualTo(Templates.WelcomeEmail)); + Assert.That(welcomeEmailTemplate?.IsInlineLocalized, Is.False); var sayHelloTemplate = _templateDefinitionManager.Get(Templates.SayHelloEmail); - Assert.AreEqual(Templates.SayHelloEmail, sayHelloTemplate?.Name); - Assert.IsTrue(sayHelloTemplate?.IsInlineLocalized); + Assert.That(sayHelloTemplate?.Name, Is.EqualTo(Templates.SayHelloEmail)); + Assert.That(sayHelloTemplate?.IsInlineLocalized, Is.True); } [Test] public void Should_Get_Null_If_Template_Not_Found() { - Assert.IsNull(_templateDefinitionManager.Get("undefined-template")); + Assert.That(_templateDefinitionManager.Get("undefined-template"), Is.Null); } [Test] diff --git a/Src/Axuno.TextTemplating.Tests/TemplateRendererTests.cs b/Src/Axuno.TextTemplating.Tests/TemplateRendererTests.cs index 8d3d7f8..4e69787 100644 --- a/Src/Axuno.TextTemplating.Tests/TemplateRendererTests.cs +++ b/Src/Axuno.TextTemplating.Tests/TemplateRendererTests.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; @@ -9,7 +8,7 @@ namespace Axuno.TextTemplating.Tests; [TestFixture] public class TemplateRendererTests { - private readonly IServiceProvider _services; + private readonly ServiceProvider _services; private readonly ITemplateRenderer _renderer; public TemplateRendererTests() @@ -18,108 +17,114 @@ public TemplateRendererTests() _renderer = _services.GetRequiredService(); } + [OneTimeTearDown] + public void CleanUp() + { + _services.Dispose(); + } + [Test] public async Task Should_Get_Rendered_With_CultureSpecific_Template() { - Assert.AreEqual("Welcome John to Axuno.TextTemplating!", await _renderer.RenderAsync( + Assert.That(await _renderer.RenderAsync( Templates.WelcomeEmail, model: new { name = "John" }, cultureName: "en" - )); + ), Is.EqualTo("Welcome John to Axuno.TextTemplating!")); - Assert.AreEqual("Willkommen, John, bei Axuno.TextTemplating!", await _renderer.RenderAsync( + Assert.That(await _renderer.RenderAsync( Templates.WelcomeEmail, model: new { name = "John" }, cultureName: "de" - )); + ), Is.EqualTo("Willkommen, John, bei Axuno.TextTemplating!")); } [Test] public async Task Should_Use_Fallback_Culture_CultureSpecific_Template() { //"en-US" falls back to "en" since "en-US" doesn't exists and "en" is the fallback culture - Assert.AreEqual("Welcome John to Axuno.TextTemplating!", await _renderer.RenderAsync( + Assert.That(await _renderer.RenderAsync( Templates.WelcomeEmail, model: new { name = "John" }, cultureName: "en_US" - )); - + ), Is.EqualTo("Welcome John to Axuno.TextTemplating!")); + //"es" falls back to "en" since "es" doesn't exists and "en" is the fallback culture - Assert.AreEqual("Welcome John to Axuno.TextTemplating!", await _renderer.RenderAsync( + Assert.That(await _renderer.RenderAsync( Templates.WelcomeEmail, model: new { name = "John" }, cultureName: "es" - )); + ), Is.EqualTo("Welcome John to Axuno.TextTemplating!")); } [Test] public async Task Should_Get_Rendered_Localized_Template_Content_With_Strongly_Typed_Model() { - Assert.AreEqual("Welcome John to Axuno.TextTemplating!", await _renderer.RenderAsync( + Assert.That(await _renderer.RenderAsync( Templates.WelcomeEmail, model: new WelcomeEmailModel("John"), cultureName: "en" - )); + ), Is.EqualTo("Welcome John to Axuno.TextTemplating!")); } [Test] public async Task Should_Get_Rendered_Localized_Template_Content_With_Dictionary_Model() { - Assert.AreEqual("Welcome John to Axuno.TextTemplating!", await _renderer.RenderAsync( + Assert.That(await _renderer.RenderAsync( Templates.WelcomeEmail, model: new Dictionary { { "name", "John" } }, cultureName: "en" - )); + ), Is.EqualTo("Welcome John to Axuno.TextTemplating!")); } [Test] public async Task Should_Get_Rendered_Inline_Localized_Template() { - Assert.AreEqual("*BEGIN*Hello John, how are you?*END*", await _renderer.RenderAsync( + Assert.That(await _renderer.RenderAsync( Templates.SayHelloEmail, new SayHelloEmailModel("John"), cultureName: "en" - )); + ), Is.EqualTo("*BEGIN*Hello John, how are you?*END*")); - Assert.AreEqual("*BEGIN*Bonjour John, comment ça va?*END*", await _renderer.RenderAsync( + Assert.That(await _renderer.RenderAsync( Templates.SayHelloEmail, new SayHelloEmailModel("John"), cultureName: "fr" - )); - - Assert.AreEqual("*BEGIN*Hallo John, wie geht es Dir?*END*", await _renderer.RenderAsync( + ), Is.EqualTo("*BEGIN*Bonjour John, comment ça va?*END*")); + + Assert.That(await _renderer.RenderAsync( Templates.SayHelloEmail, new SayHelloEmailModel("John"), cultureName: "de" - )); + ), Is.EqualTo("*BEGIN*Hallo John, wie geht es Dir?*END*")); } [Test] public async Task Should_Get_Localized_Numbers() { - Assert.AreEqual("*BEGIN*123.45*END*", await _renderer.RenderAsync( + Assert.That(await _renderer.RenderAsync( Templates.ShowDecimalNumber, new Dictionary(new List> {new KeyValuePair("amount", 123.45M)}), cultureName: "en" - )); - - Assert.AreEqual("*BEGIN*123,45*END*", await _renderer.RenderAsync( + ), Is.EqualTo("*BEGIN*123.45*END*")); + + Assert.That(await _renderer.RenderAsync( Templates.ShowDecimalNumber, new Dictionary(new List> {new KeyValuePair("amount", 123.45M)}), cultureName: "de" - )); + ), Is.EqualTo("*BEGIN*123,45*END*")); } private class WelcomeEmailModel @@ -141,4 +146,4 @@ public SayHelloEmailModel(string name) Name = name; } } -} \ No newline at end of file +} diff --git a/Src/Axuno.TextTemplating.Tests/TextTemplatingOptionsTests.cs b/Src/Axuno.TextTemplating.Tests/TextTemplatingOptionsTests.cs index 41e7055..7bef693 100644 --- a/Src/Axuno.TextTemplating.Tests/TextTemplatingOptionsTests.cs +++ b/Src/Axuno.TextTemplating.Tests/TextTemplatingOptionsTests.cs @@ -20,6 +20,6 @@ public TextTemplatingOptionsTests() [Test] public void Should_Auto_Add_TemplateDefinitionProviders_To_Options() { - Assert.Contains(typeof(TestTemplateDefinitionProvider), _options.DefinitionProviders.ToList()); + Assert.That(_options.DefinitionProviders.ToList(), Does.Contain(typeof(TestTemplateDefinitionProvider))); } -} \ No newline at end of file +} diff --git a/Src/Axuno.TextTemplating.Tests/VirtualFiles/LocalizedTemplateContentReaderFactoryTests.cs b/Src/Axuno.TextTemplating.Tests/VirtualFiles/LocalizedTemplateContentReaderFactoryTests.cs index f9978b9..5ec7c19 100644 --- a/Src/Axuno.TextTemplating.Tests/VirtualFiles/LocalizedTemplateContentReaderFactoryTests.cs +++ b/Src/Axuno.TextTemplating.Tests/VirtualFiles/LocalizedTemplateContentReaderFactoryTests.cs @@ -30,8 +30,8 @@ public async Task Create_Should_Work_With_PhysicalFileProvider() var reader = await localizedTemplateContentReaderFactory.CreateAsync(_templateDefinitionManager.Get(Templates.WelcomeEmail)!); - Assert.AreEqual(reader.GetContent("en"), "Welcome {{model.name}} to Axuno.TextTemplating!"); - Assert.AreEqual(reader.GetContent("de"), "Willkommen, {{model.name}}, bei Axuno.TextTemplating!"); + Assert.That(reader.GetContent("en"), Is.EqualTo("Welcome {{model.name}} to Axuno.TextTemplating!")); + Assert.That(reader.GetContent("de"), Is.EqualTo("Willkommen, {{model.name}}, bei Axuno.TextTemplating!")); } private class TestPhysicalVirtualFileProvider : IFileProvider @@ -58,4 +58,4 @@ public IChangeToken Watch(string filter) return _physicalFileProvider.Watch(filter); } } -} \ No newline at end of file +} diff --git a/Src/Axuno.TextTemplating.Tests/VirtualFiles/VirtualFileTemplateContributorTests.cs b/Src/Axuno.TextTemplating.Tests/VirtualFiles/VirtualFileTemplateContributorTests.cs index ffa6484..8ce2b0d 100644 --- a/Src/Axuno.TextTemplating.Tests/VirtualFiles/VirtualFileTemplateContributorTests.cs +++ b/Src/Axuno.TextTemplating.Tests/VirtualFiles/VirtualFileTemplateContributorTests.cs @@ -9,7 +9,7 @@ namespace Axuno.TextTemplating.Tests.VirtualFiles; [TestFixture] public class VirtualFileTemplateContributorTests { - private readonly IServiceProvider _services; + private readonly ServiceProvider _services; private readonly ITemplateDefinitionManager _templateDefinitionManager; private readonly VirtualFileTemplateContentContributor _virtualFileTemplateContentContributor; @@ -20,29 +20,32 @@ public VirtualFileTemplateContributorTests() _virtualFileTemplateContentContributor = _services.GetRequiredService(); } + [OneTimeTearDown] + public void CleanUp() + { + _services.Dispose(); + } + [Test] public async Task Should_Get_Localized_Content_By_Culture() { - Assert.AreEqual("Welcome {{model.name}} to Axuno.TextTemplating!", - await _virtualFileTemplateContentContributor.GetAsync( + Assert.That(await _virtualFileTemplateContentContributor.GetAsync( new TemplateContentContributorContext(_templateDefinitionManager.Get(Templates.WelcomeEmail)!, _services, - "en"))); - - Assert.AreEqual("Willkommen, {{model.name}}, bei Axuno.TextTemplating!", - await _virtualFileTemplateContentContributor.GetAsync( + "en")), Is.EqualTo("Welcome {{model.name}} to Axuno.TextTemplating!")); + + Assert.That(await _virtualFileTemplateContentContributor.GetAsync( new TemplateContentContributorContext(_templateDefinitionManager.Get(Templates.WelcomeEmail)!, _services, - "de"))); + "de")), Is.EqualTo("Willkommen, {{model.name}}, bei Axuno.TextTemplating!")); } [Test] public async Task Should_Get_Non_Localized_Template_Content() { - Assert.AreEqual("{{ L \"HelloText\" model.name}}, {{ L \"HowAreYou\" }}", - await _virtualFileTemplateContentContributor.GetAsync( + Assert.That(await _virtualFileTemplateContentContributor.GetAsync( new TemplateContentContributorContext(_templateDefinitionManager.Get(Templates.SayHelloEmail)!, _services, - null))); + null)), Is.EqualTo("{{ L \"HelloText\" model.name}}, {{ L \"HowAreYou\" }}")); } -} \ No newline at end of file +} diff --git a/Src/Axuno.TextTemplating/Axuno.TextTemplating.csproj b/Src/Axuno.TextTemplating/Axuno.TextTemplating.csproj index 284ce1d..48fbde3 100644 --- a/Src/Axuno.TextTemplating/Axuno.TextTemplating.csproj +++ b/Src/Axuno.TextTemplating/Axuno.TextTemplating.csproj @@ -1,7 +1,6 @@  - - netstandard2.1;net60 + netstandard2.1;net60;net80 enable $(NoWarn);1591 Text templating is used to dynamically render contents based on a template and a model. @@ -25,16 +24,13 @@ The library is a modified version of the lightweight TextTemplating.Scriban part Git TextTemplating.png https://github.com/axuno/Axuno.TextTemplating - Bumped to v2.0.0 -Breaking changes caused by updated dependencies + Library - DEBUG;TRACE - bin\Release\ bin\Release\Axuno.TextTemplating.xml @@ -44,35 +40,28 @@ Breaking changes caused by updated dependencies true true - - - - - - - + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - True - - - - <_Parameter1>Axuno.TextTemplating.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d1a4e14b1bc90a8278973eb1fb32c4161de835aaa1e67b9e5f6dd4e7cedc5c12aa31cf43fd57659df045a1941bd4b0192247c8671312abe95c974deb5319e6a071d314d6368b7826f4281e15b5f67891b349fd52e7d1fd238813d7dd22e83ad21251547633da3bb1d3680956bdeca4840b45da7244287d9b0beef181dc59bbc9 - diff --git a/Src/TextTemplatingDemo/Program.cs b/Src/TextTemplatingDemo/Program.cs index ac39155..4936f52 100644 --- a/Src/TextTemplatingDemo/Program.cs +++ b/Src/TextTemplatingDemo/Program.cs @@ -35,45 +35,45 @@ private static void ConfigureServices(IServiceCollection services) Services = services.BuildServiceProvider(); } - static async Task Main() + public static async Task Main() { ConfigureServices(new ServiceCollection()); // This will return the renderer registered as the last var renderer = Services.GetRequiredService(); - Console.WriteLine("*** Hello Template from TemplateContentProider ***"); + Console.WriteLine(@"*** Hello Template from TemplateContentProider ***"); var templateContentDemo = Services.GetRequiredService(); Console.WriteLine(await templateContentDemo.GetContentAsync("Hello")); Console.WriteLine(); - Console.WriteLine("*** Rendering Hello Template with class model ***"); + Console.WriteLine(@"*** Rendering Hello Template with class model ***"); await new HelloDemo(renderer).RunAsync(); - Console.WriteLine("*** Rendering Hello Template with anonymous model ***"); + Console.WriteLine(@"*** Rendering Hello Template with anonymous model ***"); await new HelloDemo(renderer).RunWithAnonymousModelAsync(); Console.WriteLine(); - Console.WriteLine("*** Rendering from Global context ***"); + Console.WriteLine(@"*** Rendering from Global context ***"); await new TextTemplateDemo.Demos.GlobalContext.GlobalContextUsageDemo(renderer).RunAsync(); Console.WriteLine(); - Console.WriteLine("*** Rendering Password Reset Template (localized inline) ***"); - Console.WriteLine("*** English ***"); + Console.WriteLine(@"*** Rendering Password Reset Template (localized inline) ***"); + Console.WriteLine(@"*** English ***"); await new PasswordResetDemo(renderer).RunAsync("en"); - Console.WriteLine("*** German ***"); + Console.WriteLine(@"*** German ***"); await new PasswordResetDemo(renderer).RunAsync("de"); Console.WriteLine(); - Console.WriteLine("*** Separate WelcomeEmail Templates from embedded resources, with Layout (localized) ***"); + Console.WriteLine(@"*** Separate WelcomeEmail Templates from embedded resources, with Layout (localized) ***"); Console.WriteLine(); - Console.WriteLine("*** English ***"); + Console.WriteLine(@"*** English ***"); await new WelcomeEmailDemo(renderer).RunAsync("en"); Console.WriteLine(); - Console.WriteLine("*** Spanish ***"); + Console.WriteLine(@"*** Spanish ***"); await new WelcomeEmailDemo(renderer).RunAsync("es"); Console.WriteLine(); - Console.WriteLine("*** Custom renderer demo ***"); + Console.WriteLine(@"*** Custom renderer demo ***"); await new CustomRendererDemo(Services).RunAsync(); Console.WriteLine(); } @@ -83,9 +83,9 @@ public static string AssemblyDirectory get { var location = Assembly.GetExecutingAssembly().Location; - UriBuilder uri = new UriBuilder(location); + var uri = new UriBuilder(location); var path = Uri.UnescapeDataString(uri.Path); return Path.GetDirectoryName(path)!; } } -} \ No newline at end of file +} diff --git a/Src/TextTemplatingDemo/TextTemplatingDemo.csproj b/Src/TextTemplatingDemo/TextTemplatingDemo.csproj index 0940fee..76d2cb2 100644 --- a/Src/TextTemplatingDemo/TextTemplatingDemo.csproj +++ b/Src/TextTemplatingDemo/TextTemplatingDemo.csproj @@ -2,7 +2,7 @@ Exe - net60 + net80 latest enable @@ -22,8 +22,8 @@ - - + +