From f3caa977f363ef48f7a18298a551b1ea96f0824e Mon Sep 17 00:00:00 2001 From: knysh Date: Thu, 19 Dec 2019 11:53:28 +0300 Subject: [PATCH] Bug/158 localization issue (#159) * #158 fixed registration of ILocalizationManager * #158 added tests for localization message --- .../Browsers/BrowserStartup.cs | 2 +- .../Unit/LocalizationManagerTests.cs | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/LocalizationManagerTests.cs diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserStartup.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserStartup.cs index 81565aae..406ebe58 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserStartup.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserStartup.cs @@ -28,7 +28,7 @@ public override IServiceCollection ConfigureServices(IServiceCollection services services.AddSingleton(serviceProvider => new TimeoutConfiguration(settings)); services.AddSingleton(serviceProvider => new TimeoutConfiguration(settings)); services.AddSingleton(serviceProvider => new BrowserProfile(settings)); - services.AddSingleton(serviceProvider => new LocalizationManager(serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService(), Assembly.GetExecutingAssembly())); + services.AddSingleton(serviceProvider => new LocalizationManager(serviceProvider.GetRequiredService(), serviceProvider.GetRequiredService(), Assembly.GetExecutingAssembly())); services.AddTransient(serviceProvider => BrowserManager.BrowserFactory); return services; } diff --git a/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/LocalizationManagerTests.cs b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/LocalizationManagerTests.cs new file mode 100644 index 00000000..d761de90 --- /dev/null +++ b/Aquality.Selenium/tests/Aquality.Selenium.Tests/Unit/LocalizationManagerTests.cs @@ -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(); + private static ILocalizationManager LocalizationManager => BrowserManager.GetRequiredService(); + + [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 + } + } +}