add unit test for making sure all translations keys exist
This commit is contained in:
parent
aef50aa2de
commit
f5cd0ffcc8
2 changed files with 46 additions and 0 deletions
44
Tests/Lib/Localization/Translations.test.cs
Normal file
44
Tests/Lib/Localization/Translations.test.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Tests.Lib.Localization
|
||||
{
|
||||
public class Translations_test
|
||||
{
|
||||
[Fact]
|
||||
public void TranslationsYamlIsValid()
|
||||
{
|
||||
// Read the file
|
||||
var translationFile = File.ReadAllText(Path.GetFullPath("./../../../../Geekbot.net/Lib/Localization/Translations.yml"));
|
||||
|
||||
// Deserialize
|
||||
var input = new StringReader(translationFile);
|
||||
var deserializer = new DeserializerBuilder().Build();
|
||||
var rawTranslations = deserializer.Deserialize<Dictionary<string, Dictionary<string, Dictionary<string, string>>>>(input);
|
||||
|
||||
// These languages must be supported
|
||||
var supportedLanguages = new List<string>
|
||||
{
|
||||
"EN",
|
||||
"CHDE"
|
||||
};
|
||||
|
||||
// Iterate every single key to make sure it's populated
|
||||
foreach (var command in rawTranslations)
|
||||
{
|
||||
foreach (var str in command.Value)
|
||||
{
|
||||
str.Value.Select(e => e.Key).ToList().Should().BeEquivalentTo(supportedLanguages, str.Key);
|
||||
foreach (var lang in str.Value)
|
||||
{
|
||||
lang.Value.Should().NotBeNullOrEmpty($"{command.Key} / {str.Key} / {lang.Key}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,11 +6,13 @@
|
|||
<NoWarn>xUnit1026</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version="5.6.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.0" />
|
||||
<PackageReference Include="Moq" Version="4.10.1" />
|
||||
<PackageReference Include="xunit" Version="2.4.1" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
|
||||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
|
||||
<PackageReference Include="YamlDotNet" Version="6.0.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Geekbot.net\Geekbot.net.csproj" />
|
||||
|
|
Loading…
Reference in a new issue