Make IntegrationTesting not depend on M.A.Hosting.Abstractions (#14112)

This commit is contained in:
Justin Kotalik 2019-09-19 05:33:17 +09:00 committed by GitHub
parent 4a7bf75e89
commit 1540b7d122
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 24 deletions

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// 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.AspNetCore.Server.IntegrationTesting

View File

@ -1,13 +0,0 @@
using Microsoft.AspNetCore.Hosting.Server.Features;
using System.Linq;
namespace Microsoft.AspNetCore.Hosting
{
public static class IWebHostExtensions
{
public static string GetAddress(this IWebHost host)
{
return host.ServerFeatures.Get<IServerAddressesFeature>().Addresses.First();
}
}
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>ASP.NET Core helpers to deploy applications to IIS Express, IIS, WebListener and Kestrel for testing.</Description>
@ -19,7 +19,6 @@
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Hosting.Abstractions" />
<Reference Include="Microsoft.AspNetCore.Testing" />
<Reference Include="Microsoft.Extensions.FileProviders.Embedded" />
<Reference Include="Microsoft.Extensions.Logging" />

3
src/Hosting/build.cmd Normal file
View File

@ -0,0 +1,3 @@
@ECHO OFF
SET RepoRoot=%~dp0..\..
%RepoRoot%\build.cmd -projects %~dp0**\*.*proj %*

View File

@ -53,7 +53,7 @@ namespace Microsoft.AspNetCore.StaticFiles
using (var server = builder.Start(TestUrlHelper.GetTestUrl(ServerType.Kestrel)))
{
var environment = server.Services.GetRequiredService<IWebHostEnvironment>();
using (var client = new HttpClient { BaseAddress = new Uri(server.GetAddress()) })
using (var client = new HttpClient { BaseAddress = new Uri(Helpers.GetAddress(server)) })
{
var response = await client.GetAsync("hello");
var responseText = await response.Content.ReadAsStringAsync();
@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.StaticFiles
using (var server = builder.Start(TestUrlHelper.GetTestUrl(ServerType.Kestrel)))
{
var environment = server.Services.GetRequiredService<IWebHostEnvironment>();
using (var client = new HttpClient { BaseAddress = new Uri(server.GetAddress()) })
using (var client = new HttpClient { BaseAddress = new Uri(Helpers.GetAddress(server)) })
{
var response = await client.GetAsync("hello");
var responseText = await response.Content.ReadAsStringAsync();

View File

@ -0,0 +1,17 @@
// 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.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server.Features;
namespace Microsoft.AspNetCore.StaticFiles
{
public static class Helpers
{
public static string GetAddress(IWebHost server)
{
return server.ServerFeatures.Get<IServerAddressesFeature>().Addresses.First();
}
}
}

View File

@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.StaticFiles
using (var server = builder.Start(TestUrlHelper.GetTestUrl(ServerType.Kestrel)))
{
using (var client = new HttpClient { BaseAddress = new Uri(server.GetAddress()) })
using (var client = new HttpClient { BaseAddress = new Uri(Helpers.GetAddress(server)) })
{
var response = await client.GetAsync("TestDocument.txt");
@ -76,7 +76,7 @@ namespace Microsoft.AspNetCore.StaticFiles
using (var server = builder.Start(TestUrlHelper.GetTestUrl(ServerType.Kestrel)))
{
using (var client = new HttpClient { BaseAddress = new Uri(server.GetAddress()) })
using (var client = new HttpClient { BaseAddress = new Uri(Helpers.GetAddress(server)) })
{
var response = await client.GetAsync("TestDocument.txt");
@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.StaticFiles
using (var server = builder.Start(TestUrlHelper.GetTestUrl(ServerType.Kestrel)))
{
using (var client = new HttpClient { BaseAddress = new Uri(server.GetAddress()) })
using (var client = new HttpClient { BaseAddress = new Uri(Helpers.GetAddress(server)) })
{
var last = File.GetLastWriteTimeUtc(Path.Combine(AppContext.BaseDirectory, "TestDocument.txt"));
var response = await client.GetAsync("TestDocument.txt");
@ -143,7 +143,7 @@ namespace Microsoft.AspNetCore.StaticFiles
{
var hostingEnvironment = server.Services.GetService<IWebHostEnvironment>();
using (var client = new HttpClient { BaseAddress = new Uri(server.GetAddress()) })
using (var client = new HttpClient { BaseAddress = new Uri(Helpers.GetAddress(server)) })
{
var fileInfo = hostingEnvironment.WebRootFileProvider.GetFileInfo(Path.GetFileName(requestUrl));
var response = await client.GetAsync(requestUrl);
@ -181,7 +181,7 @@ namespace Microsoft.AspNetCore.StaticFiles
{
var hostingEnvironment = server.Services.GetService<IWebHostEnvironment>();
using (var client = new HttpClient { BaseAddress = new Uri(server.GetAddress()) })
using (var client = new HttpClient { BaseAddress = new Uri(Helpers.GetAddress(server)) })
{
var fileInfo = hostingEnvironment.WebRootFileProvider.GetFileInfo(Path.GetFileName(requestUrl));
var request = new HttpRequestMessage(HttpMethod.Head, requestUrl);
@ -261,7 +261,7 @@ namespace Microsoft.AspNetCore.StaticFiles
using (var server = builder.Start(TestUrlHelper.GetTestUrl(serverType)))
{
// We don't use HttpClient here because it's disconnect behavior varies across platforms.
var socket = SendSocketRequestAsync(server.GetAddress(), "/TestDocument1MB.txt");
var socket = SendSocketRequestAsync(Helpers.GetAddress(server), "/TestDocument1MB.txt");
await requestReceived.Task.TimeoutAfter(interval);
socket.LingerState = new LingerOption(true, 0);