react to removal of PlatformAbstractions (#1023)
This commit is contained in:
parent
853b3847ad
commit
ce650eee7f
|
|
@ -26,7 +26,6 @@
|
||||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="$(AspNetCoreVersion)" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.RazorViews.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.Extensions.RazorViews.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.Extensions.RuntimeEnvironment.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.Extensions.RuntimeEnvironment.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.Extensions.StackTrace.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.Extensions.StackTrace.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -15,7 +15,6 @@ using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.ObjectPool;
|
using Microsoft.Extensions.ObjectPool;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Hosting
|
namespace Microsoft.AspNetCore.Hosting
|
||||||
{
|
{
|
||||||
|
|
@ -274,9 +273,8 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
|
|
||||||
_options = new WebHostOptions(_config);
|
_options = new WebHostOptions(_config);
|
||||||
|
|
||||||
var appEnvironment = PlatformServices.Default.Application;
|
var contentRootPath = ResolveContentRootPath(_options.ContentRootPath, AppContext.BaseDirectory);
|
||||||
var contentRootPath = ResolveContentRootPath(_options.ContentRootPath, appEnvironment.ApplicationBasePath);
|
var applicationName = _options.ApplicationName;
|
||||||
var applicationName = _options.ApplicationName ?? appEnvironment.ApplicationName;
|
|
||||||
|
|
||||||
// Initialize the hosting environment
|
// Initialize the hosting environment
|
||||||
_hostingEnvironment.Initialize(applicationName, contentRootPath, _options);
|
_hostingEnvironment.Initialize(applicationName, contentRootPath, _options);
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Internal;
|
using Microsoft.Extensions.Internal;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PlatformAbstractions = Microsoft.DotNet.PlatformAbstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
||||||
{
|
{
|
||||||
|
|
@ -214,18 +214,35 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting
|
||||||
|
|
||||||
private string GetRuntimeIdentifier()
|
private string GetRuntimeIdentifier()
|
||||||
{
|
{
|
||||||
var architecture = PlatformAbstractions.RuntimeEnvironment.RuntimeArchitecture;
|
var architecture = GetArchitecture();
|
||||||
switch (PlatformAbstractions.RuntimeEnvironment.OperatingSystemPlatform)
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
case PlatformAbstractions.Platform.Windows:
|
return "win7-" + architecture;
|
||||||
return "win7-" + architecture;
|
}
|
||||||
case PlatformAbstractions.Platform.Linux:
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||||
return "linux-" + architecture;
|
{
|
||||||
case PlatformAbstractions.Platform.Darwin:
|
return "linux-" + architecture;
|
||||||
return "osx.10.12-" + architecture;
|
}
|
||||||
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
|
{
|
||||||
|
return "osx.10.12-" + architecture;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Unrecognized operation system platform");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetArchitecture()
|
||||||
|
{
|
||||||
|
switch (RuntimeInformation.OSArchitecture)
|
||||||
|
{
|
||||||
|
case Architecture.X86:
|
||||||
|
return "x86";
|
||||||
|
case Architecture.X64:
|
||||||
|
return "x64";
|
||||||
default:
|
default:
|
||||||
throw new InvalidOperationException(
|
throw new NotSupportedException($"Unsupported architecture: {RuntimeInformation.OSArchitecture}");
|
||||||
"Unrecognized operation system platform: " + PlatformAbstractions.RuntimeEnvironment.OperatingSystemPlatform);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(DotNetPlatformAbstractionsVersion)" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="$(AspNetCoreVersion)" />
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Process.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.Extensions.Process.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.Extensions.RuntimeEnvironment.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.Extensions.RuntimeEnvironment.Sources" Version="$(AspNetCoreVersion)" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.NETCore.Windows.ApiSets" Version="$(WindowsApiSetsVersion)" />
|
<PackageReference Include="Microsoft.NETCore.Windows.ApiSets" Version="$(WindowsApiSetsVersion)" />
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Server.IntegrationTesting.xunit
|
namespace Microsoft.AspNetCore.Server.IntegrationTesting.xunit
|
||||||
{
|
{
|
||||||
|
|
@ -13,8 +12,7 @@ namespace Microsoft.AspNetCore.Server.IntegrationTesting.xunit
|
||||||
|
|
||||||
public static string GetSolutionRoot()
|
public static string GetSolutionRoot()
|
||||||
{
|
{
|
||||||
var applicationName = PlatformServices.Default.Application.ApplicationName;
|
var applicationBasePath = AppContext.BaseDirectory;
|
||||||
var applicationBasePath = PlatformServices.Default.Application.ApplicationBasePath;
|
|
||||||
|
|
||||||
var directoryInfo = new DirectoryInfo(applicationBasePath);
|
var directoryInfo = new DirectoryInfo(applicationBasePath);
|
||||||
do
|
do
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.AspNetCore.Testing" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Testing" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
|
<PackageReference Include="Microsoft.Extensions.Options" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="$(AspNetCoreVersion)" />
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
|
||||||
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
|
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
|
||||||
<PackageReference Include="xunit" Version="$(XunitVersion)" />
|
<PackageReference Include="xunit" Version="$(XunitVersion)" />
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
@ -21,7 +21,6 @@ using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Logging.Abstractions;
|
using Microsoft.Extensions.Logging.Abstractions;
|
||||||
using Microsoft.Extensions.Logging.Testing;
|
using Microsoft.Extensions.Logging.Testing;
|
||||||
using Microsoft.Extensions.ObjectPool;
|
using Microsoft.Extensions.ObjectPool;
|
||||||
using Microsoft.Extensions.PlatformAbstractions;
|
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
[assembly: HostingStartup(typeof(WebHostBuilderTests.TestHostingStartup))]
|
[assembly: HostingStartup(typeof(WebHostBuilderTests.TestHostingStartup))]
|
||||||
|
|
@ -650,52 +649,79 @@ namespace Microsoft.AspNetCore.Hosting
|
||||||
.UseStartup("Microsoft.AspNetCore.Hosting.Tests")
|
.UseStartup("Microsoft.AspNetCore.Hosting.Tests")
|
||||||
.Build())
|
.Build())
|
||||||
{
|
{
|
||||||
var appBase = PlatformServices.Default.Application.ApplicationBasePath;
|
var appBase = AppContext.BaseDirectory;
|
||||||
Assert.Equal(appBase, host.Services.GetService<IHostingEnvironment>().ContentRootPath);
|
Assert.Equal(appBase, host.Services.GetService<IHostingEnvironment>().ContentRootPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DefaultApplicationNameToStartupAssemblyName()
|
public void DefaultApplicationNameWithNoStartupThrows()
|
||||||
|
{
|
||||||
|
var builder = new ConfigurationBuilder();
|
||||||
|
var host = new WebHostBuilder()
|
||||||
|
.UseServer(new TestServer());
|
||||||
|
|
||||||
|
var ex = Assert.Throws<ArgumentException>(() => host.Build());
|
||||||
|
|
||||||
|
// ArgumentException adds "Parameter name" to the message and this is the cleanest way to make sure we get the right
|
||||||
|
// expected string
|
||||||
|
Assert.Equal(new ArgumentException("A valid non-empty application name must be provided.", "applicationName").Message , ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void DefaultApplicationNameWithUseStartupOfString()
|
||||||
{
|
{
|
||||||
var builder = new ConfigurationBuilder();
|
var builder = new ConfigurationBuilder();
|
||||||
using (var host = new WebHostBuilder()
|
using (var host = new WebHostBuilder()
|
||||||
.UseServer(new TestServer())
|
.UseServer(new TestServer())
|
||||||
.UseStartup("Microsoft.AspNetCore.Hosting.Tests")
|
.UseStartup(typeof(Startup).Assembly.GetName().Name)
|
||||||
.Build())
|
.Build())
|
||||||
{
|
{
|
||||||
var hostingEnv = host.Services.GetService<IHostingEnvironment>();
|
var hostingEnv = host.Services.GetService<IHostingEnvironment>();
|
||||||
Assert.Equal("Microsoft.AspNetCore.Hosting.Tests", hostingEnv.ApplicationName);
|
Assert.Equal(typeof(Startup).Assembly.GetName().Name, hostingEnv.ApplicationName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DefaultApplicationNameToStartupType()
|
public void DefaultApplicationNameWithUseStartupOfT()
|
||||||
{
|
{
|
||||||
var builder = new ConfigurationBuilder();
|
var builder = new ConfigurationBuilder();
|
||||||
using (var host = new WebHostBuilder()
|
using (var host = new WebHostBuilder()
|
||||||
.UseServer(new TestServer())
|
.UseServer(new TestServer())
|
||||||
.UseStartup<StartupNoServices>()
|
.UseStartup<StartupNoServices>()
|
||||||
.UseStartup("Microsoft.AspNetCore.Hosting.Tests.NonExistent")
|
|
||||||
.Build())
|
.Build())
|
||||||
{
|
{
|
||||||
var hostingEnv = host.Services.GetService<IHostingEnvironment>();
|
var hostingEnv = host.Services.GetService<IHostingEnvironment>();
|
||||||
Assert.Equal("Microsoft.AspNetCore.Hosting.Tests.NonExistent", hostingEnv.ApplicationName);
|
Assert.Equal(typeof(StartupNoServices).Assembly.GetName().Name, hostingEnv.ApplicationName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DefaultApplicationNameAndBasePathToStartupMethods()
|
public void DefaultApplicationNameWithUseStartupOfType()
|
||||||
|
{
|
||||||
|
var builder = new ConfigurationBuilder();
|
||||||
|
var host = new WebHostBuilder()
|
||||||
|
.UseServer(new TestServer())
|
||||||
|
.UseStartup(typeof(StartupNoServices))
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var hostingEnv = host.Services.GetService<IHostingEnvironment>();
|
||||||
|
Assert.Equal(typeof(StartupNoServices).Assembly.GetName().Name, hostingEnv.ApplicationName);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void DefaultApplicationNameWithConfigure()
|
||||||
{
|
{
|
||||||
var builder = new ConfigurationBuilder();
|
var builder = new ConfigurationBuilder();
|
||||||
using (var host = new WebHostBuilder()
|
using (var host = new WebHostBuilder()
|
||||||
.UseServer(new TestServer())
|
.UseServer(new TestServer())
|
||||||
.Configure(app => { })
|
.Configure(app => { })
|
||||||
.UseStartup("Microsoft.AspNetCore.Hosting.Tests.NonExistent")
|
|
||||||
.Build())
|
.Build())
|
||||||
{
|
{
|
||||||
var hostingEnv = host.Services.GetService<IHostingEnvironment>();
|
var hostingEnv = host.Services.GetService<IHostingEnvironment>();
|
||||||
Assert.Equal("Microsoft.AspNetCore.Hosting.Tests.NonExistent", hostingEnv.ApplicationName);
|
|
||||||
|
// Should be the assembly containing this test, because that's where the delegate comes from
|
||||||
|
Assert.Equal(typeof(WebHostBuilderTests).Assembly.GetName().Name, hostingEnv.ApplicationName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue