2020-03-13 14:43:41 +11:00
|
|
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
|
using Moq;
|
2020-03-24 11:53:56 +11:00
|
|
|
|
using System.Data.Common;
|
2020-03-13 14:43:41 +11:00
|
|
|
|
using System.Net;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Cache;
|
|
|
|
|
|
using Umbraco.Core.Diagnostics;
|
2020-03-25 15:06:22 +11:00
|
|
|
|
using Umbraco.Core.Hosting;
|
2020-03-13 14:43:41 +11:00
|
|
|
|
using Umbraco.Core.Logging;
|
2020-03-25 16:52:42 +11:00
|
|
|
|
using Umbraco.Net;
|
2020-03-13 14:43:41 +11:00
|
|
|
|
using Umbraco.Core.Persistence;
|
|
|
|
|
|
using Umbraco.Core.Runtime;
|
|
|
|
|
|
using Umbraco.Tests.Common;
|
|
|
|
|
|
using Umbraco.Web.BackOffice;
|
|
|
|
|
|
using Umbraco.Web.BackOffice.AspNetCore;
|
|
|
|
|
|
using IHostingEnvironment = Umbraco.Core.Hosting.IHostingEnvironment;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Tests.Integration.Implementations
|
|
|
|
|
|
{
|
|
|
|
|
|
public class TestHelper : TestHelperBase
|
|
|
|
|
|
{
|
|
|
|
|
|
private IBackOfficeInfo _backOfficeInfo;
|
|
|
|
|
|
private readonly IHostingEnvironment _hostingEnvironment;
|
2020-03-26 15:39:20 +11:00
|
|
|
|
private readonly IApplicationShutdownRegistry _hostingLifetime;
|
2020-03-13 14:43:41 +11:00
|
|
|
|
private readonly IIpResolver _ipResolver;
|
|
|
|
|
|
private readonly IWebHostEnvironment _hostEnvironment;
|
|
|
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
|
|
|
|
|
|
|
|
public TestHelper() : base(typeof(TestHelper).Assembly)
|
|
|
|
|
|
{
|
|
|
|
|
|
var httpContext = new DefaultHttpContext();
|
|
|
|
|
|
httpContext.Connection.RemoteIpAddress = IPAddress.Parse("127.0.0.1");
|
|
|
|
|
|
_httpContextAccessor = Mock.Of<IHttpContextAccessor>(x => x.HttpContext == httpContext);
|
|
|
|
|
|
_ipResolver = new AspNetIpResolver(_httpContextAccessor);
|
|
|
|
|
|
|
|
|
|
|
|
_hostEnvironment = Mock.Of<IWebHostEnvironment>(x =>
|
|
|
|
|
|
x.ApplicationName == "UmbracoIntegrationTests"
|
|
|
|
|
|
&& x.ContentRootPath == CurrentAssemblyDirectory
|
|
|
|
|
|
&& x.WebRootPath == CurrentAssemblyDirectory); // same folder for now?
|
|
|
|
|
|
|
2020-03-25 15:06:22 +11:00
|
|
|
|
_hostingEnvironment = new TestHostingEnvironment(
|
2020-03-13 14:43:41 +11:00
|
|
|
|
SettingsForTests.GetDefaultHostingSettings(),
|
|
|
|
|
|
_hostEnvironment,
|
2020-03-25 15:06:22 +11:00
|
|
|
|
_httpContextAccessor);
|
|
|
|
|
|
|
2020-03-26 15:39:20 +11:00
|
|
|
|
_hostingLifetime = new AspNetCoreApplicationShutdownRegistry(Mock.Of<IHostApplicationLifetime>());
|
2020-03-13 14:43:41 +11:00
|
|
|
|
|
|
|
|
|
|
Logger = new ProfilingLogger(new ConsoleLogger(new MessageTemplates()), Profiler);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IUmbracoBootPermissionChecker UmbracoBootPermissionChecker { get; } = new TestUmbracoBootPermissionChecker();
|
|
|
|
|
|
|
|
|
|
|
|
public AppCaches AppCaches { get; } = new AppCaches(NoAppCache.Instance, NoAppCache.Instance, new IsolatedCaches(type => NoAppCache.Instance));
|
|
|
|
|
|
|
|
|
|
|
|
public IProfilingLogger Logger { get; private set; }
|
|
|
|
|
|
|
|
|
|
|
|
public IProfiler Profiler { get; } = new VoidProfiler();
|
|
|
|
|
|
|
|
|
|
|
|
public IHttpContextAccessor GetHttpContextAccessor() => _httpContextAccessor;
|
|
|
|
|
|
|
|
|
|
|
|
public IWebHostEnvironment GetWebHostEnvironment() => _hostEnvironment;
|
|
|
|
|
|
|
2020-03-26 15:32:39 +11:00
|
|
|
|
public override IDbProviderFactoryCreator DbProviderFactoryCreator => new SqlServerDbProviderFactoryCreator(Constants.DbProviderNames.SqlServer, DbProviderFactories.GetFactory);
|
2020-03-13 14:43:41 +11:00
|
|
|
|
|
|
|
|
|
|
public override IBulkSqlInsertProvider BulkSqlInsertProvider => new SqlServerBulkSqlInsertProvider();
|
|
|
|
|
|
|
|
|
|
|
|
public override IMarchal Marchal { get; } = new AspNetCoreMarchal();
|
|
|
|
|
|
|
|
|
|
|
|
public override IBackOfficeInfo GetBackOfficeInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_backOfficeInfo == null)
|
2020-03-23 17:15:32 +11:00
|
|
|
|
_backOfficeInfo = new AspNetCoreBackOfficeInfo(SettingsForTests.GetDefaultGlobalSettings(GetUmbracoVersion()));
|
2020-03-13 14:43:41 +11:00
|
|
|
|
return _backOfficeInfo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override IHostingEnvironment GetHostingEnvironment() => _hostingEnvironment;
|
2020-03-26 15:39:20 +11:00
|
|
|
|
public override IApplicationShutdownRegistry GetHostingEnvironmentLifetime() => _hostingLifetime;
|
2020-03-13 14:43:41 +11:00
|
|
|
|
|
|
|
|
|
|
public override IIpResolver GetIpResolver() => _ipResolver;
|
2020-03-25 15:06:22 +11:00
|
|
|
|
|
2020-03-13 14:43:41 +11:00
|
|
|
|
}
|
|
|
|
|
|
}
|