2019-05-12 01:59:55 +02:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Geekbot.net.Lib.Localization;
|
|
|
|
using Moq;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Tests.Lib.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
|
2019-05-12 15:57:58 +02:00
|
|
|
.Setup(thm => thm.GetString("EN", "dateTime", "Days"))
|
|
|
|
.Returns("day|days");
|
2019-05-12 01:59:55 +02:00
|
|
|
translationHandlerMock
|
2019-05-12 15:57:58 +02:00
|
|
|
.Setup(thm => thm.GetString("EN", "dateTime", "Hours"))
|
|
|
|
.Returns("hour|hours");
|
2019-05-12 01:59:55 +02:00
|
|
|
translationHandlerMock
|
2019-05-12 15:57:58 +02:00
|
|
|
.Setup(thm => thm.GetString("EN", "dateTime", "Minutes"))
|
|
|
|
.Returns("minute|minutes");
|
2019-05-12 01:59:55 +02:00
|
|
|
translationHandlerMock
|
2019-05-12 15:57:58 +02:00
|
|
|
.Setup(thm => thm.GetString("EN", "dateTime", "Seconds"))
|
|
|
|
.Returns("second|seconds");
|
2019-05-12 01:59:55 +02:00
|
|
|
translationHandlerMock
|
2019-05-12 15:57:58 +02:00
|
|
|
.Setup(thm => thm.GetString("EN", "dateTime", "And"))
|
|
|
|
.Returns("and");
|
2019-05-12 01:59:55 +02:00
|
|
|
|
2019-05-12 15:57:58 +02:00
|
|
|
var context = new TranslationGuildContext(translationHandlerMock.Object, "EN", new Dictionary<string, string>());
|
2019-05-12 01:59:55 +02:00
|
|
|
var result = context.FormatDateTimeAsRemaining(testData.DateTime);
|
|
|
|
Assert.Equal(result, testData.Expected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|