From 4c15a74d145a5a622e3a7e433abbabc301b2ade9 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Fri, 8 Dec 2017 17:27:29 +0000 Subject: [PATCH] Begin E2E testing for HostedInAspNet sample --- samples/HostedInAspNet.Server/Program.cs | 4 +++ .../ServerFixtures/AspNetEnvironment.cs | 11 ++++++++ .../ServerFixtures/AspNetSiteServerFixture.cs | 5 +++- .../Microsoft.Blazor.E2ETest.csproj | 1 + .../Tests/HostedInAspNetTest.cs | 26 +++++++++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 test/Microsoft.Blazor.E2ETest/Infrastructure/ServerFixtures/AspNetEnvironment.cs create mode 100644 test/Microsoft.Blazor.E2ETest/Tests/HostedInAspNetTest.cs diff --git a/samples/HostedInAspNet.Server/Program.cs b/samples/HostedInAspNet.Server/Program.cs index 9ca394d0f2..26ed194826 100644 --- a/samples/HostedInAspNet.Server/Program.cs +++ b/samples/HostedInAspNet.Server/Program.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; namespace HostedInAspNet.Server { @@ -15,6 +16,9 @@ namespace HostedInAspNet.Server public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) + .UseConfiguration(new ConfigurationBuilder() + .AddCommandLine(args) + .Build()) .UseStartup() .Build(); } diff --git a/test/Microsoft.Blazor.E2ETest/Infrastructure/ServerFixtures/AspNetEnvironment.cs b/test/Microsoft.Blazor.E2ETest/Infrastructure/ServerFixtures/AspNetEnvironment.cs new file mode 100644 index 0000000000..300039d0d9 --- /dev/null +++ b/test/Microsoft.Blazor.E2ETest/Infrastructure/ServerFixtures/AspNetEnvironment.cs @@ -0,0 +1,11 @@ +// 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. + +namespace Microsoft.Blazor.E2ETest.Infrastructure.ServerFixtures +{ + public enum AspNetEnvironment + { + Development, + Production + } +} diff --git a/test/Microsoft.Blazor.E2ETest/Infrastructure/ServerFixtures/AspNetSiteServerFixture.cs b/test/Microsoft.Blazor.E2ETest/Infrastructure/ServerFixtures/AspNetSiteServerFixture.cs index 295cb5a6e3..1671468ce2 100644 --- a/test/Microsoft.Blazor.E2ETest/Infrastructure/ServerFixtures/AspNetSiteServerFixture.cs +++ b/test/Microsoft.Blazor.E2ETest/Infrastructure/ServerFixtures/AspNetSiteServerFixture.cs @@ -13,6 +13,8 @@ namespace Microsoft.Blazor.E2ETest.Infrastructure.ServerFixtures public BuildWebHost BuildWebHostMethod { get; set; } + public AspNetEnvironment Environment { get; set; } = AspNetEnvironment.Production; + protected override IWebHost CreateWebHost() { if (BuildWebHostMethod == null) @@ -29,7 +31,8 @@ namespace Microsoft.Blazor.E2ETest.Infrastructure.ServerFixtures return BuildWebHostMethod(new[] { "--urls", "http://127.0.0.1:0", - "--contentroot", sampleSitePath + "--contentroot", sampleSitePath, + "--environment", Environment.ToString(), }); } } diff --git a/test/Microsoft.Blazor.E2ETest/Microsoft.Blazor.E2ETest.csproj b/test/Microsoft.Blazor.E2ETest/Microsoft.Blazor.E2ETest.csproj index 48787d5184..b7684c3b03 100644 --- a/test/Microsoft.Blazor.E2ETest/Microsoft.Blazor.E2ETest.csproj +++ b/test/Microsoft.Blazor.E2ETest/Microsoft.Blazor.E2ETest.csproj @@ -17,6 +17,7 @@ + diff --git a/test/Microsoft.Blazor.E2ETest/Tests/HostedInAspNetTest.cs b/test/Microsoft.Blazor.E2ETest/Tests/HostedInAspNetTest.cs new file mode 100644 index 0000000000..9804759ed7 --- /dev/null +++ b/test/Microsoft.Blazor.E2ETest/Tests/HostedInAspNetTest.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 Microsoft.Blazor.E2ETest.Infrastructure; +using Microsoft.Blazor.E2ETest.Infrastructure.ServerFixtures; +using Xunit; + +namespace Microsoft.Blazor.E2ETest.Tests +{ + public class HostedInAspNetTest : ServerTestBase + { + public HostedInAspNetTest(BrowserFixture browserFixture, AspNetSiteServerFixture serverFixture) + : base(browserFixture, serverFixture) + { + serverFixture.BuildWebHostMethod = HostedInAspNet.Server.Program.BuildWebHost; + serverFixture.Environment = AspNetEnvironment.Development; + } + + [Fact] + public void HasTitle() + { + Navigate("/", noReload: true); + Assert.Equal("Sample Blazor app", Browser.Title); + } + } +}