Skip to content

Commit f3caa97

Browse files
authored
Bug/158 localization issue (#159)
* #158 fixed registration of ILocalizationManager * #158 added tests for localization message
1 parent 2e4b09c commit f3caa97

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserStartup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public override IServiceCollection ConfigureServices(IServiceCollection services
2828
services.AddSingleton<ITimeoutConfiguration>(serviceProvider => new TimeoutConfiguration(settings));
2929
services.AddSingleton<CoreTimeoutConfiguration>(serviceProvider => new TimeoutConfiguration(settings));
3030
services.AddSingleton<IBrowserProfile>(serviceProvider => new BrowserProfile(settings));
31-
services.AddSingleton(serviceProvider => new LocalizationManager(serviceProvider.GetRequiredService<ILoggerConfiguration>(), serviceProvider.GetRequiredService<Logger>(), Assembly.GetExecutingAssembly()));
31+
services.AddSingleton<ILocalizationManager>(serviceProvider => new LocalizationManager(serviceProvider.GetRequiredService<ILoggerConfiguration>(), serviceProvider.GetRequiredService<Logger>(), Assembly.GetExecutingAssembly()));
3232
services.AddTransient(serviceProvider => BrowserManager.BrowserFactory);
3333
return services;
3434
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.IO;
3+
using System.Linq;
4+
using Aquality.Selenium.Browsers;
5+
using NUnit.Framework;
6+
using Aquality.Selenium.Core.Localization;
7+
8+
namespace Aquality.Selenium.Tests.Unit
9+
{
10+
[TestFixture]
11+
[Parallelizable(ParallelScope.All)]
12+
internal class LocalizationManagerTests
13+
{
14+
private const string LocalizedNavigationMessage = "Navigate to url - 'test'";
15+
private const string LogPath = "../../../Log/log.log";
16+
private const string TestUrl = "test";
17+
private const string NavigationKey = "loc.browser.navigate";
18+
private static ILocalizedLogger LocalizedLogger => BrowserManager.GetRequiredService<ILocalizedLogger>();
19+
private static ILocalizationManager LocalizationManager => BrowserManager.GetRequiredService<ILocalizationManager>();
20+
21+
[TestCase(LogLevel.Info)]
22+
[TestCase(LogLevel.Debug)]
23+
[TestCase(LogLevel.Error)]
24+
[TestCase(LogLevel.Fatal)]
25+
[TestCase(LogLevel.Warn)]
26+
[Parallelizable(ParallelScope.None)]
27+
public void Should_BeAble_LogLocalizedMessage(LogLevel logLevel)
28+
{
29+
switch (logLevel)
30+
{
31+
case LogLevel.Info:
32+
LocalizedLogger.Info(NavigationKey, TestUrl);
33+
break;
34+
case LogLevel.Debug:
35+
LocalizedLogger.Debug(NavigationKey, null, TestUrl);
36+
break;
37+
case LogLevel.Error:
38+
LocalizedLogger.Error(NavigationKey, TestUrl);
39+
break;
40+
case LogLevel.Fatal:
41+
LocalizedLogger.Fatal(NavigationKey, null, TestUrl);
42+
break;
43+
case LogLevel.Warn:
44+
LocalizedLogger.Warn(NavigationKey, TestUrl);
45+
break;
46+
default:
47+
throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, "Cannot process log level");
48+
}
49+
50+
var logMessage = File.ReadAllLines(LogPath).LastOrDefault();
51+
Assert.IsFalse(string.IsNullOrEmpty(logMessage), "Message should appear in log file");
52+
Assert.IsTrue(logMessage.Contains(LocalizedNavigationMessage),
53+
$"Message should be localized. Expected: {LocalizedNavigationMessage}, actual: {logMessage}");
54+
}
55+
56+
[Test]
57+
public void Should_BeAble_ToLocalizeLoggerMessage()
58+
{
59+
var message = LocalizationManager.GetLocalizedMessage("loc.browser.navigate", "test");
60+
Assert.AreEqual(LocalizedNavigationMessage, message, "Message should be localized");
61+
}
62+
63+
public enum LogLevel
64+
{
65+
Info,
66+
Debug,
67+
Error,
68+
Fatal,
69+
Warn
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)