Skip to content

Commit

Permalink
Testbuilder v2 (#114)
Browse files Browse the repository at this point in the history
* Lots of (admittedly poorly managed) changes to rev to v2.
* Biggest change: Now there's a TestBuilder.Build() method that will validate as many dependencies as possible.

---------

Co-authored-by: Michael Curn <[email protected]>
Co-authored-by: Kevin B <[email protected]>
  • Loading branch information
3 people authored Mar 27, 2023
1 parent 02d51df commit 0ebf19d
Show file tree
Hide file tree
Showing 41 changed files with 2,392 additions and 902 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<TargetFramework>net6.0</TargetFramework>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
<NoWarn>
CA1303;CS1822;CS1822;<!-- Next ones are temporary. -->CS8620;CS8625;CS8600;CS8602;CS8618;CS8603;CS8604;CA1822;CA1062
</NoWarn>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IntelliTect.TestTools.TestFramework" Version="1.1.1" />
<PackageReference Include="Selenium.WebDriver" Version="4.0.0-alpha01" />
<PackageReference Include="System.Text.Json" Version="4.7.2" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="IntelliTect.Analyzers" Version="0.1.8">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="IntelliTect.TestTools.TestFramework" Version="1.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="Selenium.WebDriver" Version="4.8.0" />
<PackageReference Include="System.Text.Json" Version="7.0.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using System;
using System.Text.Json.Serialization;
using OpenQA.Selenium;

namespace ExampleTests.Harness
Expand All @@ -10,7 +11,7 @@ public BasePage(IWebDriver driver)
Driver = driver;
}

public string BaseUrl { get; set; } = @"https://intellitect.com/";
public Uri BaseUrl { get; set; } = new Uri("https://intellitect.com/");
[JsonIgnore]
protected IWebDriver Driver { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Test1()
IsBodyAvailable = true
};

TestBuilder builder = new TestBuilder();
TestBuilder builder = new();
builder
.AddLogger<NewLogger>()
.AddDependencyService<IWebDriver>(new WebDriverFactory("Chrome").Driver)
Expand All @@ -38,7 +38,7 @@ public void Test1()
[Fact]
public void RegisterMembership()
{
TestBuilder builder = new TestBuilder();
TestBuilder builder = new();
builder
.AddDependencyService<IWebDriver>(new WebDriverFactory("Chrome").Driver)
.AddDependencyService<Harness.IntelliTectWebpage>()
Expand All @@ -50,7 +50,7 @@ public void RegisterMembership()
[Fact]
public void LogIn()
{
TestBuilder builder = new TestBuilder();
TestBuilder builder = new();
builder
.AddDependencyService<IWebDriver>(new WebDriverFactory("Chrome").Driver)
.AddDependencyService<Account>(new AccountFactory().Account)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace ExampleTests
{
class NewLogger : ILogger
public class NewLogger : ILogger
{
public string TestCaseKey { get; set; }
public string CurrentTestBlock { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@ public WebDriverFactory(string browserType)

private IWebDriver GetWebDriver(IServiceProvider service)
{
if (_BrowserType == "Chrome")
_Driver = new ChromeDriver(Directory.GetCurrentDirectory());
else
_Driver = new ChromeDriver(Directory.GetCurrentDirectory());
return _Driver;
return new ChromeDriver(Directory.GetCurrentDirectory());
}

private IWebDriver _Driver;
private string _BrowserType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace IntelliTect.TestTools.TestFramework.Tests
{
public static class ErrorMessages
{
public const string ExecuteError = "there must be one and only one execute method";
public const string MissingInputError = "unable to satisfy test block input";
public const string MismatchedExecuteOverrideError = "unable to find corresponding execute parameter";
public const string TooManyExecuteOverridesError = "too many execute overrides were provided";
public const string AlreadyAddedError = "multiple execute argument overrides of the same type are not allowed";
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;

namespace IntelliTect.TestTools.TestFramework.Tests
{
public class ThrowingLogger : ITestCaseLogger
{
public ThrowingLogger(TestCase tc)
{
TestCase = tc;
}

public string? TestCaseKey { get; set; }
public string? CurrentTestBlock { get; set; }

public TestCase TestCase { get; }

public void Debug(string message)
{
throw new NotImplementedException();
}

public void Critical(string message)
{
throw new NotImplementedException();
}

public void Info(string message)
{
throw new NotImplementedException();
}

public void TestBlockInput(object input)
{
throw new NotImplementedException();
}

public void TestBlockOutput(object output)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
<NoWarn>1701;1702;CA1822;CA1303</NoWarn>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
<NoWarn>
CA1303;
CA1822;
</NoWarn>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="IntelliTect.Analyzers" Version="0.1.8">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using Xunit;

namespace IntelliTect.TestTools.TestFramework.Tests
{
public class TestBase
{
protected static void ValidateAggregateException(AggregateException result, int expectedInnerExceptions, params string[] messages)
{
if (result is null) throw new ArgumentNullException(nameof(result));
Assert.Equal(expectedInnerExceptions, result.InnerExceptions.Count);

foreach(string s in messages)
{
Assert.Contains(result.InnerExceptions,
m => m.Message.Contains(
s,
StringComparison.InvariantCultureIgnoreCase));
}
}
}
}
Loading

0 comments on commit 0ebf19d

Please sign in to comment.