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.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace MonoSanity
|
||||
{
|
||||
|
|
@ -15,6 +16,9 @@ namespace MonoSanity
|
|||
|
||||
public static IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseConfiguration(new ConfigurationBuilder()
|
||||
.AddCommandLine(args)
|
||||
.Build())
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,16 +9,12 @@ namespace Microsoft.Blazor.DevHost.Server
|
|||
{
|
||||
internal class Program
|
||||
{
|
||||
internal static IWebHost BuildWebHost(string[] args)
|
||||
{
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddCommandLine(args)
|
||||
.Build();
|
||||
|
||||
return WebHost.CreateDefaultBuilder(args)
|
||||
.UseConfiguration(configuration)
|
||||
internal static IWebHost BuildWebHost(string[] args) =>
|
||||
WebHost.CreateDefaultBuilder(args)
|
||||
.UseConfiguration(new ConfigurationBuilder()
|
||||
.AddCommandLine(args)
|
||||
.Build())
|
||||
.UseStartup<Startup>()
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,36 @@
|
|||
// 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.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
|
||||
namespace Microsoft.Blazor.E2ETest.Infrastructure.ServerFixtures
|
||||
{
|
||||
public class AspNetSiteServerFixture<TStartup> : WebHostServerFixture
|
||||
where TStartup: class
|
||||
public class AspNetSiteServerFixture : WebHostServerFixture
|
||||
{
|
||||
public delegate IWebHost BuildWebHost(string[] args);
|
||||
|
||||
public BuildWebHost BuildWebHostMethod { get; set; }
|
||||
|
||||
protected override IWebHost CreateWebHost()
|
||||
{
|
||||
var sampleSitePath = Path.Combine(
|
||||
FindSolutionDir(),
|
||||
"samples",
|
||||
typeof(TStartup).Assembly.GetName().Name);
|
||||
if (BuildWebHostMethod == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"No value was provided for {nameof(BuildWebHostMethod)}");
|
||||
}
|
||||
|
||||
return WebHost.CreateDefaultBuilder()
|
||||
.UseStartup<TStartup>()
|
||||
.UseContentRoot(sampleSitePath)
|
||||
.UseUrls("http://127.0.0.1:0")
|
||||
.Build();
|
||||
var sampleSitePath = Path.Combine(
|
||||
FindSolutionDir(),
|
||||
"samples",
|
||||
BuildWebHostMethod.Method.DeclaringType.Assembly.GetName().Name);
|
||||
|
||||
return BuildWebHostMethod(new[]
|
||||
{
|
||||
"--urls", "http://127.0.0.1:0",
|
||||
"--contentroot", sampleSitePath
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,12 @@ using Xunit;
|
|||
|
||||
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)
|
||||
{
|
||||
serverFixture.BuildWebHostMethod = MonoSanity.Program.BuildWebHost;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Reference in New Issue