From 0ac789221ec7c0daeedbf96c394ae9a9dcda206f Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Thu, 7 Dec 2017 11:49:05 +0000 Subject: [PATCH] Begin E2E testing for DevHost-based projects --- samples/BlazorStandalone/wwwroot/index.html | 2 +- src/Microsoft.Blazor.DevHost/Program.cs | 3 ++- .../Properties/AssemblyInfo.cs | 3 +++ .../Server/Program.cs | 13 ++++++---- .../ServerFixtures/DevHostServerFixture.cs | 26 +++++++++++++++++++ .../Microsoft.Blazor.E2ETest.csproj | 2 ++ .../Tests/BlazorStandaloneTest.cs | 25 ++++++++++++++++++ 7 files changed, 67 insertions(+), 7 deletions(-) create mode 100644 src/Microsoft.Blazor.DevHost/Properties/AssemblyInfo.cs create mode 100644 test/Microsoft.Blazor.E2ETest/Infrastructure/ServerFixtures/DevHostServerFixture.cs create mode 100644 test/Microsoft.Blazor.E2ETest/Tests/BlazorStandaloneTest.cs diff --git a/samples/BlazorStandalone/wwwroot/index.html b/samples/BlazorStandalone/wwwroot/index.html index c3d471ecdc..715729c43c 100644 --- a/samples/BlazorStandalone/wwwroot/index.html +++ b/samples/BlazorStandalone/wwwroot/index.html @@ -2,7 +2,7 @@ - + Blazor standalone

Hello

diff --git a/src/Microsoft.Blazor.DevHost/Program.cs b/src/Microsoft.Blazor.DevHost/Program.cs index 7a441aa6be..bef5fac2c2 100644 --- a/src/Microsoft.Blazor.DevHost/Program.cs +++ b/src/Microsoft.Blazor.DevHost/Program.cs @@ -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}"); diff --git a/src/Microsoft.Blazor.DevHost/Properties/AssemblyInfo.cs b/src/Microsoft.Blazor.DevHost/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..1b7cb6a645 --- /dev/null +++ b/src/Microsoft.Blazor.DevHost/Properties/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.Blazor.E2ETest")] diff --git a/src/Microsoft.Blazor.DevHost/Server/Program.cs b/src/Microsoft.Blazor.DevHost/Server/Program.cs index b174a02e1a..163f07b6fe 100644 --- a/src/Microsoft.Blazor.DevHost/Server/Program.cs +++ b/src/Microsoft.Blazor.DevHost/Server/Program.cs @@ -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() .Build(); + } } } diff --git a/test/Microsoft.Blazor.E2ETest/Infrastructure/ServerFixtures/DevHostServerFixture.cs b/test/Microsoft.Blazor.E2ETest/Infrastructure/ServerFixtures/DevHostServerFixture.cs new file mode 100644 index 0000000000..928b12c0ee --- /dev/null +++ b/test/Microsoft.Blazor.E2ETest/Infrastructure/ServerFixtures/DevHostServerFixture.cs @@ -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 : 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 + }); + } + } +} diff --git a/test/Microsoft.Blazor.E2ETest/Microsoft.Blazor.E2ETest.csproj b/test/Microsoft.Blazor.E2ETest/Microsoft.Blazor.E2ETest.csproj index aad742e4c1..48787d5184 100644 --- a/test/Microsoft.Blazor.E2ETest/Microsoft.Blazor.E2ETest.csproj +++ b/test/Microsoft.Blazor.E2ETest/Microsoft.Blazor.E2ETest.csproj @@ -16,7 +16,9 @@ + + diff --git a/test/Microsoft.Blazor.E2ETest/Tests/BlazorStandaloneTest.cs b/test/Microsoft.Blazor.E2ETest/Tests/BlazorStandaloneTest.cs new file mode 100644 index 0000000000..c403c6838c --- /dev/null +++ b/test/Microsoft.Blazor.E2ETest/Tests/BlazorStandaloneTest.cs @@ -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> + { + public BlazorStandaloneTest(BrowserFixture browserFixture, DevHostServerFixture serverFixture) + : base(browserFixture, serverFixture) + { + } + + [Fact] + public void HasTitle() + { + Navigate("/"); + Assert.Equal("Blazor standalone", Browser.Title); + } + } +}