Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@ -0,0 +1,291 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Web.Razor.Generator;
using Xunit;
using Xunit.Extensions;
using Assert = Microsoft.TestCommon.AssertEx;
namespace System.Web.Razor.Test.Generator
{
public class CSharpRazorCodeGeneratorTest : RazorCodeGeneratorTest<CSharpRazorCodeLanguage>
{
protected override string FileExtension
{
get { return "cshtml"; }
}
protected override string LanguageName
{
get { return "CS"; }
}
protected override string BaselineExtension
{
get { return "cs"; }
}
private const string TestPhysicalPath = @"C:\Bar.cshtml";
private const string TestVirtualPath = "~/Foo/Bar.cshtml";
[Fact]
public void ConstructorRequiresNonNullClassName()
{
Assert.ThrowsArgumentNullOrEmptyString(() => new CSharpRazorCodeGenerator(null, TestRootNamespaceName, TestPhysicalPath, CreateHost()), "className");
}
[Fact]
public void ConstructorRequiresNonEmptyClassName()
{
Assert.ThrowsArgumentNullOrEmptyString(() => new CSharpRazorCodeGenerator(String.Empty, TestRootNamespaceName, TestPhysicalPath, CreateHost()), "className");
}
[Fact]
public void ConstructorRequiresNonNullRootNamespaceName()
{
Assert.ThrowsArgumentNull(() => new CSharpRazorCodeGenerator("Foo", null, TestPhysicalPath, CreateHost()), "rootNamespaceName");
}
[Fact]
public void ConstructorAllowsEmptyRootNamespaceName()
{
new CSharpRazorCodeGenerator("Foo", String.Empty, TestPhysicalPath, CreateHost());
}
[Fact]
public void ConstructorRequiresNonNullHost()
{
Assert.ThrowsArgumentNull(() => new CSharpRazorCodeGenerator("Foo", TestRootNamespaceName, TestPhysicalPath, null), "host");
}
[Theory]
[InlineData("NestedCodeBlocks")]
[InlineData("CodeBlock")]
[InlineData("ExplicitExpression")]
[InlineData("MarkupInCodeBlock")]
[InlineData("Blocks")]
[InlineData("ImplicitExpression")]
[InlineData("Imports")]
[InlineData("ExpressionsInCode")]
[InlineData("FunctionsBlock")]
[InlineData("Templates")]
[InlineData("Sections")]
[InlineData("RazorComments")]
[InlineData("Helpers")]
[InlineData("HelpersMissingCloseParen")]
[InlineData("HelpersMissingOpenBrace")]
[InlineData("HelpersMissingOpenParen")]
[InlineData("NestedHelpers")]
[InlineData("InlineBlocks")]
[InlineData("NestedHelpers")]
[InlineData("LayoutDirective")]
[InlineData("ConditionalAttributes")]
[InlineData("ResolveUrl")]
public void CSharpCodeGeneratorCorrectlyGeneratesRunTimeCode(string testType)
{
RunTest(testType);
}
//// To regenerate individual baselines, uncomment this and set the appropriate test name in the Inline Data.
//// Please comment out again after regenerating.
//// TODO: Remove this when we go to a Source Control system that doesn't lock files, thus requiring we unlock them to regenerate them :(
//[Theory]
//[InlineData("ConditionalAttributes")]
//public void CSharpCodeGeneratorCorrectlyGeneratesRunTimeCode2(string testType)
//{
// RunTest(testType);
//}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesMappingsForRazorCommentsAtDesignTime()
{
RunTest("RazorComments", "RazorComments.DesignTime", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(4, 3, 3, 6),
/* 02 */ new GeneratedCodeMapping(5, 40, 39, 22),
/* 03 */ new GeneratedCodeMapping(6, 50, 49, 58),
/* 04 */ new GeneratedCodeMapping(12, 3, 3, 24),
/* 05 */ new GeneratedCodeMapping(13, 46, 46, 3),
/* 06 */ new GeneratedCodeMapping(15, 3, 7, 1),
/* 07 */ new GeneratedCodeMapping(15, 8, 8, 1)
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesImportStatementsAtDesignTime()
{
RunTest("Imports", "Imports.DesignTime", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 2, 1, 15),
/* 02 */ new GeneratedCodeMapping(2, 2, 1, 32),
/* 03 */ new GeneratedCodeMapping(3, 2, 1, 12),
/* 04 */ new GeneratedCodeMapping(5, 30, 30, 21),
/* 05 */ new GeneratedCodeMapping(6, 36, 36, 20),
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesFunctionsBlocksAtDesignTime()
{
RunTest("FunctionsBlock", "FunctionsBlock.DesignTime", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 13, 13, 4),
/* 02 */ new GeneratedCodeMapping(5, 13, 13, 104),
/* 03 */ new GeneratedCodeMapping(12, 26, 26, 11)
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesHiddenSpansWithinCode()
{
RunTest("HiddenSpansInCode", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>
{
/* 01 */ new GeneratedCodeMapping(1, 3, 3, 6),
/* 02 */ new GeneratedCodeMapping(2, 6, 6, 5)
});
}
[Fact]
public void CSharpCodeGeneratorGeneratesCodeWithParserErrorsInDesignTimeMode()
{
RunTest("ParserError", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 3, 3, 31)
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesInheritsAtRuntime()
{
RunTest("Inherits", baselineName: "Inherits.Runtime");
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesInheritsAtDesigntime()
{
RunTest("Inherits", baselineName: "Inherits.Designtime", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 2, 7, 5),
/* 02 */ new GeneratedCodeMapping(3, 11, 11, 25),
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesDesignTimePragmasForUnfinishedExpressionsInCode()
{
RunTest("UnfinishedExpressionInCode", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 3, 3, 2),
/* 02 */ new GeneratedCodeMapping(2, 2, 7, 9),
/* 03 */ new GeneratedCodeMapping(2, 11, 11, 2)
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesDesignTimePragmasMarkupAndExpressions()
{
RunTest("DesignTime", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(2, 14, 13, 36),
/* 02 */ new GeneratedCodeMapping(3, 23, 23, 1),
/* 03 */ new GeneratedCodeMapping(3, 28, 28, 15),
/* 04 */ new GeneratedCodeMapping(8, 3, 7, 12),
/* 05 */ new GeneratedCodeMapping(9, 2, 7, 4),
/* 06 */ new GeneratedCodeMapping(9, 15, 15, 3),
/* 07 */ new GeneratedCodeMapping(9, 26, 26, 1),
/* 08 */ new GeneratedCodeMapping(14, 6, 7, 3),
/* 09 */ new GeneratedCodeMapping(17, 9, 24, 7),
/* 10 */ new GeneratedCodeMapping(17, 16, 16, 26),
/* 11 */ new GeneratedCodeMapping(19, 19, 19, 9),
/* 12 */ new GeneratedCodeMapping(21, 1, 1, 1)
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesDesignTimePragmasForImplicitExpressionStartedAtEOF()
{
RunTest("ImplicitExpressionAtEOF", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(3, 2, 7, 0)
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesDesignTimePragmasForExplicitExpressionStartedAtEOF()
{
RunTest("ExplicitExpressionAtEOF", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(3, 3, 7, 0)
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesDesignTimePragmasForCodeBlockStartedAtEOF()
{
RunTest("CodeBlockAtEOF", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 3, 3, 0)
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesDesignTimePragmasForEmptyImplicitExpression()
{
RunTest("EmptyImplicitExpression", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(3, 2, 7, 0)
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesDesignTimePragmasForEmptyImplicitExpressionInCode()
{
RunTest("EmptyImplicitExpressionInCode", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 3, 3, 6),
/* 02 */ new GeneratedCodeMapping(2, 6, 7, 0),
/* 03 */ new GeneratedCodeMapping(2, 6, 6, 2)
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesDesignTimePragmasForEmptyExplicitExpression()
{
RunTest("EmptyExplicitExpression", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(3, 3, 7, 0)
});
}
[Fact]
public void CSharpCodeGeneratorCorrectlyGeneratesDesignTimePragmasForEmptyCodeBlock()
{
RunTest("EmptyCodeBlock", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(3, 3, 3, 0)
});
}
[Fact]
public void CSharpCodeGeneratorDoesNotRenderLinePragmasIfGenerateLinePragmasIsSetToFalse()
{
RunTest("NoLinePragmas", generatePragmas: false);
}
[Fact]
public void CSharpCodeGeneratorRendersHelpersBlockCorrectlyWhenInstanceHelperRequested()
{
RunTest("Helpers", baselineName: "Helpers.Instance", hostConfig: h => h.StaticHelpers = false);
}
[Fact]
public void CSharpCodeGeneratorCorrectlyInstrumentsRazorCodeWhenInstrumentationRequested()
{
RunTest("Instrumented", hostConfig: host =>
{
host.EnableInstrumentation = true;
host.InstrumentedSourceFilePath = String.Format("~/{0}.cshtml", host.DefaultClassName);
});
}
}
}

View File

@ -0,0 +1,65 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Web.Razor.Generator;
using Xunit;
namespace System.Web.Razor.Test.Generator
{
public class GeneratedCodeMappingTest
{
[Fact]
public void GeneratedCodeMappingsAreEqualIfDataIsEqual()
{
GeneratedCodeMapping left = new GeneratedCodeMapping(12, 34, 56, 78);
GeneratedCodeMapping right = new GeneratedCodeMapping(12, 34, 56, 78);
Assert.True(left == right);
Assert.True(left.Equals(right));
Assert.True(right.Equals(left));
Assert.True(Equals(left, right));
}
[Fact]
public void GeneratedCodeMappingsAreNotEqualIfCodeLengthIsNotEqual()
{
GeneratedCodeMapping left = new GeneratedCodeMapping(12, 34, 56, 87);
GeneratedCodeMapping right = new GeneratedCodeMapping(12, 34, 56, 78);
Assert.False(left == right);
Assert.False(left.Equals(right));
Assert.False(right.Equals(left));
Assert.False(Equals(left, right));
}
[Fact]
public void GeneratedCodeMappingsAreNotEqualIfStartGeneratedColumnIsNotEqual()
{
GeneratedCodeMapping left = new GeneratedCodeMapping(12, 34, 56, 87);
GeneratedCodeMapping right = new GeneratedCodeMapping(12, 34, 65, 87);
Assert.False(left == right);
Assert.False(left.Equals(right));
Assert.False(right.Equals(left));
Assert.False(Equals(left, right));
}
[Fact]
public void GeneratedCodeMappingsAreNotEqualIfStartColumnIsNotEqual()
{
GeneratedCodeMapping left = new GeneratedCodeMapping(12, 34, 56, 87);
GeneratedCodeMapping right = new GeneratedCodeMapping(12, 43, 56, 87);
Assert.False(left == right);
Assert.False(left.Equals(right));
Assert.False(right.Equals(left));
Assert.False(Equals(left, right));
}
[Fact]
public void GeneratedCodeMappingsAreNotEqualIfStartLineIsNotEqual()
{
GeneratedCodeMapping left = new GeneratedCodeMapping(12, 34, 56, 87);
GeneratedCodeMapping right = new GeneratedCodeMapping(21, 34, 56, 87);
Assert.False(left == right);
Assert.False(left.Equals(right));
Assert.False(right.Equals(left));
Assert.False(Equals(left, right));
}
}
}

View File

@ -0,0 +1,148 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
//#define GENERATE_BASELINES
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Razor.Generator;
using System.Web.Razor.Test.Utils;
using System.Web.WebPages.TestUtils;
using Xunit;
namespace System.Web.Razor.Test.Generator
{
public abstract class RazorCodeGeneratorTest<TLanguage>
where TLanguage : RazorCodeLanguage, new()
{
protected static readonly string TestRootNamespaceName = "TestOutput";
protected abstract string FileExtension { get; }
protected abstract string LanguageName { get; }
protected abstract string BaselineExtension { get; }
protected RazorEngineHost CreateHost()
{
return new RazorEngineHost(new TLanguage());
}
protected void RunTest(string name, string baselineName = null, bool generatePragmas = true, bool designTimeMode = false, IList<GeneratedCodeMapping> expectedDesignTimePragmas = null, Action<RazorEngineHost> hostConfig = null)
{
// Load the test files
if (baselineName == null)
{
baselineName = name;
}
string source = TestFile.Create(String.Format("CodeGenerator.{1}.Source.{0}.{2}", name, LanguageName, FileExtension)).ReadAllText();
string expectedOutput = TestFile.Create(String.Format("CodeGenerator.{1}.Output.{0}.{2}", baselineName, LanguageName, BaselineExtension)).ReadAllText();
// Set up the host and engine
RazorEngineHost host = CreateHost();
host.NamespaceImports.Add("System");
host.DesignTimeMode = designTimeMode;
host.StaticHelpers = true;
host.DefaultClassName = name;
// Add support for templates, etc.
host.GeneratedClassContext = new GeneratedClassContext(GeneratedClassContext.DefaultExecuteMethodName,
GeneratedClassContext.DefaultWriteMethodName,
GeneratedClassContext.DefaultWriteLiteralMethodName,
"WriteTo",
"WriteLiteralTo",
"Template",
"DefineSection",
"BeginContext",
"EndContext")
{
LayoutPropertyName = "Layout",
ResolveUrlMethodName = "Href"
};
if (hostConfig != null)
{
hostConfig(host);
}
RazorTemplateEngine engine = new RazorTemplateEngine(host);
// Generate code for the file
GeneratorResults results = null;
using (StringTextBuffer buffer = new StringTextBuffer(source))
{
results = engine.GenerateCode(buffer, className: name, rootNamespace: TestRootNamespaceName, sourceFileName: generatePragmas ? String.Format("{0}.{1}", name, FileExtension) : null);
}
// Generate code
CodeCompileUnit ccu = results.GeneratedCode;
CodeDomProvider codeProvider = (CodeDomProvider)Activator.CreateInstance(host.CodeLanguage.CodeDomProviderType);
CodeGeneratorOptions options = new CodeGeneratorOptions();
// Both run-time and design-time use these settings. See:
// * $/Dev10/pu/SP_WebTools/venus/html/Razor/Impl/RazorCodeGenerator.cs:204
// * $/Dev10/Releases/RTMRel/ndp/fx/src/xsp/System/Web/Compilation/BuildManagerHost.cs:373
options.BlankLinesBetweenMembers = false;
options.IndentString = String.Empty;
StringBuilder output = new StringBuilder();
using (StringWriter writer = new StringWriter(output))
{
codeProvider.GenerateCodeFromCompileUnit(ccu, writer, options);
}
WriteBaseline(String.Format(@"test\System.Web.Razor.Test\TestFiles\CodeGenerator\{0}\Output\{1}.{2}", LanguageName, baselineName, BaselineExtension), MiscUtils.StripRuntimeVersion(output.ToString()));
// Verify code against baseline
#if !GENERATE_BASELINES
Assert.Equal(expectedOutput, MiscUtils.StripRuntimeVersion(output.ToString()));
#endif
// Verify design-time pragmas
if (designTimeMode)
{
Assert.True(expectedDesignTimePragmas != null || results.DesignTimeLineMappings == null || results.DesignTimeLineMappings.Count == 0);
Assert.True(expectedDesignTimePragmas == null || (results.DesignTimeLineMappings != null && results.DesignTimeLineMappings.Count > 0));
if (expectedDesignTimePragmas != null)
{
Assert.Equal(
expectedDesignTimePragmas.ToArray(),
results.DesignTimeLineMappings
.OrderBy(p => p.Key)
.Select(p => p.Value)
.ToArray());
}
}
}
[Conditional("GENERATE_BASELINES")]
private void WriteBaseline(string baselineFile, string output)
{
string root = RecursiveFind("Runtime.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);
}
}
}
}

View File

@ -0,0 +1,280 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Web.Razor.Generator;
using Xunit;
using Xunit.Extensions;
using Assert = Microsoft.TestCommon.AssertEx;
namespace System.Web.Razor.Test.Generator
{
public class VBRazorCodeGeneratorTest : RazorCodeGeneratorTest<VBRazorCodeLanguage>
{
private const string TestPhysicalPath = @"C:\Bar.vbhtml";
private const string TestVirtualPath = "~/Foo/Bar.vbhtml";
protected override string FileExtension
{
get { return "vbhtml"; }
}
protected override string LanguageName
{
get { return "VB"; }
}
protected override string BaselineExtension
{
get { return "vb"; }
}
[Fact]
public void ConstructorRequiresNonNullClassName()
{
Assert.ThrowsArgumentNullOrEmptyString(() => new VBRazorCodeGenerator(null, TestRootNamespaceName, TestPhysicalPath, CreateHost()), "className");
}
[Fact]
public void ConstructorRequiresNonEmptyClassName()
{
Assert.ThrowsArgumentNullOrEmptyString(() => new VBRazorCodeGenerator(String.Empty, TestRootNamespaceName, TestPhysicalPath, CreateHost()), "className");
}
[Fact]
public void ConstructorRequiresNonNullRootNamespaceName()
{
Assert.ThrowsArgumentNull(() => new VBRazorCodeGenerator("Foo", null, TestPhysicalPath, CreateHost()), "rootNamespaceName");
}
[Fact]
public void ConstructorAllowsEmptyRootNamespaceName()
{
new VBRazorCodeGenerator("Foo", String.Empty, TestPhysicalPath, CreateHost());
}
[Fact]
public void ConstructorRequiresNonNullHost()
{
Assert.ThrowsArgumentNull(() => new VBRazorCodeGenerator("Foo", TestRootNamespaceName, TestPhysicalPath, null), "host");
}
[Theory]
[InlineData("NestedCodeBlocks")]
[InlineData("NestedCodeBlocks")]
[InlineData("CodeBlock")]
[InlineData("ExplicitExpression")]
[InlineData("MarkupInCodeBlock")]
[InlineData("Blocks")]
[InlineData("ImplicitExpression")]
[InlineData("Imports")]
[InlineData("ExpressionsInCode")]
[InlineData("FunctionsBlock")]
[InlineData("Options")]
[InlineData("Templates")]
[InlineData("RazorComments")]
[InlineData("Sections")]
[InlineData("Helpers")]
[InlineData("HelpersMissingCloseParen")]
[InlineData("HelpersMissingOpenParen")]
[InlineData("NestedHelpers")]
[InlineData("LayoutDirective")]
[InlineData("ConditionalAttributes")]
[InlineData("ResolveUrl")]
public void VBCodeGeneratorCorrectlyGeneratesRunTimeCode(string testName)
{
RunTest(testName);
}
//// To regenerate individual baselines, uncomment this and set the appropriate test name in the Inline Data.
//// Please comment out again after regenerating.
//// TODO: Remove this when we go to a Source Control system that doesn't lock files, thus requiring we unlock them to regenerate them :(
//[Theory]
//[InlineData("RazorComments")]
//public void VBCodeGeneratorCorrectlyGeneratesRunTimeCode2(string testType)
//{
// RunTest(testType);
//}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesMappingsForRazorCommentsAtDesignTime()
{
// (4, 6) -> (?, 6) [6]
// ( 5, 40) -> (?, 39) [2]
// ( 8, 6) -> (?, 6) [33]
// ( 9, 46) -> (?, 46) [3]
// ( 12, 3) -> (?, 7) [3]
// ( 12, 8) -> (?, 8) [1]
RunTest("RazorComments", "RazorComments.DesignTime", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(4, 6, 6, 6),
/* 02 */ new GeneratedCodeMapping(5, 40, 39, 2),
/* 03 */ new GeneratedCodeMapping(8, 6, 6, 33),
/* 04 */ new GeneratedCodeMapping(9, 46, 46, 3),
/* 05 */ new GeneratedCodeMapping(12, 3, 7, 1),
/* 06 */ new GeneratedCodeMapping(12, 8, 8, 1)
});
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesHelperMissingNameAtDesignTime()
{
RunTest("HelpersMissingName", designTimeMode: true);
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesImportStatementsAtDesignTimeButCannotWrapPragmasAroundImportStatement()
{
RunTest("Imports", "Imports.DesignTime", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 2, 1, 19),
/* 02 */ new GeneratedCodeMapping(2, 2, 1, 36),
/* 03 */ new GeneratedCodeMapping(3, 2, 1, 16),
/* 04 */ new GeneratedCodeMapping(5, 30, 30, 22),
/* 05 */ new GeneratedCodeMapping(6, 36, 36, 21),
});
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesFunctionsBlocksAtDesignTime()
{
RunTest("FunctionsBlock", "FunctionsBlock.DesignTime", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 11, 11, 4),
/* 02 */ new GeneratedCodeMapping(5, 11, 11, 129),
/* 03 */ new GeneratedCodeMapping(12, 26, 26, 11)
});
}
[Fact]
public void VBCodeGeneratorGeneratesCodeWithParserErrorsInDesignTimeMode()
{
RunTest("ParserError", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 6, 6, 16)
});
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesInheritsAtRuntime()
{
RunTest("Inherits", baselineName: "Inherits.Runtime");
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesInheritsAtDesigntime()
{
RunTest("Inherits", baselineName: "Inherits.Designtime", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 11, 25, 27)
});
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesDesignTimePragmasForUnfinishedExpressionsInCode()
{
RunTest("UnfinishedExpressionInCode", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 6, 6, 2),
/* 02 */ new GeneratedCodeMapping(2, 2, 7, 9),
/* 03 */ new GeneratedCodeMapping(2, 11, 11, 2)
});
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesDesignTimePragmasMarkupAndExpressions()
{
RunTest("DesignTime", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(2, 14, 13, 17),
/* 02 */ new GeneratedCodeMapping(3, 20, 20, 1),
/* 03 */ new GeneratedCodeMapping(3, 25, 25, 20),
/* 04 */ new GeneratedCodeMapping(8, 3, 7, 12),
/* 05 */ new GeneratedCodeMapping(9, 2, 7, 4),
/* 06 */ new GeneratedCodeMapping(9, 16, 16, 3),
/* 07 */ new GeneratedCodeMapping(9, 27, 27, 1),
/* 08 */ new GeneratedCodeMapping(14, 6, 7, 3),
/* 09 */ new GeneratedCodeMapping(17, 9, 24, 5),
/* 10 */ new GeneratedCodeMapping(17, 14, 14, 28),
/* 11 */ new GeneratedCodeMapping(19, 20, 20, 14)
});
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesDesignTimePragmasForImplicitExpressionStartedAtEOF()
{
RunTest("ImplicitExpressionAtEOF", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(3, 2, 7, 0)
});
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesDesignTimePragmasForExplicitExpressionStartedAtEOF()
{
RunTest("ExplicitExpressionAtEOF", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(3, 3, 7, 0)
});
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesDesignTimePragmasForCodeBlockStartedAtEOF()
{
RunTest("CodeBlockAtEOF", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(3, 6, 6, 0)
});
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesDesignTimePragmasForEmptyImplicitExpression()
{
RunTest("EmptyImplicitExpression", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(3, 2, 7, 0)
});
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesDesignTimePragmasForEmptyImplicitExpressionInCode()
{
RunTest("EmptyImplicitExpressionInCode", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(1, 6, 6, 6),
/* 02 */ new GeneratedCodeMapping(2, 6, 7, 0),
/* 03 */ new GeneratedCodeMapping(2, 6, 6, 2)
});
}
[Fact]
public void VBCodeGeneratorCorrectlyGeneratesDesignTimePragmasForEmptyExplicitExpression()
{
RunTest("EmptyExplicitExpression", designTimeMode: true, expectedDesignTimePragmas: new List<GeneratedCodeMapping>()
{
/* 01 */ new GeneratedCodeMapping(3, 3, 7, 0)
});
}
[Fact]
public void VBCodeGeneratorDoesNotRenderLinePragmasIfGenerateLinePragmasIsSetToFalse()
{
RunTest("NoLinePragmas", generatePragmas: false);
}
[Fact]
public void VBCodeGeneratorRendersHelpersBlockCorrectlyWhenInstanceHelperRequested()
{
RunTest("Helpers", baselineName: "Helpers.Instance", hostConfig: h => h.StaticHelpers = false);
}
[Fact]
public void VBCodeGeneratorCorrectlyInstrumentsRazorCodeWhenInstrumentationRequested()
{
RunTest("Instrumented", hostConfig: host =>
{
host.EnableInstrumentation = true;
host.InstrumentedSourceFilePath = String.Format("~/{0}.vbhtml", host.DefaultClassName);
});
}
}
}