-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added possibility to override default container with services added unit tests * set ParallelScope.None for CustomConfigurationTests * fixed parallel run for Custom Configuration * removed cast Startup to BrowserStartup * added dot * removed reduntant empty line * updated registration of BrowserFactory
- Loading branch information
Showing
5 changed files
with
138 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
Aquality.Selenium/src/Aquality.Selenium/Browsers/BrowserStartup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Aquality.Selenium.Elements; | ||
using Aquality.Selenium.Elements.Interfaces; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using Aquality.Selenium.Core.Localization; | ||
using Aquality.Selenium.Core.Logging; | ||
using System.Reflection; | ||
using Aquality.Selenium.Core.Applications; | ||
using Aquality.Selenium.Configurations; | ||
using Aquality.Selenium.Core.Configurations; | ||
using CoreElementFactory = Aquality.Selenium.Core.Elements.Interfaces.IElementFactory; | ||
using CoreTimeoutConfiguration = Aquality.Selenium.Core.Configurations.ITimeoutConfiguration; | ||
using ILoggerConfiguration = Aquality.Selenium.Core.Configurations.ILoggerConfiguration; | ||
using ITimeoutConfiguration = Aquality.Selenium.Configurations.ITimeoutConfiguration; | ||
using TimeoutConfiguration = Aquality.Selenium.Configurations.TimeoutConfiguration; | ||
|
||
namespace Aquality.Selenium.Browsers | ||
{ | ||
public class BrowserStartup : Startup | ||
{ | ||
public override IServiceCollection ConfigureServices(IServiceCollection services, Func<IServiceProvider, IApplication> applicationProvider, | ||
ISettingsFile settings = null) | ||
{ | ||
settings = settings ?? GetSettings(); | ||
base.ConfigureServices(services, applicationProvider, settings); | ||
services.AddTransient<IElementFactory, ElementFactory>(); | ||
services.AddTransient<CoreElementFactory, ElementFactory>(); | ||
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.AddTransient(serviceProvider => BrowserManager.BrowserFactory); | ||
return services; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ity.Selenium/tests/Aquality.Selenium.Tests/Unit/Configuration/CustomConfigurationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using Aquality.Selenium.Browsers; | ||
using Aquality.Selenium.Core.Applications; | ||
using Aquality.Selenium.Core.Configurations; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NUnit.Framework; | ||
|
||
namespace Aquality.Selenium.Tests.Unit.Configuration | ||
{ | ||
[TestFixture] | ||
[Parallelizable(ParallelScope.All)] | ||
internal class CustomConfigurationTests | ||
{ | ||
private const string SpecialLoggerLanguage = "SpecialLoggerLanguage"; | ||
private const string SpecialCustomValue = "SpecialCustomValue"; | ||
private static readonly TimeSpan DefaultCommandTimeout = TimeSpan.FromSeconds(60); | ||
|
||
[SetUp] | ||
public static void Before() | ||
{ | ||
BrowserManager.SetStartup(new CustomStartup()); | ||
} | ||
|
||
[Test] | ||
public void Should_BeAbleOverrideDependencies_AndGetCustomService() | ||
{ | ||
Assert.AreEqual(SpecialLoggerLanguage, BrowserManager.GetRequiredService<ILoggerConfiguration>().Language, "Configuration value should be overriden."); | ||
} | ||
|
||
[Test] | ||
public void Should_BeAbleAdd_CustomService() | ||
{ | ||
Assert.AreEqual(SpecialCustomValue, BrowserManager.GetRequiredService<ICustomService>().CustomValue, "Custom service should have value"); | ||
} | ||
|
||
[Test] | ||
public void Should_BeAbleGet_DefaultService() | ||
{ | ||
Assert.AreEqual(DefaultCommandTimeout, BrowserManager.GetRequiredService<ITimeoutConfiguration>().Command, "Default service value should have default value"); | ||
} | ||
|
||
[TearDown] | ||
public static void After() | ||
{ | ||
BrowserManager.SetStartup(new BrowserStartup()); | ||
} | ||
|
||
private class CustomLoggerConfiguration : ILoggerConfiguration | ||
{ | ||
public string Language { get; } = SpecialLoggerLanguage; | ||
} | ||
|
||
private interface ICustomService | ||
{ | ||
string CustomValue { get; } | ||
} | ||
|
||
private class CustomService : ICustomService | ||
{ | ||
public string CustomValue { get; } = SpecialCustomValue; | ||
} | ||
|
||
private class CustomStartup : BrowserStartup | ||
{ | ||
public override IServiceCollection ConfigureServices(IServiceCollection services, Func<IServiceProvider, IApplication> applicationProvider, ISettingsFile settings = null) | ||
{ | ||
settings = GetSettings(); | ||
base.ConfigureServices(services, applicationProvider, settings); | ||
services.AddSingleton<ILoggerConfiguration>(new CustomLoggerConfiguration()); | ||
services.AddTransient<ICustomService, CustomService>(); | ||
return services; | ||
} | ||
} | ||
} | ||
} |