Skip to content

Commit

Permalink
#37 renamed ApplicationManager to AqualityServices (#39)
Browse files Browse the repository at this point in the history
+semver: minor

* #37 renamed ApplicationManager to AqualityServices

* made IsApplicationStarted protected

* #37 fixed build

* fix build
  • Loading branch information
knysh authored Dec 12, 2019
1 parent 0d2ee6c commit 8c2ce82
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace Aquality.Selenium.Core.Applications
{
public abstract class ApplicationManager<TApplication>
public abstract class AqualityServices<TApplication>
where TApplication : class, IApplication
{
private static readonly ThreadLocal<TApplication> AppContainer = new ThreadLocal<TApplication>();
private static readonly ThreadLocal<IServiceProvider> ServiceProviderContainer = new ThreadLocal<IServiceProvider>();

protected ApplicationManager()
protected AqualityServices()
{
}

public static bool IsApplicationStarted()
protected static bool IsApplicationStarted()
{
return AppContainer.IsValueCreated && AppContainer.Value.Driver.SessionId != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Aquality.Selenium.Core.Tests.Applications
{
public class ApplicationManagerTests
public class AqualityServicesTests
{
private const string SpecialSettingsFile = "special";
private const string SpecialLanguageValue = "special";
Expand All @@ -19,31 +19,31 @@ public class ApplicationManagerTests
[Test]
public void Should_BePossibleTo_RegisterCustomServices()
{
Assert.IsInstanceOf<TestTimeoutConfiguration>(TestApplicationManager.ServiceProvider.GetService<ITimeoutConfiguration>());
Assert.IsInstanceOf<TestTimeoutConfiguration>(TestAqualityServices.ServiceProvider.GetService<ITimeoutConfiguration>());
}

[Test]
public void Should_BePossibleTo_GetCustomValues()
{
var timeoutConfiguration = TestApplicationManager.ServiceProvider.GetService<ITimeoutConfiguration>() as TestTimeoutConfiguration;
var timeoutConfiguration = TestAqualityServices.ServiceProvider.GetService<ITimeoutConfiguration>() as TestTimeoutConfiguration;
Assert.AreEqual(SpecialTimeoutValue, timeoutConfiguration.CustomTimeout);
}

[Test]
public void Should_BePossibleTo_GetCustomLoggerValues()
{
TestApplicationManager.SetStartup(new CustomStartup());
var timeoutConfiguration = TestApplicationManager.ServiceProvider.GetService<ILoggerConfiguration>() as CustomLoggerConfiguration;
TestAqualityServices.SetStartup(new CustomStartup());
var timeoutConfiguration = TestAqualityServices.ServiceProvider.GetService<ILoggerConfiguration>() as CustomLoggerConfiguration;
Assert.AreEqual(SpecialLogger, timeoutConfiguration.CustomLogger);
}

[Test]
public void Should_BePossibleTo_RegisterCustomServices_WithCustomSettingsFile()
{
Assert.AreEqual(SpecialLanguageValue, TestApplicationManager.ServiceProvider.GetService<ILoggerConfiguration>().Language);
Assert.AreEqual(SpecialLanguageValue, TestAqualityServices.ServiceProvider.GetService<ILoggerConfiguration>().Language);
}

private class TestApplicationManager : ApplicationManager<IApplication>
private class TestAqualityServices : AqualityServices<IApplication>
{
private static ThreadLocal<TestStartup> startup = new ThreadLocal<TestStartup>();

Expand All @@ -56,7 +56,7 @@ public static void SetStartup(Startup startup)
{
if (startup != null)
{
TestApplicationManager.startup.Value = (TestStartup)startup;
TestAqualityServices.startup.Value = (TestStartup)startup;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ApplicationNotStartedTests : TestWithBrowser
public void Should_NotStartApplication_ForServiceResolving(Type type)
{
Assert.IsNotNull(ServiceProvider.GetRequiredService(type));
Assert.IsFalse(ApplicationManager.IsApplicationStarted());
Assert.IsFalse(AqualityServices.IsApplicationStarted);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

namespace Aquality.Selenium.Core.Tests.Applications.Browser
{
public class ApplicationManager : ApplicationManager<ChromeApplication>
public class AqualityServices : AqualityServices<ChromeApplication>
{
private static readonly object downloadDriverLock = new object();

public new static bool IsApplicationStarted => IsApplicationStarted();

public static ChromeApplication Application => GetApplication(services => StartChrome(services));

public static IServiceProvider ServiceProvider => GetServiceProvider(services => Application);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ protected WebElement(By locator, string name, ElementState state) : base(locator
{
}

protected override ElementActionRetrier ActionRetrier => ApplicationManager.ServiceProvider.GetRequiredService<ElementActionRetrier>();
protected override ElementActionRetrier ActionRetrier => AqualityServices.ServiceProvider.GetRequiredService<ElementActionRetrier>();

protected override IApplication Application => ApplicationManager.Application;
protected override IApplication Application => AqualityServices.Application;

protected override ConditionalWait ConditionalWait => ApplicationManager.ServiceProvider.GetRequiredService<ConditionalWait>();
protected override ConditionalWait ConditionalWait => AqualityServices.ServiceProvider.GetRequiredService<ConditionalWait>();

protected override IElementFactory Factory => ApplicationManager.ServiceProvider.GetRequiredService<IElementFactory>();
protected override IElementFactory Factory => AqualityServices.ServiceProvider.GetRequiredService<IElementFactory>();

protected override IElementFinder Finder => ApplicationManager.ServiceProvider.GetRequiredService<IElementFinder>();
protected override IElementFinder Finder => AqualityServices.ServiceProvider.GetRequiredService<IElementFinder>();

protected override ILocalizedLogger LocalizedLogger => ApplicationManager.ServiceProvider.GetRequiredService<ILocalizedLogger>();
protected override ILocalizedLogger LocalizedLogger => AqualityServices.ServiceProvider.GetRequiredService<ILocalizedLogger>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class FindElementsTests : TestWithBrowser
public new void SetUp()
{
elementFactory = ServiceProvider.GetRequiredService<IElementFactory>();
ApplicationManager.Application.Driver.Navigate().GoToUrl(HoversURL);
AqualityServices.Application.Driver.Navigate().GoToUrl(HoversURL);
var example = new Label(ContentLoc, "Example", ElementState.Displayed);
example.Click();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ public void SetUp()
{
var services = new ServiceCollection();

new Startup().ConfigureServices(services, serviceCollection => ApplicationManager.Application);
new Startup().ConfigureServices(services, serviceCollection => AqualityServices.Application);
ServiceProvider = services.BuildServiceProvider();
}

[TearDown]
public void CleanUp()
{
if (ApplicationManager.IsApplicationStarted())
if (AqualityServices.IsApplicationStarted)
{
ApplicationManager.Application.Quit();
AqualityServices.Application.Quit();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@

namespace Aquality.Selenium.Core.Tests.Applications.WindowsApp
{
public class ApplicationManager : ApplicationManager<WindowsApplication>
public class AqualityServices : AqualityServices<WindowsApplication>
{
private const string SupportedApplication = "./Resources/WindowsApp/Day Maxi Calc.exe";
private const string DefaultDriverServer = "http://127.0.0.1:4723/";


public new static bool IsApplicationStarted => IsApplicationStarted();

public static WindowsApplication Application => GetApplication(service => StartApplication(service));

public static IServiceProvider ServiceProvider => GetServiceProvider(services => Application);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public class CalculatorTest : TestWithApplication
[Test]
public void Should_WorkWithCalculator()
{
ApplicationManager.Application.Driver.FindElement(CalculatorWindow.OneButton).Click();
ApplicationManager.Application.Driver.FindElement(CalculatorWindow.PlusButton).Click();
ApplicationManager.Application.Driver.FindElement(CalculatorWindow.TwoButton).Click();
ApplicationManager.Application.Driver.FindElement(CalculatorWindow.EqualsButton).Click();
var result = ApplicationManager.Application.Driver.FindElement(CalculatorWindow.ResultsLabel).Text;
AqualityServices.Application.Driver.FindElement(CalculatorWindow.OneButton).Click();
AqualityServices.Application.Driver.FindElement(CalculatorWindow.PlusButton).Click();
AqualityServices.Application.Driver.FindElement(CalculatorWindow.TwoButton).Click();
AqualityServices.Application.Driver.FindElement(CalculatorWindow.EqualsButton).Click();
var result = AqualityServices.Application.Driver.FindElement(CalculatorWindow.ResultsLabel).Text;
StringAssert.Contains("3", result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ConditionalWaitTests : TestWithApplication
[Test]
public void Should_BePossibleTo_UseConditionalWait_WithDriver()
{
Assert.DoesNotThrow(() => ApplicationManager.ServiceProvider.GetService<ConditionalWait>().WaitFor(driver =>
Assert.DoesNotThrow(() => AqualityServices.ServiceProvider.GetService<ConditionalWait>().WaitFor(driver =>
{
return driver.FindElements(By.XPath("//*")).Count > 0;
}));
Expand All @@ -24,10 +24,10 @@ public void Should_BePossibleTo_UseConditionalWait_WithDriver()
[Test]
public void Should_BePossibleTo_UseConditionalWait_WithElementFinder()
{
bool elementFinderCondition() => ApplicationManager.ServiceProvider.GetRequiredService<IElementFinder>()
bool elementFinderCondition() => AqualityServices.ServiceProvider.GetRequiredService<IElementFinder>()
.FindElement(CalculatorWindow.ResultsLabel, timeout: LittleTimeout).Text.Contains("3");
Assert.IsFalse(elementFinderCondition());
Assert.DoesNotThrow(() => ApplicationManager.ServiceProvider.GetService<ConditionalWait>().WaitFor(driver =>
Assert.DoesNotThrow(() => AqualityServices.ServiceProvider.GetService<ConditionalWait>().WaitFor(driver =>
{
driver.FindElement(CalculatorWindow.TwoButton).Click();
driver.FindElement(CalculatorWindow.PlusButton).Click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Aquality.Selenium.Core.Tests.Applications.WindowsApp
{
public class ElementFactoryTests : TestWithApplication
{
private IElementFactory Factory => ApplicationManager.ServiceProvider.GetRequiredService<IElementFactory>();
private IElementFactory Factory => AqualityServices.ServiceProvider.GetRequiredService<IElementFactory>();

private IElement NumberPad => Factory.GetButton(CalculatorWindow.WindowLocator, "Number pad");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ protected WindowElement(By locator, string name) : base(locator, name, ElementSt
{
}

protected override ElementActionRetrier ActionRetrier => ApplicationManager.ServiceProvider.GetRequiredService<ElementActionRetrier>();
protected override ElementActionRetrier ActionRetrier => AqualityServices.ServiceProvider.GetRequiredService<ElementActionRetrier>();

protected override IApplication Application => ApplicationManager.Application;
protected override IApplication Application => AqualityServices.Application;

protected override ConditionalWait ConditionalWait => ApplicationManager.ServiceProvider.GetRequiredService<ConditionalWait>();
protected override ConditionalWait ConditionalWait => AqualityServices.ServiceProvider.GetRequiredService<ConditionalWait>();

protected override IElementFactory Factory => ApplicationManager.ServiceProvider.GetRequiredService<IElementFactory>();
protected override IElementFactory Factory => AqualityServices.ServiceProvider.GetRequiredService<IElementFactory>();

protected override IElementFinder Finder => ApplicationManager.ServiceProvider.GetRequiredService<IElementFinder>();
protected override IElementFinder Finder => AqualityServices.ServiceProvider.GetRequiredService<IElementFinder>();

protected override ILocalizedLogger LocalizedLogger => ApplicationManager.ServiceProvider.GetRequiredService<ILocalizedLogger>();
protected override ILocalizedLogger LocalizedLogger => AqualityServices.ServiceProvider.GetRequiredService<ILocalizedLogger>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public class TestWithApplication
[TearDown]
public void CleanUp()
{
if (ApplicationManager.IsApplicationStarted())
if (AqualityServices.IsApplicationStarted)
{
ApplicationManager.Application.Driver.Quit();
AqualityServices.Application.Driver.Quit();
}
}
}
Expand Down

0 comments on commit 8c2ce82

Please sign in to comment.