Exemplo n.º 1
0
        /// <summary>
        /// According to referencesource.microsoft.com, this is routed through Request.MapPath, which we expect most testers will by mocking or replacing.
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public override string MapPath(string path)
        {
            if (!WebApplicationProxy.IsInitialized)
            {
                throw new InvalidOperationException("WebApplicationProxy needs to be initialized before using MapPath");
            }

            // NOTE: YAGNI -- make this a simple implementation that concatenates the two paths

            var vpath = VirtualPathWrapper.Create(path);

            // Drop initial slash before we join paths
            var virtualPathString = vpath.VirtualPathString.Substring(1);

            return(System.IO.Path.Combine(WebApplicationProxy.WebRootFolder, virtualPathString));
        }
        /// <summary>
        /// Add some needed configuration to the HttpRuntime so that it thinks we are running in a Web Service
        /// </summary>
        private static void InjectTestValuesIntoHttpRuntime()
        {
            var p = typeof(HttpRuntime).GetField("_appDomainAppVPath", BindingFlags.NonPublic | BindingFlags.Instance);

            p.SetValue(HttpRuntimeInstance, VirtualPathWrapper.Create("/").VirtualPath);
        }