public void ExtensionNotSupportedTest() { // Tests that calling RenderPage on an unsupported extension returns a new simpler error message // instead of the full error about build providers in system.web.dll. var vpath = "~/hello/world.txt"; var ext = ".txt"; var compilationUtilThrowingBuildManager = new CompilationUtil(); var otherExceptionBuildManager = new Mock<IVirtualPathFactory>(); var msg = "The file \"~/hello/world.txt\" could not be rendered, because it does not exist or is not a valid page."; otherExceptionBuildManager.Setup(c => c.CreateInstance(It.IsAny<string>())).Throws(new HttpException(msg)); Assert.Throws<HttpException>(() => WebPage.CreateInstanceFromVirtualPath(vpath, new VirtualPathFactoryManager(compilationUtilThrowingBuildManager)), String.Format(CultureInfo.CurrentCulture, WebPageResources.WebPage_FileNotSupported, ext, vpath)); // Test that other error messages are thrown unmodified. Assert.Throws<HttpException>(() => WebPage.CreateInstanceFromVirtualPath(vpath, otherExceptionBuildManager.Object), msg); }