tests: setup initial infra for end to end tests
This commit is contained in:
Vendored
+2
-1
@@ -3,5 +3,6 @@
|
|||||||
"Antiforgery",
|
"Antiforgery",
|
||||||
"blazor",
|
"blazor",
|
||||||
"Hsts"
|
"Hsts"
|
||||||
]
|
],
|
||||||
|
"dotnet.unitTests.runSettingsPath": "./test/Blog.Tests/.runsettings"
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
@inherits LayoutComponentBase
|
@inherits LayoutComponentBase
|
||||||
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
@Body
|
@Body
|
||||||
|
|
||||||
|
|||||||
@@ -24,3 +24,5 @@ app
|
|||||||
.AddInteractiveServerRenderMode();
|
.AddInteractiveServerRenderMode();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
|
public partial class Program {}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RunSettings>
|
||||||
|
<Playwright>
|
||||||
|
<BrowserName>chromium</BrowserName>
|
||||||
|
<LaunchOptions>
|
||||||
|
<Headless>false</Headless>
|
||||||
|
<Channel>msedge</Channel>
|
||||||
|
</LaunchOptions>
|
||||||
|
</Playwright>
|
||||||
|
</RunSettings>
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="bunit" Version="1.27.17" />
|
<PackageReference Include="bunit" Version="1.27.17" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.3" />
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||||
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.42.0" />
|
<PackageReference Include="Microsoft.Playwright.NUnit" Version="1.42.0" />
|
||||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
namespace Blog.Tests.EndToEnd;
|
||||||
|
|
||||||
|
public class BlogHostFactory<TProgram> : WebApplicationFactory<TProgram> where TProgram : class
|
||||||
|
{
|
||||||
|
protected override IHost CreateHost(IHostBuilder builder)
|
||||||
|
{
|
||||||
|
var testHost = base.CreateHost(builder);
|
||||||
|
builder.ConfigureWebHost(webHostBuilder => webHostBuilder.UseKestrel());
|
||||||
|
|
||||||
|
var kestrelHost = builder.Build();
|
||||||
|
kestrelHost.Start();
|
||||||
|
|
||||||
|
return new CompositeHost(testHost, kestrelHost);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
namespace Blog.Tests.EndToEnd;
|
||||||
|
|
||||||
|
public class BlogPageTest : PageTest
|
||||||
|
{
|
||||||
|
private readonly BlogHostFactory<Program> _factory = new();
|
||||||
|
|
||||||
|
public override BrowserNewContextOptions ContextOptions()
|
||||||
|
{
|
||||||
|
var baseUrl = "http://localhost:5000";
|
||||||
|
|
||||||
|
_factory
|
||||||
|
.WithWebHostBuilder(builder => builder.UseUrls(baseUrl))
|
||||||
|
.CreateDefaultClient();
|
||||||
|
|
||||||
|
var options = base.ContextOptions();
|
||||||
|
options.BaseURL = baseUrl;
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
namespace Blog.Tests.EndToEnd;
|
||||||
|
|
||||||
|
public class CompositeHost(IHost testHost, IHost kestrelHost) : IHost
|
||||||
|
{
|
||||||
|
private readonly IHost _testHost = testHost;
|
||||||
|
private readonly IHost _kestrelHost = kestrelHost;
|
||||||
|
|
||||||
|
public IServiceProvider Services => _testHost.Services;
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_testHost.Dispose();
|
||||||
|
_kestrelHost.Dispose();
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task StartAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
await _testHost.StartAsync(cancellationToken);
|
||||||
|
await _kestrelHost.StartAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task StopAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
await _testHost.StopAsync(cancellationToken);
|
||||||
|
await _kestrelHost.StopAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
namespace Blog.Tests.EndToEnd;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class IndexTests : BlogPageTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public async Task Index_WhenNavigatedTo_ItShouldDisplayMessage()
|
||||||
|
{
|
||||||
|
await Page.GotoAsync("/");
|
||||||
|
var message = Page.GetByRole(AriaRole.Heading, new () { Name = "Hello, world!" });
|
||||||
|
await Expect(message).ToBeVisibleAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +1,6 @@
|
|||||||
global using NUnit.Framework;
|
global using NUnit.Framework;
|
||||||
|
global using Microsoft.AspNetCore.Mvc.Testing;
|
||||||
|
global using Microsoft.Extensions.Hosting;
|
||||||
|
global using Microsoft.AspNetCore.Hosting;
|
||||||
|
global using Microsoft.Playwright.NUnit;
|
||||||
|
global using Microsoft.Playwright;
|
||||||
Reference in New Issue
Block a user