Skip to content

Commit 6d8771d

Browse files
committed
Add unit tests for template options
1 parent 9be6b0f commit 6d8771d

2 files changed

Lines changed: 64 additions & 1 deletion

File tree

src/OrchardCoreContrib.PoExtractor/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static void Main(string[] args)
3131
});
3232
var template = app.Option("-t|--template <TEMPLATE>", "Specifies the template engine to extract the translatable strings from.", CommandOptionType.SingleValue, option =>
3333
{
34-
option.Accepts(cfg => cfg.Values(TemplateEngine.Both, "Razor", "Liquid"));
34+
option.Accepts(cfg => cfg.Values(TemplateEngine.Both, TemplateEngine.Razor, TemplateEngine.Liquid));
3535
option.DefaultValue = TemplateEngine.Both;
3636
});
3737
var ignoredProjects = app.Option("-i|--ignore <IGNORED_PROJECTS>", "Ignores extracting PO files from a given project(s).", CommandOptionType.MultipleValue);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Xunit;
2+
3+
namespace OrchardCoreContrib.PoExtractor.Tests;
4+
5+
public class ProgramTests
6+
{
7+
[Fact]
8+
public void Main_NoTemplateOption_UsesBothRazorAndLiquid()
9+
{
10+
// Arrange
11+
var root = Path.Combine(Path.GetTempPath(), "PoExtractorTests", Guid.NewGuid().ToString("N"));
12+
var input = Path.Combine(root, "input");
13+
var output = Path.Combine(root, "output");
14+
var project = Path.Combine(input, "TestModule");
15+
16+
Directory.CreateDirectory(project);
17+
Directory.CreateDirectory(output);
18+
19+
File.WriteAllText(Path.Combine(project, "TestModule.csproj"), """
20+
<Project Sdk="Microsoft.NET.Sdk">
21+
<PropertyGroup>
22+
<TargetFramework>net10.0</TargetFramework>
23+
</PropertyGroup>
24+
</Project>
25+
""");
26+
27+
File.WriteAllText(Path.Combine(project, "Index.cshtml"), """
28+
@T["Hello from Razor"]
29+
""");
30+
31+
File.WriteAllText(Path.Combine(project, "index.liquid"), """
32+
{{ "Hello from Liquid" | t }}
33+
""");
34+
35+
var potFileName = "all.pot";
36+
37+
try
38+
{
39+
// Act
40+
Program.Main(
41+
[
42+
input,
43+
output,
44+
"--single", potFileName
45+
]);
46+
47+
// Assert
48+
var potPath = Path.Combine(output, potFileName);
49+
Assert.True(File.Exists(potPath));
50+
51+
var pot = File.ReadAllText(potPath);
52+
Assert.Contains("Hello from Razor", pot);
53+
Assert.Contains("Hello from Liquid", pot);
54+
}
55+
finally
56+
{
57+
if (Directory.Exists(root))
58+
{
59+
Directory.Delete(root, recursive: true);
60+
}
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)