Skip to content

Commit cc45095

Browse files
authored
extract i localization manager (#27)
* exstracted interfaces for LocalizationManager and LocalizationManager * updated LocalizationManagerTests * #23 renamed LocalizationLogger to LocalizedLogger * changed AddTransient to AddSingleton
1 parent 83dcd68 commit cc45095

File tree

12 files changed

+103
-34
lines changed

12 files changed

+103
-34
lines changed

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Applications/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public void ConfigureServices(IServiceCollection services, Func<IServiceProvider
3434
services.AddTransient<ConditionalWait>();
3535
services.AddSingleton<ILoggerConfiguration>(new LoggerConfiguration(settingsFile));
3636
services.AddSingleton(Logger.Instance);
37-
services.AddSingleton<LocalizationManager>();
38-
services.AddSingleton<LocalizationLogger>();
37+
services.AddSingleton<ILocalizationManager, LocalizationManager>();
38+
services.AddSingleton<ILocalizedLogger, LocalizedLogger>();
3939
services.AddSingleton<IRetryConfiguration>(new RetryConfiguration(settingsFile));
4040
services.AddSingleton<ElementActionRetrier>();
4141

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Aquality.Selenium.Core.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/Element.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected Element(By locator, string name, ElementState state)
4242

4343
protected abstract IElementFinder Finder { get; }
4444

45-
protected abstract LocalizationLogger LocalizationLogger { get; }
45+
protected abstract ILocalizedLogger LocalizedLogger { get; }
4646

4747
protected virtual Logger Logger => Logger.Instance;
4848

@@ -103,7 +103,7 @@ protected virtual T DoWithRetry<T>(Func<T> function)
103103

104104
protected virtual void LogElementAction(string messageKey, params object[] args)
105105
{
106-
LocalizationLogger.InfoElementAction(ElementType, Name, messageKey, args);
106+
LocalizedLogger.InfoElementAction(ElementType, Name, messageKey, args);
107107
}
108108
}
109109
}

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/ElementFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ElementFactory : IElementFactory
1717
{
1818
private const string ByXpathIdentifier = "By.XPath";
1919

20-
public ElementFactory(ConditionalWait conditionalWait, IElementFinder elementFinder, LocalizationManager localizationManager)
20+
public ElementFactory(ConditionalWait conditionalWait, IElementFinder elementFinder, ILocalizationManager localizationManager)
2121
{
2222
ConditionalWait = conditionalWait;
2323
ElementFinder = elementFinder;
@@ -28,7 +28,7 @@ public ElementFactory(ConditionalWait conditionalWait, IElementFinder elementFin
2828

2929
protected IElementFinder ElementFinder { get; }
3030

31-
protected LocalizationManager LocalizationManager { get; }
31+
protected ILocalizationManager LocalizationManager { get; }
3232

3333
/// <summary>
3434
/// Gets map between elements interfaces and their implementations.

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Elements/ElementFinder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ namespace Aquality.Selenium.Core.Elements
1515
/// </summary>
1616
public class ElementFinder : IElementFinder
1717
{
18-
public ElementFinder(Logger logger, LocalizationLogger localizationLogger, LocalizationManager localizationManager, ConditionalWait conditionalWait)
18+
public ElementFinder(Logger logger, ILocalizedLogger localizedLogger, ILocalizationManager localizationManager, ConditionalWait conditionalWait)
1919
{
2020
Logger = logger;
21-
LocalizationLogger = localizationLogger;
21+
LocalizedLogger = localizedLogger;
2222
LocalizationManager = localizationManager;
2323
ConditionalWait = conditionalWait;
2424
}
2525

2626
private Logger Logger { get; }
2727

28-
private LocalizationLogger LocalizationLogger { get; }
28+
private ILocalizedLogger LocalizedLogger { get; }
2929

30-
private LocalizationManager LocalizationManager { get; }
30+
private ILocalizationManager LocalizationManager { get; }
3131

3232
private ConditionalWait ConditionalWait { get; }
3333

@@ -103,7 +103,7 @@ private void HandleTimeoutException(WebDriverTimeoutException ex, DesiredState d
103103
}
104104
else
105105
{
106-
LocalizationLogger.Debug("loc.elements.were.found.but.not.in.state", null, locator.ToString(), desiredState.StateName);
106+
LocalizedLogger.Debug("loc.elements.were.found.but.not.in.state", null, locator.ToString(), desiredState.StateName);
107107
}
108108
}
109109
else
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace Aquality.Selenium.Core.Localization
2+
{
3+
/// <summary>
4+
/// This interface is using for translation messages to different languages
5+
/// </summary>
6+
public interface ILocalizationManager
7+
{
8+
/// <summary>
9+
/// Get localized message from resources by its key.
10+
/// </summary>
11+
/// <param name="messageKey">Key in resource file.</param>
12+
/// <param name="args">Arguments, which will be provided to template of localized message.</param>
13+
/// <returns>Localized message.</returns>
14+
string GetLocalizedMessage(string messageKey, params object[] args);
15+
}
16+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using System;
2+
3+
namespace Aquality.Selenium.Core.Localization
4+
{
5+
/// <summary>
6+
/// Log messages to different languages
7+
/// </summary>
8+
public interface ILocalizedLogger
9+
{
10+
/// <summary>
11+
/// Logs localized message for action with INFO level which is applied for element, for example, click, send keys etc.
12+
/// </summary>
13+
/// <param name="elementType">Type of the element.</param>
14+
/// <param name="elementName">Name of the element.</param>
15+
/// <param name="messageKey">Key in resource file.</param>
16+
/// <param name="args">Arguments, which will be provided to template of localized message.</param>
17+
void InfoElementAction(string elementType, string elementName, string messageKey, params object[] args);
18+
19+
/// <summary>
20+
/// Logs localized message with INFO level.
21+
/// </summary>
22+
/// <param name="messageKey">Key in resource file.</param>
23+
/// <param name="args">Arguments, which will be provided to template of localized message.</param>
24+
void Info(string messageKey, params object[] args);
25+
26+
/// <summary>
27+
/// Logs localized message with DEBUG level.
28+
/// </summary>
29+
/// <param name="messageKey">Key in resource file.</param>
30+
/// <param name="exception">Exception, gets null value by default.</param>
31+
/// <param name="args">Arguments, which will be provided to template of localized message.</param>
32+
void Debug(string messageKey, Exception exception = null, params object[] args);
33+
34+
/// <summary>
35+
/// Logs localized message with WARN level.
36+
/// </summary>
37+
/// <param name="messageKey">Key in resource file.</param>
38+
/// <param name="args">Arguments, which will be provided to template of localized message.</param>
39+
void Warn(string messageKey, params object[] args);
40+
41+
/// <summary>
42+
/// Logs localized message with ERROR level.
43+
/// </summary>
44+
/// <param name="messageKey">Key in resource file.</param>
45+
/// <param name="args">Arguments, which will be provided to template of localized message.</param>
46+
void Error(string messageKey, params object[] args);
47+
48+
/// <summary>
49+
/// Logs localized message with FATAL level.
50+
/// </summary>
51+
/// <param name="messageKey">Key in resource file.</param>
52+
/// <param name="exception">Exception, gets null value by default.</param>
53+
/// <param name="args">Arguments, which will be provided to template of localized message.</param>
54+
void Fatal(string messageKey, Exception exception = null, params object[] args);
55+
}
56+
}

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Localization/LocalizationManager.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55

66
namespace Aquality.Selenium.Core.Localization
77
{
8-
/// <summary>
9-
/// This class is using for translation messages to different languages
10-
/// </summary>
11-
public class LocalizationManager
8+
public class LocalizationManager : ILocalizationManager
129
{
1310
private const string LangResource = "Resources.Localization.{0}.json";
14-
private readonly JsonSettingsFile localizationFile;
11+
private readonly ISettingsFile localizationFile;
1512
private readonly Logger logger;
1613

1714
public LocalizationManager(ILoggerConfiguration loggerConfiguration, Logger logger, Assembly assembly = null)
@@ -21,12 +18,6 @@ public LocalizationManager(ILoggerConfiguration loggerConfiguration, Logger logg
2118
this.logger = logger;
2219
}
2320

24-
/// <summary>
25-
/// Get localized message from resources by its key.
26-
/// </summary>
27-
/// <param name="messageKey">Key in resource file.</param>
28-
/// <param name="args">Arguments, which will be provided to template of localized message.</param>
29-
/// <returns>Localized message.</returns>
3021
public string GetLocalizedMessage(string messageKey, params object[] args)
3122
{
3223
var jsonKey = $"$['{messageKey}']";

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Localization/LocalizationLogger.cs renamed to Aquality.Selenium.Core/src/Aquality.Selenium.Core/Localization/LocalizedLogger.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33

44
namespace Aquality.Selenium.Core.Localization
55
{
6-
/// <summary>
7-
/// Log messages to different languages
8-
/// </summary>
9-
public class LocalizationLogger
6+
public class LocalizedLogger : ILocalizedLogger
107
{
11-
private readonly LocalizationManager localizationManager;
8+
private readonly ILocalizationManager localizationManager;
129
private readonly Logger logger;
1310

14-
public LocalizationLogger(LocalizationManager localizationManager, Logger logger)
11+
public LocalizedLogger(ILocalizationManager localizationManager, Logger logger)
1512
{
1613
this.localizationManager = localizationManager;
1714
this.logger = logger;

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/Browser/ApplicationNotStartedTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public class ApplicationNotStartedTests : TestWithBrowser
1717
typeof(ElementActionRetrier),
1818
typeof(ConditionalWait),
1919
typeof(Logger),
20-
typeof(LocalizationManager),
21-
typeof(LocalizationLogger),
20+
typeof(ILocalizationManager),
21+
typeof(ILocalizedLogger),
2222
typeof(IElementFinder),
2323
typeof(IElementFactory),
2424
typeof(ITimeoutConfiguration),

0 commit comments

Comments
 (0)