diff --git a/samples/StandaloneApp/Pages/FetchData.cshtml b/samples/StandaloneApp/Pages/FetchData.cshtml index 3d0488fe73..d41bd5607b 100644 --- a/samples/StandaloneApp/Pages/FetchData.cshtml +++ b/samples/StandaloneApp/Pages/FetchData.cshtml @@ -10,6 +10,6 @@ protected override async Task OnInitAsync() { - responseText = await Http.GetStringAsync("http://example.com/"); + responseText = await Http.GetStringAsync("/"); } } diff --git a/test/Microsoft.AspNetCore.Blazor.E2ETest/Microsoft.AspNetCore.Blazor.E2ETest.csproj b/test/Microsoft.AspNetCore.Blazor.E2ETest/Microsoft.AspNetCore.Blazor.E2ETest.csproj index c1fe37b21c..9f22f62217 100644 --- a/test/Microsoft.AspNetCore.Blazor.E2ETest/Microsoft.AspNetCore.Blazor.E2ETest.csproj +++ b/test/Microsoft.AspNetCore.Blazor.E2ETest/Microsoft.AspNetCore.Blazor.E2ETest.csproj @@ -23,6 +23,7 @@ + diff --git a/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/HttpClientTest.cs b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/HttpClientTest.cs new file mode 100644 index 0000000000..58d67c6f64 --- /dev/null +++ b/test/Microsoft.AspNetCore.Blazor.E2ETest/Tests/HttpClientTest.cs @@ -0,0 +1,40 @@ +// 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.Blazor.E2ETest.Infrastructure; +using Microsoft.AspNetCore.Blazor.E2ETest.Infrastructure.ServerFixtures; +using System; +using System.Net.Http; +using System.Threading.Tasks; +using Xunit; + +namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests +{ + public class HttpClientTest : BasicTestAppTestBase, IClassFixture + { + readonly ServerFixture _apiServerFixture; + + public HttpClientTest( + BrowserFixture browserFixture, + DevHostServerFixture devHostServerFixture, + AspNetSiteServerFixture apiServerFixture) + : base(browserFixture, devHostServerFixture) + { + apiServerFixture.BuildWebHostMethod = TestServer.Program.BuildWebHost; + _apiServerFixture = apiServerFixture; + + //Navigate(ServerPathBase, noReload: true); + } + + [Fact] + public async Task SanityCheck_ApiServerIsRunning() + { + // Just so we can be sure that the other tests are even relevant + // Note that the HttpClient we're instantiating here is *not* the + // one under test. This is not related to Blazor in any way. + var httpClient = new HttpClient { BaseAddress = _apiServerFixture.RootUri }; + var responseText = await httpClient.GetStringAsync("/api/greeting/sayhello"); + Assert.Equal("Hello", responseText); + } + } +} diff --git a/test/testapps/TestServer/Controllers/GreetingController.cs b/test/testapps/TestServer/Controllers/GreetingController.cs new file mode 100644 index 0000000000..32835f896d --- /dev/null +++ b/test/testapps/TestServer/Controllers/GreetingController.cs @@ -0,0 +1,11 @@ +using Microsoft.AspNetCore.Mvc; + +namespace TestServer.Controllers +{ + [Route("api/[controller]/[action]")] + public class GreetingController : Controller + { + [HttpGet] + public string SayHello() => "Hello"; + } +} diff --git a/test/testapps/TestServer/Program.cs b/test/testapps/TestServer/Program.cs index 630210191e..aaad4cef42 100644 --- a/test/testapps/TestServer/Program.cs +++ b/test/testapps/TestServer/Program.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore; +using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; namespace TestServer { @@ -19,6 +13,9 @@ namespace TestServer public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) + .UseConfiguration(new ConfigurationBuilder() + .AddCommandLine(args) + .Build()) .UseStartup() .Build(); } diff --git a/test/testapps/TestServer/Startup.cs b/test/testapps/TestServer/Startup.cs index f26d799fcc..22ef5544db 100644 --- a/test/testapps/TestServer/Startup.cs +++ b/test/testapps/TestServer/Startup.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; namespace TestServer {