|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Shouldly;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
@ -19,7 +20,85 @@ namespace Volo.Abp.TextTemplating
|
|
|
|
|
var content = await _templateRenderer.RenderAsync(
|
|
|
|
|
TestTemplates.ForgotPasswordEmail
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
content.ShouldBe("Please click to the following link to get an email to reset your password!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Should_Get_Rendered_Localized_Template_Content_With_Different_Cultures()
|
|
|
|
|
{
|
|
|
|
|
(await _templateRenderer.RenderAsync(
|
|
|
|
|
TestTemplates.WelcomeEmail,
|
|
|
|
|
model: new
|
|
|
|
|
{
|
|
|
|
|
name = "John"
|
|
|
|
|
},
|
|
|
|
|
cultureName: "en"
|
|
|
|
|
)).ShouldBe("Welcome John to the abp.io!");
|
|
|
|
|
|
|
|
|
|
(await _templateRenderer.RenderAsync(
|
|
|
|
|
TestTemplates.WelcomeEmail,
|
|
|
|
|
model: new
|
|
|
|
|
{
|
|
|
|
|
name = "John"
|
|
|
|
|
},
|
|
|
|
|
cultureName: "tr"
|
|
|
|
|
)).ShouldBe("Merhaba John, abp.io'ya hoşgeldiniz!");
|
|
|
|
|
|
|
|
|
|
//"en-US" fallbacks to "en" since "en-US" doesn't exists and "en" is the fallback culture
|
|
|
|
|
(await _templateRenderer.RenderAsync(
|
|
|
|
|
TestTemplates.WelcomeEmail,
|
|
|
|
|
model: new
|
|
|
|
|
{
|
|
|
|
|
name = "John"
|
|
|
|
|
},
|
|
|
|
|
cultureName: "en-US"
|
|
|
|
|
)).ShouldBe("Welcome John to the abp.io!");
|
|
|
|
|
|
|
|
|
|
//"fr" fallbacks to "en" since "fr" doesn't exists and "en" is the default culture
|
|
|
|
|
(await _templateRenderer.RenderAsync(
|
|
|
|
|
TestTemplates.WelcomeEmail,
|
|
|
|
|
model: new
|
|
|
|
|
{
|
|
|
|
|
Name = "John" //Intentionally written as PascalCase since Scriban supports it
|
|
|
|
|
},
|
|
|
|
|
cultureName: "fr"
|
|
|
|
|
)).ShouldBe("Welcome John to the abp.io!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Should_Get_Rendered_Localized_Template_Content_With_Stronly_Typed_Model()
|
|
|
|
|
{
|
|
|
|
|
(await _templateRenderer.RenderAsync(
|
|
|
|
|
TestTemplates.WelcomeEmail,
|
|
|
|
|
model: new WelcomeEmailModel("John"),
|
|
|
|
|
cultureName: "en"
|
|
|
|
|
)).ShouldBe("Welcome John to the abp.io!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public async Task Should_Get_Rendered_Localized_Template_Content_With_Dictionary_Model()
|
|
|
|
|
{
|
|
|
|
|
(await _templateRenderer.RenderAsync(
|
|
|
|
|
TestTemplates.WelcomeEmail,
|
|
|
|
|
model: new Dictionary<string, object>() { { "name", "John" } },
|
|
|
|
|
cultureName: "en"
|
|
|
|
|
)).ShouldBe("Welcome John to the abp.io!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class WelcomeEmailModel
|
|
|
|
|
{
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
public WelcomeEmailModel()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WelcomeEmailModel(string name)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|