-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from DFE-Digital/CL/IntegrationTestProject
Cl/integration test project
- Loading branch information
Showing
10 changed files
with
147 additions
and
13 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
DfE.Data.SearchPrototype.Test/DfE.Data.SearchPrototype.Test.csproj
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
<PreserveCompilationContext>true</PreserveCompilationContext> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="AngleSharp" Version="1.1.2" /> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.6" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="WireMock.Net" Version="1.5.58" /> | ||
<PackageReference Include="xunit" Version="2.5.3" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\dfe.data.SearchPrototype.web\DfE.Data.SearchPrototype.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Xunit" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="xunit.runner.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
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,35 @@ | ||
using AngleSharp.Dom; | ||
using AngleSharp.Html.Dom; | ||
using DfE.Data.SearchPrototype.Test.Shared; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
|
||
namespace DfE.Data.SearchPrototype.Test; | ||
|
||
public class HomePageTests : PageTestHelper | ||
{ | ||
public HomePageTests(WebApplicationFactory<Program> factory) : base(factory) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task HomePage_ContainsExpectedTitle() | ||
{ | ||
// act | ||
var response = await NavigateToPage(""); | ||
|
||
// assert | ||
var headings = response.GetElementsByTagName("h1"); | ||
Assert.Equal("Welcome", headings.First().InnerHtml); | ||
} | ||
|
||
[Fact] | ||
public async Task HomePage_ContainsPrivacyLink() | ||
{ | ||
// act | ||
IDocument response = await NavigateToPage(""); | ||
|
||
// Assert | ||
IHtmlAnchorElement privacyLink = response.GetHeaderLink("Privacy"); | ||
Assert.Equal("/Home/Privacy", privacyLink.PathName); | ||
} | ||
} |
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,14 @@ | ||
using AngleSharp.Dom; | ||
using AngleSharp.Html.Dom; | ||
|
||
namespace DfE.Data.SearchPrototype.Test.Shared; | ||
|
||
public static class DomBrowserHelpers | ||
{ | ||
public static IHtmlAnchorElement GetHeaderLink(this IDocument response, string linkName) | ||
{ | ||
var header = response.GetElementsByTagName("header").Single(); | ||
var anchorTags = header.GetElementsByTagName("a"); | ||
return (IHtmlAnchorElement)anchorTags.Single(anchorTags => anchorTags.TextContent.Contains(linkName)); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
DfE.Data.SearchPrototype.Test/Shared/IntegrationTestingWebApplicationFactory.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,15 @@ | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
|
||
namespace DfE.Data.SearchPrototype.Test.Shared; | ||
|
||
public class IntegrationTestingWebApplicationFactory : IClassFixture<WebApplicationFactory<Program>> | ||
{ | ||
private readonly WebApplicationFactory<Program> _fixture; | ||
protected HttpClient _httpClient; | ||
|
||
public IntegrationTestingWebApplicationFactory(WebApplicationFactory<Program> fixture) | ||
{ | ||
_fixture = fixture; | ||
_httpClient = _fixture.CreateClient(); | ||
} | ||
} |
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,27 @@ | ||
using AngleSharp; | ||
using AngleSharp.Dom; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
|
||
namespace DfE.Data.SearchPrototype.Test.Shared; | ||
|
||
public class PageTestHelper : IntegrationTestingWebApplicationFactory | ||
{ | ||
private IBrowsingContext _context; | ||
|
||
public PageTestHelper(WebApplicationFactory<Program> factory) : base(factory) | ||
{ | ||
// anglesharp | ||
AngleSharp.IConfiguration angleSharpConfig = Configuration.Default; | ||
_context = BrowsingContext.New(angleSharpConfig); | ||
//-------------------------------------------------------------------- | ||
} | ||
|
||
protected async Task<IDocument> NavigateToPage(string webPage) | ||
{ | ||
HttpResponseMessage response = await _httpClient.GetAsync(webPage); | ||
|
||
var DOM = await response.Content.ReadAsStringAsync(); | ||
|
||
return await _context.OpenAsync(req => req.Content(DOM)); | ||
} | ||
} |
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,4 @@ | ||
# Project description | ||
|
||
These integration tests run the web app and use Anglesharp to query the DOM of the returned page for expected elements. | ||
|
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,3 @@ | ||
{ | ||
"shadowCopy": false | ||
} |
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
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