Infrastructure for E2E tests where the app makes requests to an API server

This commit is contained in:
Steve Sanderson 2018-02-23 13:28:58 +00:00
parent ea6b6bcd19
commit 88cc2caf45
6 changed files with 58 additions and 15 deletions

View File

@ -10,6 +10,6 @@
protected override async Task OnInitAsync()
{
responseText = await Http.GetStringAsync("http://example.com/");
responseText = await Http.GetStringAsync("/");
}
}

View File

@ -23,6 +23,7 @@
<ProjectReference Include="..\..\samples\StandaloneApp\StandaloneApp.csproj" />
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.DevHost\Microsoft.AspNetCore.Blazor.DevHost.csproj" />
<ProjectReference Include="..\testapps\BasicTestApp\BasicTestApp.csproj" />
<ProjectReference Include="..\testapps\TestServer\TestServer.csproj" />
</ItemGroup>
</Project>

View File

@ -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);
}
}
}

View File

@ -0,0 +1,11 @@
using Microsoft.AspNetCore.Mvc;
namespace TestServer.Controllers
{
[Route("api/[controller]/[action]")]
public class GreetingController : Controller
{
[HttpGet]
public string SayHello() => "Hello";
}
}

View File

@ -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<Startup>()
.Build();
}

View File

@ -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
{