Make E2E tests even more E2E by using ASP.NET Core apps' BuildWebHost method

This commit is contained in:
Steve Sanderson 2017-12-07 11:57:34 +00:00
parent 0ac789221e
commit 6cad4e3b84
4 changed files with 33 additions and 23 deletions

View File

@ -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();
}

View File

@ -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();
}
}
}

View File

@ -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
});
}
}
}

View File

@ -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]