using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Funq; using ServiceStack.Common.Web; using ServiceStack.Html; using ServiceStack.IO; using ServiceStack.ServiceHost; using ServiceStack.ServiceInterface.Validation; using ServiceStack.VirtualPath; using ServiceStack.WebHost.Endpoints; using ServiceStack.WebHost.Endpoints.Extensions; namespace ServiceStack.ServiceInterface.Testing { public class TestAppHost : IAppHost { private readonly Funq.Container container; public TestAppHost() : this(new Container(), Assembly.GetExecutingAssembly()) {} public TestAppHost(Funq.Container container, params Assembly[] serviceAssemblies) { this.container = container ?? new Container(); if (serviceAssemblies.Length == 0) serviceAssemblies = new[] { Assembly.GetExecutingAssembly() }; var createInstance = EndpointHostConfig.Instance; this.Config = EndpointHost.Config = new EndpointHostConfig( GetType().Name, new ServiceManager(true, serviceAssemblies)); this.ContentTypeFilters = new HttpResponseFilter(); this.PreRequestFilters = new List>(); this.RequestFilters = new List>(); this.ResponseFilters = new List>(); this.ViewEngines = new List(); this.CatchAllHandlers = new List(); this.VirtualPathProvider = new FileSystemVirtualPathProvider(this); } public void RegisterAs() where T : TAs { this.container.RegisterAs(); } public virtual void Release(object instance) { } public void OnEndRequest() {} public IServiceRoutes Routes { get; private set; } public void Register(T instance) { container.Register(instance); } public T TryResolve() { return container.TryResolve(); } public IContentTypeFilter ContentTypeFilters { get; set; } public List> PreRequestFilters { get; set; } public List> RequestFilters { get; set; } public List> ResponseFilters { get; set; } public List ViewEngines { get; private set; } public HandleUncaughtExceptionDelegate ExceptionHandler { get; set; } public HandleServiceExceptionDelegate ServiceExceptionHandler { get; set; } public List CatchAllHandlers { get; private set; } public Dictionary> RequestBinders { get { throw new NotImplementedException(); } } public EndpointHostConfig Config { get; set; } public void RegisterService(Type serviceType, params string[] atRestPaths) { Config.ServiceManager.RegisterService(serviceType); } public List Plugins { get; private set; } public void LoadPlugin(params IPlugin[] plugins) { plugins.ToList().ForEach(x => x.Register(this)); } public IVirtualPathProvider VirtualPathProvider { get; set; } public IServiceRunner CreateServiceRunner(ActionContext actionContext) { throw new NotImplementedException(); } public virtual string ResolveAbsoluteUrl(string virtualPath, IHttpRequest httpReq) { return httpReq.GetAbsoluteUrl(virtualPath); } } }