Files
Umbraco-CMS/tests/Umbraco.Tests/TestHelpers/ControllerTesting/TestStartup.cs
Paul Johnson 00133e880d Move test projects from src/ to tests/ (#11357)
* Update gitignore

* Move csproj

* Update project references

* Update solutions

* Update build scripts

* Tests used to share editorconfig with projects in src

* Fix broken tests.

* Stop copying around .editorconfig

merged root one with linting

* csharp_style_expression_bodied -> suggestion

* Move StyleCop rulesets to matching directories and update shared build properties

* Remove legacy build files, update NuGet.cofig and solution files

* Restore myget source

* Clean up .gitignore

* Update .gitignore

* Move new test classes to tests after merge

* Gitignore + nuget config

* Move new test

Co-authored-by: Ronald Barendse <ronald@barend.se>
2021-10-18 08:14:04 +01:00

56 lines
2.1 KiB
C#

using System;
using System.Net.Http;
using System.Web.Http;
using System.Web.Http.Dispatcher;
using System.Web.Http.ExceptionHandling;
using System.Web.Http.Tracing;
using Owin;
using Umbraco.Cms.Core.Web;
using Umbraco.Web;
using Umbraco.Web.Hosting;
using Umbraco.Web.WebApi;
namespace Umbraco.Tests.TestHelpers.ControllerTesting
{
/// <summary>
/// Startup class for the self-hosted web server works for OWIN and WebAPI
/// </summary>
public class TestStartup
{
private readonly Func<HttpRequestMessage, IUmbracoContextAccessor, ApiController> _controllerFactory;
private readonly Action<HttpConfiguration> _initialize;
public TestStartup(Action<HttpConfiguration> initialize, Func<HttpRequestMessage, IUmbracoContextAccessor, ApiController> controllerFactory)
{
_controllerFactory = controllerFactory;
_initialize = initialize;
}
public void Configuration(IAppBuilder app)
{
var httpConfig = new HttpConfiguration();
// TODO: Enable this if you can't see the errors produced
// var traceWriter = httpConfig.EnableSystemDiagnosticsTracing();
// traceWriter.IsVerbose = true;
// traceWriter.MinimumLevel = TraceLevel.Debug;
httpConfig.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
// Add in a simple exception tracer so we can see what is causing the 500 Internal Server Error
httpConfig.Services.Add(typeof (IExceptionLogger), new TraceExceptionLogger());
httpConfig.Services.Replace(typeof (IAssembliesResolver), new SpecificAssemblyResolver(new[] { typeof (AspNetApplicationShutdownRegistry).Assembly }));
httpConfig.Services.Replace(typeof (IHttpControllerActivator), new TestControllerActivator(_controllerFactory));
httpConfig.Services.Replace(typeof (IHttpControllerSelector), new NamespaceHttpControllerSelector(httpConfig));
//auth everything
app.AuthenticateEverything();
_initialize(httpConfig);
app.UseWebApi(httpConfig);
}
}
}