Infrastructure for E2E tests where the app makes requests to an API server
This commit is contained in:
parent
ea6b6bcd19
commit
88cc2caf45
|
|
@ -10,6 +10,6 @@
|
||||||
|
|
||||||
protected override async Task OnInitAsync()
|
protected override async Task OnInitAsync()
|
||||||
{
|
{
|
||||||
responseText = await Http.GetStringAsync("http://example.com/");
|
responseText = await Http.GetStringAsync("/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
<ProjectReference Include="..\..\samples\StandaloneApp\StandaloneApp.csproj" />
|
<ProjectReference Include="..\..\samples\StandaloneApp\StandaloneApp.csproj" />
|
||||||
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.DevHost\Microsoft.AspNetCore.Blazor.DevHost.csproj" />
|
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.DevHost\Microsoft.AspNetCore.Blazor.DevHost.csproj" />
|
||||||
<ProjectReference Include="..\testapps\BasicTestApp\BasicTestApp.csproj" />
|
<ProjectReference Include="..\testapps\BasicTestApp\BasicTestApp.csproj" />
|
||||||
|
<ProjectReference Include="..\testapps\TestServer\TestServer.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -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<AspNetSiteServerFixture>
|
||||||
|
{
|
||||||
|
readonly ServerFixture _apiServerFixture;
|
||||||
|
|
||||||
|
public HttpClientTest(
|
||||||
|
BrowserFixture browserFixture,
|
||||||
|
DevHostServerFixture<BasicTestApp.Program> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace TestServer.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
public class GreetingController : Controller
|
||||||
|
{
|
||||||
|
[HttpGet]
|
||||||
|
public string SayHello() => "Hello";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,6 @@
|
||||||
using System;
|
using Microsoft.AspNetCore;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace TestServer
|
namespace TestServer
|
||||||
{
|
{
|
||||||
|
|
@ -19,6 +13,9 @@ namespace TestServer
|
||||||
|
|
||||||
public static IWebHost BuildWebHost(string[] args) =>
|
public static IWebHost BuildWebHost(string[] args) =>
|
||||||
WebHost.CreateDefaultBuilder(args)
|
WebHost.CreateDefaultBuilder(args)
|
||||||
|
.UseConfiguration(new ConfigurationBuilder()
|
||||||
|
.AddCommandLine(args)
|
||||||
|
.Build())
|
||||||
.UseStartup<Startup>()
|
.UseStartup<Startup>()
|
||||||
.Build();
|
.Build();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,7 @@
|
||||||
using System;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
|
|
||||||
namespace TestServer
|
namespace TestServer
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue