Skip to content

Commit

Permalink
V9 Move sln files to root (#11212)
Browse files Browse the repository at this point in the history
* Move sln files to root

* Fix tests

* Misc cleanup - remove unused helper

* Document the esoteric nature of UmbracoWebApplicationFactory

* Avoid unnecessary change to TestHelper WorkingDirectory
  • Loading branch information
Paul Johnson authored Sep 29, 2021
1 parent 5bfab13 commit bceebea
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 208 deletions.
2 changes: 1 addition & 1 deletion build/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ stages:
- task: NuGetCommand@2
displayName: Restore NuGet Packages
inputs:
restoreSolution: '*\src\umbraco.sln'
restoreSolution: 'umbraco.sln'
feedsToUse: config
- task: PowerShell@1
displayName: Update Version and Artifact Name
Expand Down
4 changes: 2 additions & 2 deletions build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
Write-Host "Restore NuGet"
Write-Host "Logging to $($this.BuildTemp)\nuget.restore.log"
$params = "-Source", $nugetsourceUmbraco
&$this.BuildEnv.NuGet restore "$($this.SolutionRoot)\src\umbraco-netcore-only.sln" > "$($this.BuildTemp)\nuget.restore.log" @params
&$this.BuildEnv.NuGet restore "$($this.SolutionRoot)\umbraco-netcore-only.sln" > "$($this.BuildTemp)\nuget.restore.log" @params
if (-not $?) { throw "Failed to restore NuGet packages." }
})

Expand All @@ -401,7 +401,7 @@

Write-Host "Create NuGet packages"

&dotnet pack "$($this.SolutionRoot)\src\umbraco-netcore-only.sln" `
&dotnet pack "$($this.SolutionRoot)\umbraco-netcore-only.sln" `
--output "$($this.BuildOutput)" `
--verbosity detailed `
-c Release `
Expand Down
8 changes: 1 addition & 7 deletions src/Umbraco.Infrastructure/Runtime/CoreRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public class CoreRuntime : IRuntime
private readonly IMainDom _mainDom;
private readonly IUmbracoDatabaseFactory _databaseFactory;
private readonly IEventAggregator _eventAggregator;
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IUmbracoVersion _umbracoVersion;
private CancellationToken _cancellationToken;

/// <summary>
Expand All @@ -42,9 +40,7 @@ public CoreRuntime(
IProfilingLogger profilingLogger,
IMainDom mainDom,
IUmbracoDatabaseFactory databaseFactory,
IEventAggregator eventAggregator,
IHostingEnvironment hostingEnvironment,
IUmbracoVersion umbracoVersion)
IEventAggregator eventAggregator)
{
State = state;
_loggerFactory = loggerFactory;
Expand All @@ -54,8 +50,6 @@ public CoreRuntime(
_mainDom = mainDom;
_databaseFactory = databaseFactory;
_eventAggregator = eventAggregator;
_hostingEnvironment = hostingEnvironment;
_umbracoVersion = umbracoVersion;
_logger = _loggerFactory.CreateLogger<CoreRuntime>();
}

Expand Down
16 changes: 7 additions & 9 deletions src/Umbraco.Tests.Common/TestHelperBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,10 @@ protected TestHelperBase(Assembly entryAssembly)
public TypeLoader GetMockedTypeLoader() =>
new TypeLoader(Mock.Of<ITypeFinder>(), new VaryingRuntimeHash(), Mock.Of<IAppPolicyCache>(), new DirectoryInfo(GetHostingEnvironment().MapPathContentRoot(Constants.SystemDirectories.TempData)), Mock.Of<ILogger<TypeLoader>>(), Mock.Of<IProfiler>());

//// public Configs GetConfigs() => GetConfigsFactory().Create();

public abstract IBackOfficeInfo GetBackOfficeInfo();

//// public IConfigsFactory GetConfigsFactory() => new ConfigsFactory();

/// <summary>
/// Gets the working directory of the test project.
/// </summary>
public virtual string WorkingDirectory
public string WorkingDirectory
{
get
{
Expand All @@ -70,11 +64,15 @@ public virtual string WorkingDirectory
return _workingDir;
}

var dir = Path.Combine(Assembly.GetExecutingAssembly().GetRootDirectorySafe(), "TEMP");
// Azure DevOps can only store a database in certain locations so we will need to detect if we are running
// on a build server and if so we'll use the temp path.
var dir = string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("System_DefaultWorkingDirectory"))
? Path.Combine(Assembly.GetExecutingAssembly().GetRootDirectorySafe(), "TEMP")
: Path.Combine(Path.GetTempPath(), "UmbracoTests", "TEMP");

if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
_ = Directory.CreateDirectory(dir);
}

_workingDir = dir;
Expand Down
38 changes: 0 additions & 38 deletions src/Umbraco.Tests.Integration/Implementations/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,6 @@ public TestHelper()
ProfilingLogger = new ProfilingLogger(ConsoleLoggerFactory.CreateLogger<ProfilingLogger>(), Profiler);
}

public override string WorkingDirectory
{
get
{
// For Azure Devops we can only store a database in certain locations so we will need to detect if we are running
// on a build server and if so we'll use the %temp% path.
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("System_DefaultWorkingDirectory")))
{
// We are using Azure Devops!
if (_tempWorkingDir != null)
{
return _tempWorkingDir;
}

string temp = Path.Combine(Environment.ExpandEnvironmentVariables("%temp%"), "UmbracoTemp");
Directory.CreateDirectory(temp);
_tempWorkingDir = temp;
return _tempWorkingDir;
}
else
{
return base.WorkingDirectory;
}
}
}

public IUmbracoBootPermissionChecker UmbracoBootPermissionChecker { get; } =
new TestUmbracoBootPermissionChecker();

Expand All @@ -130,18 +104,6 @@ public override string WorkingDirectory

public override IMarchal Marchal { get; } = new AspNetCoreMarchal();

public override IBackOfficeInfo GetBackOfficeInfo()
{
if (_backOfficeInfo == null)
{
var globalSettings = new GlobalSettings();
IOptionsMonitor<GlobalSettings> mockedOptionsMonitorOfGlobalSettings = Mock.Of<IOptionsMonitor<GlobalSettings>>(x => x.CurrentValue == globalSettings);
_backOfficeInfo = new AspNetCoreBackOfficeInfo(mockedOptionsMonitorOfGlobalSettings, GetHostingEnvironment());
}

return _backOfficeInfo;
}

public override IHostingEnvironment GetHostingEnvironment()
=> _hostingEnvironment ??= new TestHostingEnvironment(
GetIOptionsMonitorOfHostingSettings(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Umbraco.Cms.Tests.Integration.Testing;
using Umbraco.Cms.Web.BackOffice.Controllers;
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Cms.Web.UI;
using Umbraco.Cms.Web.Website.Controllers;
using Umbraco.Extensions;

Expand All @@ -39,8 +40,19 @@ public override void Setup()
InMemoryConfiguration["ConnectionStrings:" + Constants.System.UmbracoConnectionName] = null;
InMemoryConfiguration["Umbraco:CMS:Hosting:Debug"] = "true";

// create new WebApplicationFactory specifying 'this' as the IStartup instance
var factory = new UmbracoWebApplicationFactory<UmbracoTestServerTestBase>(CreateHostBuilder, BeforeHostStart);
/*
* It's worth noting that our usage of WebApplicationFactory is non-standard,
* the intent is that your Startup.ConfigureServices is called just like
* when the app starts up, then replacements are registered in this class with
* builder.ConfigureServices (builder.ConfigureTestServices has hung around from before the
* generic host switchover).
*
* This is currently a pain to refactor towards due to UmbracoBuilder+TypeFinder+TypeLoader setup but
* we should get there one day.
*
* See https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests
*/
var factory = new UmbracoWebApplicationFactory<Startup>(CreateHostBuilder, BeforeHostStart);

// additional host configuration for web server integration tests
Factory = factory.WithWebHostBuilder(builder =>
Expand Down Expand Up @@ -129,7 +141,7 @@ protected string PrepareUrl(string url)

protected LinkGenerator LinkGenerator { get; private set; }

protected WebApplicationFactory<UmbracoTestServerTestBase> Factory { get; private set; }
protected WebApplicationFactory<Startup> Factory { get; private set; }

public override void ConfigureServices(IServiceCollection services)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
Expand Down Expand Up @@ -99,6 +99,7 @@
<ProjectReference Include="..\Umbraco.PublishedCache.NuCache\Umbraco.PublishedCache.NuCache.csproj" />
<ProjectReference Include="..\Umbraco.Tests.Common\Umbraco.Tests.Common.csproj" />
<ProjectReference Include="..\Umbraco.Web.BackOffice\Umbraco.Web.BackOffice.csproj" />
<ProjectReference Include="..\Umbraco.Web.UI\Umbraco.Web.UI.csproj" />
<ProjectReference Include="..\Umbraco.Web.Website\Umbraco.Web.Website.csproj" />
</ItemGroup>

Expand Down
9 changes: 0 additions & 9 deletions src/Umbraco.Tests.UnitTests/TestHelpers/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ public TestHelperInternal()

public override IMarchal Marchal { get; } = Mock.Of<IMarchal>();

public override IBackOfficeInfo GetBackOfficeInfo()
=> Mock.Of<IBackOfficeInfo>();

public override IHostingEnvironment GetHostingEnvironment()
{
var testPath = TestContext.CurrentContext.TestDirectory.Split("bin")[0];
Expand Down Expand Up @@ -104,12 +101,6 @@ public static Lazy<ISqlContext> GetMockSqlContext()
public static MapperConfigurationStore CreateMaps()
=> new MapperConfigurationStore();

//// public static Configs GetConfigs() => _testHelperInternal.GetConfigs();

public static IBackOfficeInfo GetBackOfficeInfo() => s_testHelperInternal.GetBackOfficeInfo();

//// public static IConfigsFactory GetConfigsFactory() => _testHelperInternal.GetConfigsFactory();

/// <summary>
/// Gets the working directory of the test project.
/// </summary>
Expand Down
11 changes: 0 additions & 11 deletions src/Umbraco.Tests/TestHelpers/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ public TestHelperInternal() : base(typeof(TestHelperInternal).Assembly)

public override IMarchal Marchal { get; } = new FrameworkMarchal();

public override IBackOfficeInfo GetBackOfficeInfo()
=> new AspNetBackOfficeInfo(
new GlobalSettings(),
TestHelper.IOHelper, Mock.Of<ILogger<AspNetBackOfficeInfo>>(), Options.Create(new WebRoutingSettings()));

public override IHostingEnvironment GetHostingEnvironment()
=> new AspNetHostingEnvironment(Options.Create(new HostingSettings()));

Expand All @@ -88,12 +83,6 @@ public override IIpResolver GetIpResolver()

public static TypeLoader GetMockedTypeLoader() => _testHelperInternal.GetMockedTypeLoader();

//public static Configs GetConfigs() => _testHelperInternal.GetConfigs();

public static IBackOfficeInfo GetBackOfficeInfo() => _testHelperInternal.GetBackOfficeInfo();

// public static IConfigsFactory GetConfigsFactory() => _testHelperInternal.GetConfigsFactory();

/// <summary>
/// Gets the working directory of the test project.
/// </summary>
Expand Down
Loading

0 comments on commit bceebea

Please sign in to comment.