Skip to content

Commit

Permalink
Add net80 as target framework
Browse files Browse the repository at this point in the history
* Add net80 as target framework
* Update nuget packages to latests
* Update unit test to use the constraint model
* Bump version to v2.1.0
  • Loading branch information
axunonb committed Jul 3, 2024
1 parent b3c6397 commit 86b7873
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 101 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand Down
14 changes: 9 additions & 5 deletions Src/Axuno.TextTemplating.Tests/Axuno.TextTemplating.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\Axuno.TextTemplating\Axuno.TextTemplating.snk</AssemblyOriginatorKeyFile>
<Authors>axuno gGmbH</Authors>
Expand All @@ -16,10 +16,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 5 additions & 5 deletions Src/Axuno.TextTemplating.Tests/TemplateDefinitionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
63 changes: 34 additions & 29 deletions Src/Axuno.TextTemplating.Tests/TemplateRendererTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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()
Expand All @@ -18,108 +17,114 @@ public TemplateRendererTests()
_renderer = _services.GetRequiredService<ITemplateRenderer>();
}

[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<string, object> { { "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<string, decimal>(new List<KeyValuePair<string, decimal>> {new KeyValuePair<string, decimal>("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<string, decimal>(new List<KeyValuePair<string, decimal>> {new KeyValuePair<string, decimal>("amount", 123.45M)}),
cultureName: "de"
));
), Is.EqualTo("*BEGIN*123,45*END*"));
}

private class WelcomeEmailModel
Expand All @@ -141,4 +146,4 @@ public SayHelloEmailModel(string name)
Name = name;
}
}
}
}
4 changes: 2 additions & 2 deletions Src/Axuno.TextTemplating.Tests/TextTemplatingOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -58,4 +58,4 @@ public IChangeToken Watch(string filter)
return _physicalFileProvider.Watch(filter);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,29 +20,32 @@ public VirtualFileTemplateContributorTests()
_virtualFileTemplateContentContributor = _services.GetRequiredService<VirtualFileTemplateContentContributor>();
}

[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\" }}"));
}
}
}
Loading

0 comments on commit 86b7873

Please sign in to comment.