Split Geekbot.net into src/Bot, src/Core, and src/Web
This commit is contained in:
parent
7b6dd2d2f9
commit
fc0af492ad
197 changed files with 542 additions and 498 deletions
71
Tests/Core/Localization/TranslationGuildContext.test.cs
Normal file
71
Tests/Core/Localization/TranslationGuildContext.test.cs
Normal file
|
@ -0,0 +1,71 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Geekbot.Core.Localization;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Tests.Core.Localization
|
||||
{
|
||||
public class TranslationGuildContext_test
|
||||
{
|
||||
public class FormatDateTimeAsRemainingTestDto
|
||||
{
|
||||
public DateTimeOffset DateTime { get; set; }
|
||||
public string Expected { get; set; }
|
||||
}
|
||||
|
||||
public static TestData<FormatDateTimeAsRemainingTestDto> FormatDateTimeAsRemainingData =>
|
||||
new TestData<FormatDateTimeAsRemainingTestDto>
|
||||
{
|
||||
{
|
||||
"Wait for days",
|
||||
new FormatDateTimeAsRemainingTestDto
|
||||
{
|
||||
DateTime = DateTimeOffset.Now.AddDays(5),
|
||||
Expected = "4 days, 23 hours, 59 minutes and 59 seconds"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Wait for minutes",
|
||||
new FormatDateTimeAsRemainingTestDto
|
||||
{
|
||||
DateTime = DateTimeOffset.Now.AddMinutes(5),
|
||||
Expected = "4 minutes and 59 seconds"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Wait for seconds",
|
||||
new FormatDateTimeAsRemainingTestDto
|
||||
{
|
||||
DateTime = DateTimeOffset.Now.AddSeconds(5),
|
||||
Expected = "4 seconds"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
[Theory, MemberData(nameof(FormatDateTimeAsRemainingData))]
|
||||
public void FormatDateTimeAsRemaining(string testName, FormatDateTimeAsRemainingTestDto testData)
|
||||
{
|
||||
var translationHandlerMock = new Mock<ITranslationHandler>(MockBehavior.Loose);
|
||||
translationHandlerMock
|
||||
.Setup(thm => thm.GetString("EN", "dateTime", "Days"))
|
||||
.Returns("day|days");
|
||||
translationHandlerMock
|
||||
.Setup(thm => thm.GetString("EN", "dateTime", "Hours"))
|
||||
.Returns("hour|hours");
|
||||
translationHandlerMock
|
||||
.Setup(thm => thm.GetString("EN", "dateTime", "Minutes"))
|
||||
.Returns("minute|minutes");
|
||||
translationHandlerMock
|
||||
.Setup(thm => thm.GetString("EN", "dateTime", "Seconds"))
|
||||
.Returns("second|seconds");
|
||||
translationHandlerMock
|
||||
.Setup(thm => thm.GetString("EN", "dateTime", "And"))
|
||||
.Returns("and");
|
||||
|
||||
var context = new TranslationGuildContext(translationHandlerMock.Object, "EN", new Dictionary<string, string>());
|
||||
var result = context.FormatDateTimeAsRemaining(testData.DateTime);
|
||||
Assert.Equal(result, testData.Expected);
|
||||
}
|
||||
}
|
||||
}
|
46
Tests/Core/Localization/Translations.test.cs
Normal file
46
Tests/Core/Localization/Translations.test.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
using YamlDotNet.Core;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace Tests.Core.Localization
|
||||
{
|
||||
public class Translations_test
|
||||
{
|
||||
[Fact]
|
||||
public void TranslationsYamlIsValid()
|
||||
{
|
||||
// Read the file
|
||||
var translationFile = File.ReadAllText(Path.GetFullPath("./../../../../src/Core/Localization/Translations.yml"));
|
||||
|
||||
// Deserialize
|
||||
var input = new StringReader(translationFile);
|
||||
var mergingParser = new MergingParser(new Parser(input));
|
||||
var deserializer = new DeserializerBuilder().Build();
|
||||
var rawTranslations = deserializer.Deserialize<Dictionary<string, Dictionary<string, Dictionary<string, string>>>>(mergingParser);
|
||||
|
||||
// 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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue