Begin E2E testing for DevHost-based projects

This commit is contained in:
Steve Sanderson 2017-12-07 11:49:05 +00:00
parent a59bfa3cb9
commit 0ac789221e
7 changed files with 67 additions and 7 deletions

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8" />
<title></title>
<title>Blazor standalone</title>
</head>
<body>
<h1>Hello</h1>

View File

@ -1,6 +1,7 @@
// 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 Microsoft.AspNetCore.Hosting;
using System;
using System.Linq;
@ -22,7 +23,7 @@ namespace Microsoft.Blazor.DevHost
switch (command.ToLowerInvariant())
{
case "serve":
Server.Program.Main(remainingArgs);
Server.Program.BuildWebHost(remainingArgs).Run();
return 0;
default:
throw new InvalidOperationException($"Unknown command: {command}");

View File

@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;
[assembly: InternalsVisibleTo("Microsoft.Blazor.E2ETest")]

View File

@ -3,19 +3,22 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
namespace Microsoft.Blazor.DevHost.Server
{
internal class Program
{
public static void Main(string[] args)
internal static IWebHost BuildWebHost(string[] args)
{
BuildWebHost(args).Run();
}
var configuration = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
return WebHost.CreateDefaultBuilder(args)
.UseConfiguration(configuration)
.UseStartup<Startup>()
.Build();
}
}
}

View File

@ -0,0 +1,26 @@
// 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.IO;
using Microsoft.AspNetCore.Hosting;
using DevHostServerProgram = Microsoft.Blazor.DevHost.Server.Program;
namespace Microsoft.Blazor.E2ETest.Infrastructure.ServerFixtures
{
public class DevHostServerFixture<TProgram> : WebHostServerFixture
{
protected override IWebHost CreateWebHost()
{
var sampleSitePath = Path.Combine(
FindSolutionDir(),
"samples",
typeof(TProgram).Assembly.GetName().Name);
return DevHostServerProgram.BuildWebHost(new string[]
{
"--urls", "http://127.0.0.1:0",
"--contentroot", sampleSitePath
});
}
}
}

View File

@ -16,7 +16,9 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\samples\BlazorStandalone\BlazorStandalone.csproj" />
<ProjectReference Include="..\..\samples\MonoSanity\MonoSanity.csproj" />
<ProjectReference Include="..\..\src\Microsoft.Blazor.DevHost\Microsoft.Blazor.DevHost.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,25 @@
// 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 Microsoft.Blazor.E2ETest.Infrastructure;
using Microsoft.Blazor.E2ETest.Infrastructure.ServerFixtures;
using Xunit;
namespace Microsoft.Blazor.E2ETest.Tests
{
public class BlazorStandaloneTest
: ServerTestBase<DevHostServerFixture<BlazorStandalone.Program>>
{
public BlazorStandaloneTest(BrowserFixture browserFixture, DevHostServerFixture<BlazorStandalone.Program> serverFixture)
: base(browserFixture, serverFixture)
{
}
[Fact]
public void HasTitle()
{
Navigate("/");
Assert.Equal("Blazor standalone", Browser.Title);
}
}
}