Modify MvcRazorHost to use a fixed namespace for generated views.

Fixes #554
This commit is contained in:
Pranav K 2014-05-20 16:55:46 -07:00
parent a53e378cf4
commit 0c66074033
4 changed files with 7 additions and 5 deletions

View File

@ -8,6 +8,6 @@ namespace Microsoft.AspNet.Mvc.Razor
{
public interface IMvcRazorHost
{
GeneratorResults GenerateCode(string rootNamespace, string rootRelativePath, Stream inputStream);
GeneratorResults GenerateCode(string rootRelativePath, Stream inputStream);
}
}

View File

@ -11,6 +11,8 @@ namespace Microsoft.AspNet.Mvc.Razor
{
public class MvcRazorHost : RazorEngineHost, IMvcRazorHost
{
private const string ViewNamespace = "ASP";
private static readonly string[] _defaultNamespaces = new[]
{
"System",
@ -53,13 +55,13 @@ namespace Microsoft.AspNet.Mvc.Razor
}
}
public GeneratorResults GenerateCode(string rootNamespace, string rootRelativePath, Stream inputStream)
public GeneratorResults GenerateCode(string rootRelativePath, Stream inputStream)
{
string className = ParserHelpers.SanitizeClassName(rootRelativePath);
using (var reader = new StreamReader(inputStream))
{
var engine = new RazorTemplateEngine(this);
return engine.GenerateCode(reader, className, rootNamespace, rootRelativePath);
return engine.GenerateCode(reader, className, ViewNamespace, rootRelativePath);
}
}

View File

@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.Razor
{
Contract.Assert(file.PhysicalPath.StartsWith(_appRoot, StringComparison.OrdinalIgnoreCase));
var rootRelativePath = file.PhysicalPath.Substring(_appRoot.Length);
results = _razorHost.GenerateCode(_environment.ApplicationName, rootRelativePath, inputStream);
results = _razorHost.GenerateCode(rootRelativePath, inputStream);
}
if (!results.Success)

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
env.SetupGet(e => e.ApplicationName).Returns("MyTestApplication");
env.SetupGet(e => e.ApplicationBasePath).Returns(appPath);
var host = new Mock<IMvcRazorHost>();
host.Setup(h => h.GenerateCode("MyTestApplication", @"views\index\home.cshtml", It.IsAny<Stream>()))
host.Setup(h => h.GenerateCode(@"views\index\home.cshtml", It.IsAny<Stream>()))
.Returns(new GeneratorResults(new Block(new BlockBuilder { Type = BlockType.Comment }), new RazorError[0], new CodeBuilderResult("", new LineMapping[0])))
.Verifiable();
var compiler = new Mock<ICompilationService>();