diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeBuilder.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeBuilder.cs
index ec5044425f..218a623f95 100644
--- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeBuilder.cs
+++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeBuilder.cs
@@ -10,6 +10,8 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
{
public class CSharpCodeBuilder : CodeBuilder
{
+ private const int DisableAsyncWarning = 1998;
+
public CSharpCodeBuilder(CodeGeneratorContext context)
: base(context)
{
@@ -57,8 +59,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
// Add space inbetween constructor and method body
writer.WriteLine();
- // 1998 is to not warn about empty async methods.
- using (writer.BuildDisableWarningScope(1998))
+ using (writer.BuildDisableWarningScope(DisableAsyncWarning))
{
using (writer.BuildMethodDeclaration("public override async", "Task", Host.GeneratedClassContext.ExecuteMethodName))
{
diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpDesignTimeHelpersVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpDesignTimeHelpersVisitor.cs
index a84c2672aa..347c8e4542 100644
--- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpDesignTimeHelpersVisitor.cs
+++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpDesignTimeHelpersVisitor.cs
@@ -8,6 +8,8 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
internal const string InheritsHelper = "__inheritsHelper";
internal const string DesignTimeHelperMethodName = "__RazorDesignTimeHelpers__";
+ private const int DisableVariableNamingWarnings = 219;
+
public CSharpDesignTimeHelpersVisitor(CSharpCodeWriter writer, CodeGeneratorContext context)
: base(writer, context) { }
@@ -17,7 +19,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
{
using (Writer.BuildMethodDeclaration("private", "void", "@" + DesignTimeHelperMethodName))
{
- using (Writer.BuildDisableWarningScope(219))
+ using (Writer.BuildDisableWarningScope(DisableVariableNamingWarnings))
{
Accept(tree.Chunks);
}
diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/CodeTree/CSharpCodeBuilderTests.cs b/test/Microsoft.AspNet.Razor.Test/Generator/CodeTree/CSharpCodeBuilderTests.cs
index 19b6c4d619..f35df6e18b 100644
--- a/test/Microsoft.AspNet.Razor.Test/Generator/CodeTree/CSharpCodeBuilderTests.cs
+++ b/test/Microsoft.AspNet.Razor.Test/Generator/CodeTree/CSharpCodeBuilderTests.cs
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using System.Web.WebPages.TestUtils;
using Microsoft.AspNet.Razor.Generator;
-using Microsoft.AspNet.Razor.Generator.Compiler;
-using Microsoft.AspNet.Razor.Generator.Compiler.CSharp;
using Microsoft.AspNet.Razor.Parser.SyntaxTree;
+using Microsoft.AspNet.Razor.Test.Utils;
using Microsoft.TestCommon;
using Moq;
@@ -25,37 +25,13 @@ namespace Microsoft.AspNet.Razor.Test.Generator.CodeTree
// Act
var result = codeBuilder.Build();
+
+ BaselineWriter.WriteBaseline(@"test\Microsoft.AspNet.Razor.Test\TestFiles\CodeGenerator\CS\Output\CSharpCodeBuilder.cs", result.Code);
+
+ var expectedOutput = TestFile.Create("CodeGenerator.CS.Output.CSharpCodeBuilder.cs").ReadAllText();
+
// Assert
- Assert.Equal(@"namespace TestNamespace
-{
-#line 1 """"
-using FakeNamespace1
-
-#line default
-#line hidden
- ;
-#line 1 """"
-using FakeNamespace2.SubNamespace
-
-#line default
-#line hidden
- ;
- using System.Threading.Tasks;
-
- public class TestClass
- {
- #line hidden
- public TestClass()
- {
- }
-
- #pragma warning disable 1998
- public override async Task ExecuteAsync()
- {
- }
- #pragma warning restore 1998
- }
-}", result.Code.TrimEnd());
+ Assert.Equal(expectedOutput, result.Code);
}
}
}
diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs b/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs
index 3dba8b9117..592f847fc2 100644
--- a/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs
+++ b/test/Microsoft.AspNet.Razor.Test/Generator/RazorCodeGeneratorTest.cs
@@ -5,10 +5,7 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics;
-using System.IO;
using System.Linq;
-using System.Text;
using System.Web.WebPages.TestUtils;
using Microsoft.AspNet.Razor.Generator;
using Microsoft.AspNet.Razor.Generator.Compiler;
@@ -145,7 +142,7 @@ namespace Microsoft.AspNet.Razor.Test.Generator
}
// Only called if GENERATE_BASELINES is set, otherwise compiled out.
- WriteBaseline(String.Format(@"test\Microsoft.AspNet.Razor.Test\TestFiles\CodeGenerator\{0}\Output\{1}.{2}", LanguageName, baselineName, BaselineExtension), results.GeneratedCode);
+ BaselineWriter.WriteBaseline(String.Format(@"test\Microsoft.AspNet.Razor.Test\TestFiles\CodeGenerator\{0}\Output\{1}.{2}", LanguageName, baselineName, BaselineExtension), results.GeneratedCode);
#if !GENERATE_BASELINES
string textOutput = results.GeneratedCode;
@@ -191,34 +188,6 @@ namespace Microsoft.AspNet.Razor.Test.Generator
}
}
- [Conditional("GENERATE_BASELINES")]
- private void WriteBaseline(string baselineFile, string output)
- {
- string root = RecursiveFind("Razor.sln", Path.GetFullPath("."));
- string baselinePath = Path.Combine(root, baselineFile);
-
- // Update baseline
- // IMPORTANT! Replace this path with the local path on your machine to the baseline files!
- if (File.Exists(baselinePath))
- {
- File.Delete(baselinePath);
- }
- File.WriteAllText(baselinePath, output.ToString());
- }
-
- private string RecursiveFind(string path, string start)
- {
- string test = Path.Combine(start, path);
- if (File.Exists(test))
- {
- return start;
- }
- else
- {
- return RecursiveFind(path, new DirectoryInfo(start).Parent.FullName);
- }
- }
-
private void VerifyNoBrokenEndOfLines(string text)
{
for (int i = 0; i < text.Length; i++)
diff --git a/test/Microsoft.AspNet.Razor.Test/Microsoft.AspNet.Razor.Test.csproj b/test/Microsoft.AspNet.Razor.Test/Microsoft.AspNet.Razor.Test.csproj
index 3a9ef968e0..719a0201ca 100644
--- a/test/Microsoft.AspNet.Razor.Test/Microsoft.AspNet.Razor.Test.csproj
+++ b/test/Microsoft.AspNet.Razor.Test/Microsoft.AspNet.Razor.Test.csproj
@@ -117,6 +117,7 @@
+
@@ -135,6 +136,7 @@
+
diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/CSharpCodeBuilder.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/CSharpCodeBuilder.cs
new file mode 100644
index 0000000000..89dc8bacb5
--- /dev/null
+++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/CSharpCodeBuilder.cs
@@ -0,0 +1,30 @@
+namespace TestNamespace
+{
+#line 1 ""
+using FakeNamespace1
+
+#line default
+#line hidden
+ ;
+#line 1 ""
+using FakeNamespace2.SubNamespace
+
+#line default
+#line hidden
+ ;
+ using System.Threading.Tasks;
+
+ public class TestClass
+ {
+ #line hidden
+ public TestClass()
+ {
+ }
+
+ #pragma warning disable 1998
+ public override async Task ExecuteAsync()
+ {
+ }
+ #pragma warning restore 1998
+ }
+}
diff --git a/test/Microsoft.AspNet.Razor.Test/Utils/BaselineWriter.cs b/test/Microsoft.AspNet.Razor.Test/Utils/BaselineWriter.cs
new file mode 100644
index 0000000000..553c34aac6
--- /dev/null
+++ b/test/Microsoft.AspNet.Razor.Test/Utils/BaselineWriter.cs
@@ -0,0 +1,36 @@
+using System.Diagnostics;
+using System.IO;
+
+namespace Microsoft.AspNet.Razor.Test.Utils
+{
+ public static class BaselineWriter
+ {
+ [Conditional("GENERATE_BASELINES")]
+ public static void WriteBaseline(string baselineFile, string output)
+ {
+ var root = RecursiveFind("Razor.sln", Path.GetFullPath("."));
+ var baselinePath = Path.Combine(root, baselineFile);
+
+ // Update baseline
+ // IMPORTANT! Replace this path with the local path on your machine to the baseline files!
+ if (File.Exists(baselinePath))
+ {
+ File.Delete(baselinePath);
+ }
+ File.WriteAllText(baselinePath, output.ToString());
+ }
+
+ private static string RecursiveFind(string path, string start)
+ {
+ var test = Path.Combine(start, path);
+ if (File.Exists(test))
+ {
+ return start;
+ }
+ else
+ {
+ return RecursiveFind(path, new DirectoryInfo(start).Parent.FullName);
+ }
+ }
+ }
+}