示例#1
0
        // We need to construct an IApplicationEnvironment with a base path that that matches this
        // website, in order to find the razor files. This is needed because we don't have a guarantee that
        // the base path of the current app is this site (ex: functional tests).
        public static IServiceProvider ReplaceProvider(IServiceProvider provider)
        {
            var originalEnvironment = provider.GetService <IApplicationEnvironment>();

            var libraryManager = provider.GetService <ILibraryManager>();
            var info           = libraryManager.GetLibraryInformation("PrecompilationWebSite");
            var directory      = Path.GetDirectoryName(info.Path);

            var precompilationApplicationEnvironment = new PrecompilationApplicationEnvironment(
                originalEnvironment,
                directory);

            var collection = HostingServices.Create(provider);

            collection.AddInstance <IApplicationEnvironment>(precompilationApplicationEnvironment);

            return(new DelegatingServiceProvider(provider, collection.BuildServiceProvider()));
        }
示例#2
0
        // When running in memory tests the application base path will point to the functional tests
        // project folder.
        // We need to replace it to point to the actual precompilation website so that the views can
        // be found.
        public static IServiceProvider ReplaceProvider(IServiceProvider provider)
        {
            var originalEnvironment = provider.GetService <IApplicationEnvironment>();
            var newPath             = Path.GetFullPath(
                Path.Combine(
                    originalEnvironment.ApplicationBasePath,
                    "..",
                    "WebSites",
                    "PrecompilationWebSite"));

            var precompilationApplicationEnvironment = new PrecompilationApplicationEnvironment(
                originalEnvironment,
                newPath);

            var collection = HostingServices.Create(provider);

            collection.AddInstance <IApplicationEnvironment>(precompilationApplicationEnvironment);

            return(new DelegatingServiceProvider(provider, collection.BuildServiceProvider()));
        }