From f5cd0ffcc8ba0fd5e6a3c2c6a873ae0032d69b03 Mon Sep 17 00:00:00 2001 From: runebaas Date: Sun, 12 May 2019 22:05:35 +0200 Subject: [PATCH] add unit test for making sure all translations keys exist --- Tests/Lib/Localization/Translations.test.cs | 44 +++++++++++++++++++++ Tests/Tests.csproj | 2 + 2 files changed, 46 insertions(+) create mode 100644 Tests/Lib/Localization/Translations.test.cs diff --git a/Tests/Lib/Localization/Translations.test.cs b/Tests/Lib/Localization/Translations.test.cs new file mode 100644 index 0000000..fc43091 --- /dev/null +++ b/Tests/Lib/Localization/Translations.test.cs @@ -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>>>(input); + + // These languages must be supported + var supportedLanguages = new List + { + "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}"); + } + } + } + } + } +} \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 771a9d4..1c07b9c 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -6,11 +6,13 @@ xUnit1026 + +