parent
61883b5101
commit
43c75c922e
|
|
@ -1,18 +1,12 @@
|
||||||
// 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.IO;
|
|
||||||
|
|
||||||
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
{
|
{
|
||||||
public class MvcSampleFixture<TStartup> : MvcTestFixture<TStartup>
|
public class MvcSampleFixture<TStartup> : MvcTestFixture<TStartup>
|
||||||
{
|
{
|
||||||
public MvcSampleFixture()
|
public MvcSampleFixture()
|
||||||
#if NET451
|
: base("samples")
|
||||||
: base(Path.Combine("..", "..", "..", "..", "..", "..", "samples"))
|
|
||||||
#else
|
|
||||||
: base(Path.Combine("..", "..", "..", "..", "..", "samples"))
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,18 +20,15 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
{
|
{
|
||||||
public class MvcTestFixture<TStartup> : IDisposable
|
public class MvcTestFixture<TStartup> : IDisposable
|
||||||
{
|
{
|
||||||
|
private const string SolutionName = "Mvc.sln";
|
||||||
private readonly TestServer _server;
|
private readonly TestServer _server;
|
||||||
|
|
||||||
public MvcTestFixture()
|
public MvcTestFixture()
|
||||||
#if NET451
|
: this(Path.Combine("test", "WebSites"))
|
||||||
: this(Path.Combine("..", "..", "..", "..", "..", "WebSites"))
|
|
||||||
#else
|
|
||||||
: this(Path.Combine("..", "..", "..", "..", "WebSites"))
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MvcTestFixture(string relativePath)
|
protected MvcTestFixture(string solutionRelativePath)
|
||||||
{
|
{
|
||||||
// RequestLocalizationOptions saves the current culture when constructed, potentially changing response
|
// RequestLocalizationOptions saves the current culture when constructed, potentially changing response
|
||||||
// localization i.e. RequestLocalizationMiddleware behavior. Ensure the saved culture
|
// localization i.e. RequestLocalizationMiddleware behavior. Ensure the saved culture
|
||||||
|
|
@ -39,7 +36,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
using (new CultureReplacer())
|
using (new CultureReplacer())
|
||||||
{
|
{
|
||||||
var builder = new WebHostBuilder()
|
var builder = new WebHostBuilder()
|
||||||
.UseContentRoot(GetApplicationPath(relativePath))
|
.UseContentRoot(GetApplicationPath(solutionRelativePath))
|
||||||
.ConfigureServices(InitializeServices)
|
.ConfigureServices(InitializeServices)
|
||||||
.UseStartup(typeof(TStartup));
|
.UseStartup(typeof(TStartup));
|
||||||
|
|
||||||
|
|
@ -58,12 +55,26 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests
|
||||||
_server.Dispose();
|
_server.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetApplicationPath(string relativePath)
|
private static string GetApplicationPath(string solutionRelativePath)
|
||||||
{
|
{
|
||||||
var startupAssembly = typeof(TStartup).GetTypeInfo().Assembly;
|
var startupAssembly = typeof(TStartup).GetTypeInfo().Assembly;
|
||||||
var applicationName = startupAssembly.GetName().Name;
|
var applicationName = startupAssembly.GetName().Name;
|
||||||
var applicationBasePath = PlatformServices.Default.Application.ApplicationBasePath;
|
var applicationBasePath = PlatformServices.Default.Application.ApplicationBasePath;
|
||||||
return Path.GetFullPath(Path.Combine(applicationBasePath, relativePath, applicationName));
|
|
||||||
|
var directoryInfo = new DirectoryInfo(applicationBasePath);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
var solutionFileInfo = new FileInfo(Path.Combine(directoryInfo.FullName, SolutionName));
|
||||||
|
if (solutionFileInfo.Exists)
|
||||||
|
{
|
||||||
|
return Path.Combine(directoryInfo.FullName, solutionRelativePath, applicationName);
|
||||||
|
}
|
||||||
|
|
||||||
|
directoryInfo = directoryInfo.Parent;
|
||||||
|
}
|
||||||
|
while (directoryInfo.Parent != null);
|
||||||
|
|
||||||
|
throw new Exception($"Solution root could not be located using application root {applicationBasePath}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void InitializeServices(IServiceCollection services)
|
protected virtual void InitializeServices(IServiceCollection services)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue