Make E2E tests even more E2E by using ASP.NET Core apps' BuildWebHost method
This commit is contained in:
parent
0ac789221e
commit
6cad4e3b84
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using Microsoft.AspNetCore;
|
using Microsoft.AspNetCore;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace MonoSanity
|
namespace MonoSanity
|
||||||
{
|
{
|
||||||
|
|
@ -15,6 +16,9 @@ namespace MonoSanity
|
||||||
|
|
||||||
public static IWebHost BuildWebHost(string[] args) =>
|
public static IWebHost BuildWebHost(string[] args) =>
|
||||||
WebHost.CreateDefaultBuilder(args)
|
WebHost.CreateDefaultBuilder(args)
|
||||||
|
.UseConfiguration(new ConfigurationBuilder()
|
||||||
|
.AddCommandLine(args)
|
||||||
|
.Build())
|
||||||
.UseStartup<Startup>()
|
.UseStartup<Startup>()
|
||||||
.Build();
|
.Build();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,12 @@ namespace Microsoft.Blazor.DevHost.Server
|
||||||
{
|
{
|
||||||
internal class Program
|
internal class Program
|
||||||
{
|
{
|
||||||
internal static IWebHost BuildWebHost(string[] args)
|
internal static IWebHost BuildWebHost(string[] args) =>
|
||||||
{
|
WebHost.CreateDefaultBuilder(args)
|
||||||
var configuration = new ConfigurationBuilder()
|
.UseConfiguration(new ConfigurationBuilder()
|
||||||
.AddCommandLine(args)
|
.AddCommandLine(args)
|
||||||
.Build();
|
.Build())
|
||||||
|
|
||||||
return WebHost.CreateDefaultBuilder(args)
|
|
||||||
.UseConfiguration(configuration)
|
|
||||||
.UseStartup<Startup>()
|
.UseStartup<Startup>()
|
||||||
.Build();
|
.Build();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,36 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.AspNetCore;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
|
||||||
namespace Microsoft.Blazor.E2ETest.Infrastructure.ServerFixtures
|
namespace Microsoft.Blazor.E2ETest.Infrastructure.ServerFixtures
|
||||||
{
|
{
|
||||||
public class AspNetSiteServerFixture<TStartup> : WebHostServerFixture
|
public class AspNetSiteServerFixture : WebHostServerFixture
|
||||||
where TStartup: class
|
|
||||||
{
|
{
|
||||||
|
public delegate IWebHost BuildWebHost(string[] args);
|
||||||
|
|
||||||
|
public BuildWebHost BuildWebHostMethod { get; set; }
|
||||||
|
|
||||||
protected override IWebHost CreateWebHost()
|
protected override IWebHost CreateWebHost()
|
||||||
{
|
{
|
||||||
var sampleSitePath = Path.Combine(
|
if (BuildWebHostMethod == null)
|
||||||
FindSolutionDir(),
|
{
|
||||||
"samples",
|
throw new InvalidOperationException(
|
||||||
typeof(TStartup).Assembly.GetName().Name);
|
$"No value was provided for {nameof(BuildWebHostMethod)}");
|
||||||
|
}
|
||||||
|
|
||||||
return WebHost.CreateDefaultBuilder()
|
var sampleSitePath = Path.Combine(
|
||||||
.UseStartup<TStartup>()
|
FindSolutionDir(),
|
||||||
.UseContentRoot(sampleSitePath)
|
"samples",
|
||||||
.UseUrls("http://127.0.0.1:0")
|
BuildWebHostMethod.Method.DeclaringType.Assembly.GetName().Name);
|
||||||
.Build();
|
|
||||||
|
return BuildWebHostMethod(new[]
|
||||||
|
{
|
||||||
|
"--urls", "http://127.0.0.1:0",
|
||||||
|
"--contentroot", sampleSitePath
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@ using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.Blazor.E2ETest.Tests
|
namespace Microsoft.Blazor.E2ETest.Tests
|
||||||
{
|
{
|
||||||
public class MonoSanityTest : ServerTestBase<AspNetSiteServerFixture<MonoSanity.Startup>>
|
public class MonoSanityTest : ServerTestBase<AspNetSiteServerFixture>
|
||||||
{
|
{
|
||||||
public MonoSanityTest(BrowserFixture browserFixture, AspNetSiteServerFixture<MonoSanity.Startup> serverFixture)
|
public MonoSanityTest(BrowserFixture browserFixture, AspNetSiteServerFixture serverFixture)
|
||||||
: base(browserFixture, serverFixture)
|
: base(browserFixture, serverFixture)
|
||||||
{
|
{
|
||||||
|
serverFixture.BuildWebHostMethod = MonoSanity.Program.BuildWebHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue