private readonly AppDomainProxy _appDomainProxy; // The gateway to the ASP.NET-enabled .NET appdomain private AppHost(string appPhysicalDirectory, string virtualDirectory = "/") { _appDomainProxy = (AppDomainProxy)ApplicationHost.CreateApplicationHost(typeof(AppDomainProxy), virtualDirectory, appPhysicalDirectory); _appDomainProxy.RunCodeInAppDomain(() => { InitializeApplication(); FilterProviders.Providers.Add(new InterceptionFilterProvider()); LastRequestData.Reset(); }); }
private AppHost(string appPhysicalDirectory, string virtualDirectory = "/") { try { _appDomainProxy = (AppDomainProxy) ApplicationHost.CreateApplicationHost(typeof (AppDomainProxy), virtualDirectory, appPhysicalDirectory); } catch(FileNotFoundException ex) { if((ex.Message != null) && ex.Message.Contains("MvcIntegrationTestFramework")) throw new InvalidOperationException("Could not load MvcIntegrationTestFramework.dll within a bin directory under " + appPhysicalDirectory + ". Is this the path to your ASP.NET MVC application, and have you set up a post-build event to copy your test assemblies and their dependencies to this folder? See the demo project for an example."); throw; } _appDomainProxy.RunCodeInAppDomain(() => { InitializeApplication(); AttachTestControllerDescriptorsForAllControllers(); LastRequestData.Reset(); }); }
private void AddAssemblyResolver(string appPhysicalDirectory) { _appDomainProxy.RunCodeInAppDomain(baseDir => { AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { var tokens = args.Name.Split(",".ToCharArray()); string assemblyCulture; string assemblyName = tokens[0]; string assemblyFileName = assemblyName.Replace(".resources", "") + ".dll"; string assemblyPath; if (tokens.Length < 2) { assemblyCulture = null; } else { assemblyCulture = tokens[2].Substring(tokens[2].IndexOf('=') + 1); } if (assemblyName.EndsWith(".resources")) { // Specific resources are located in app subdirectories string resourceDirectory = Path.Combine(baseDir, assemblyCulture ?? "en"); assemblyPath = Path.Combine(resourceDirectory, assemblyName + ".dll"); if (File.Exists(assemblyPath)) { return(Assembly.LoadFile(assemblyPath)); } } assemblyPath = Path.Combine(baseDir, assemblyFileName); try { return(Assembly.LoadFile(assemblyPath)); } catch (Exception ex) { Console.WriteLine(ex); return(null); } }; }, Path.Combine(appPhysicalDirectory, "bin")); }
private readonly AppDomainProxy _appDomainProxy; // The gateway to the ASP.NET-enabled .NET appdomain private AppHost(string appPhysicalDirectory, string virtualDirectory = "/") { try { _appDomainProxy = (AppDomainProxy)ApplicationHost.CreateApplicationHost(typeof(AppDomainProxy), virtualDirectory, appPhysicalDirectory); } catch (FileNotFoundException ex) { if ((ex.Message != null) && ex.Message.Contains("MvcIntegrationTestFramework")) { throw new InvalidOperationException("Could not load MvcIntegrationTestFramework.dll within a bin directory under " + appPhysicalDirectory + ". Is this the path to your ASP.NET MVC application, and have you set up a post-build event to copy your test assemblies and their dependencies to this folder? See the demo project for an example."); } throw; } _appDomainProxy.RunCodeInAppDomain(() => { InitializeApplication(); AttachTestControllerDescriptorsForAllControllers(); LastRequestData.Reset(); }); }
private AppHost(string appPhysicalDirectory, string virtualDirectory = "/") { _appDomainProxy = (AppDomainProxy)ApplicationHost.CreateApplicationHost(typeof(AppDomainProxy), virtualDirectory, appPhysicalDirectory); _appDomainProxy.RunCodeInAppDomain((preInit, postInit) => { if (preInit != null) { preInit.Invoke(); } InitializeApplication(); if (postInit != null) { postInit.Invoke(); } FilterProviders.Providers.Add(new InterceptionFilterProvider()); LastRequestData.Reset(); }, _preInit, _postInit); }