Skip to content

Commit

Permalink
Bug/158 localization issue (#159)
Browse files Browse the repository at this point in the history
* #158 fixed registration of ILocalizationManager

* #158 added tests for localization message
  • Loading branch information
knysh authored Dec 19, 2019
1 parent 2e4b09c commit f3caa97
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override IServiceCollection ConfigureServices(IServiceCollection services
services.AddSingleton<ITimeoutConfiguration>(serviceProvider => new TimeoutConfiguration(settings));
services.AddSingleton<CoreTimeoutConfiguration>(serviceProvider => new TimeoutConfiguration(settings));
services.AddSingleton<IBrowserProfile>(serviceProvider => new BrowserProfile(settings));
services.AddSingleton(serviceProvider => new LocalizationManager(serviceProvider.GetRequiredService<ILoggerConfiguration>(), serviceProvider.GetRequiredService<Logger>(), Assembly.GetExecutingAssembly()));
services.AddSingleton<ILocalizationManager>(serviceProvider => new LocalizationManager(serviceProvider.GetRequiredService<ILoggerConfiguration>(), serviceProvider.GetRequiredService<Logger>(), Assembly.GetExecutingAssembly()));
services.AddTransient(serviceProvider => BrowserManager.BrowserFactory);
return services;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.IO;
using System.Linq;
using Aquality.Selenium.Browsers;
using NUnit.Framework;
using Aquality.Selenium.Core.Localization;

namespace Aquality.Selenium.Tests.Unit
{
[TestFixture]
[Parallelizable(ParallelScope.All)]
internal class LocalizationManagerTests
{
private const string LocalizedNavigationMessage = "Navigate to url - 'test'";
private const string LogPath = "../../../Log/log.log";
private const string TestUrl = "test";
private const string NavigationKey = "loc.browser.navigate";
private static ILocalizedLogger LocalizedLogger => BrowserManager.GetRequiredService<ILocalizedLogger>();
private static ILocalizationManager LocalizationManager => BrowserManager.GetRequiredService<ILocalizationManager>();

[TestCase(LogLevel.Info)]
[TestCase(LogLevel.Debug)]
[TestCase(LogLevel.Error)]
[TestCase(LogLevel.Fatal)]
[TestCase(LogLevel.Warn)]
[Parallelizable(ParallelScope.None)]
public void Should_BeAble_LogLocalizedMessage(LogLevel logLevel)
{
switch (logLevel)
{
case LogLevel.Info:
LocalizedLogger.Info(NavigationKey, TestUrl);
break;
case LogLevel.Debug:
LocalizedLogger.Debug(NavigationKey, null, TestUrl);
break;
case LogLevel.Error:
LocalizedLogger.Error(NavigationKey, TestUrl);
break;
case LogLevel.Fatal:
LocalizedLogger.Fatal(NavigationKey, null, TestUrl);
break;
case LogLevel.Warn:
LocalizedLogger.Warn(NavigationKey, TestUrl);
break;
default:
throw new ArgumentOutOfRangeException(nameof(logLevel), logLevel, "Cannot process log level");
}

var logMessage = File.ReadAllLines(LogPath).LastOrDefault();
Assert.IsFalse(string.IsNullOrEmpty(logMessage), "Message should appear in log file");
Assert.IsTrue(logMessage.Contains(LocalizedNavigationMessage),
$"Message should be localized. Expected: {LocalizedNavigationMessage}, actual: {logMessage}");
}

[Test]
public void Should_BeAble_ToLocalizeLoggerMessage()
{
var message = LocalizationManager.GetLocalizedMessage("loc.browser.navigate", "test");
Assert.AreEqual(LocalizedNavigationMessage, message, "Message should be localized");
}

public enum LogLevel
{
Info,
Debug,
Error,
Fatal,
Warn
}
}
}

0 comments on commit f3caa97

Please sign in to comment.