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,71 @@
// 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;
using Moq;
using Xunit;
namespace System.Web.Mvc.Razor.Test
{
public class MvcCSharpRazorCodeGeneratorTest
{
[Fact]
public void Constructor()
{
// Arrange
Mock<RazorEngineHost> mockHost = new Mock<RazorEngineHost>();
// Act
var generator = new MvcCSharpRazorCodeGenerator("FooClass", "Root.Namespace", "SomeSourceFile.cshtml", mockHost.Object);
// Assert
Assert.Equal("FooClass", generator.ClassName);
Assert.Equal("Root.Namespace", generator.RootNamespaceName);
Assert.Equal("SomeSourceFile.cshtml", generator.SourceFileName);
Assert.Same(mockHost.Object, generator.Host);
}
[Fact]
public void Constructor_DoesNotSetBaseTypeForNonMvcHost()
{
// Arrange
Mock<RazorEngineHost> mockHost = new Mock<RazorEngineHost>();
mockHost.SetupGet(h => h.NamespaceImports).Returns(new HashSet<string>());
// Act
var generator = new MvcCSharpRazorCodeGenerator("FooClass", "Root.Namespace", "SomeSourceFile.cshtml", mockHost.Object);
// Assert
Assert.Equal(0, generator.Context.GeneratedClass.BaseTypes.Count);
}
[Fact]
public void Constructor_DoesNotSetBaseTypeForSpecialPage()
{
// Arrange
Mock<MvcWebPageRazorHost> mockHost = new Mock<MvcWebPageRazorHost>("_viewStart.cshtml", "_viewStart.cshtml");
mockHost.SetupGet(h => h.NamespaceImports).Returns(new HashSet<string>());
// Act
var generator = new MvcCSharpRazorCodeGenerator("FooClass", "Root.Namespace", "_viewStart.cshtml", mockHost.Object);
// Assert
Assert.Equal(0, generator.Context.GeneratedClass.BaseTypes.Count);
}
[Fact]
public void Constructor_SetsBaseTypeForRegularPage()
{
// Arrange
Mock<MvcWebPageRazorHost> mockHost = new Mock<MvcWebPageRazorHost>("SomeSourceFile.cshtml", "SomeSourceFile.cshtml") { CallBase = true };
mockHost.SetupGet(h => h.NamespaceImports).Returns(new HashSet<string>());
// Act
var generator = new MvcCSharpRazorCodeGenerator("FooClass", "Root.Namespace", "SomeSourceFile.cshtml", mockHost.Object);
// Assert
Assert.Equal(1, generator.Context.GeneratedClass.BaseTypes.Count);
Assert.Equal("System.Web.Mvc.WebViewPage<dynamic>", generator.Context.GeneratedClass.BaseTypes[0].BaseType);
}
}
}

View File

@@ -0,0 +1,286 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using System.Web.Razor;
using System.Web.Razor.Generator;
using System.Web.Razor.Parser;
using System.Web.Razor.Parser.SyntaxTree;
using System.Web.Razor.Test.Framework;
using System.Web.Razor.Text;
using Xunit;
namespace System.Web.Mvc.Razor.Test
{
public class MvcCSharpRazorCodeParserTest
{
[Fact]
public void Constructor_AddsModelKeyword()
{
var parser = new TestMvcCSharpRazorCodeParser();
Assert.True(parser.HasDirective("model"));
}
[Fact]
public void ParseModelKeyword_HandlesSingleInstance()
{
// Arrange + Act
var document = "@model Foo";
var spans = ParseDocument(document);
// Assert
var factory = SpanFactory.CreateCsHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None),
factory.Code(" Foo")
.As(new SetModelTypeCodeGenerator("Foo", "{0}<{1}>"))
};
Assert.Equal(expectedSpans, spans.ToArray());
}
[Fact]
public void ParseModelKeyword_HandlesNullableTypes()
{
// Arrange + Act
var document = "@model Foo?\r\nBar";
var spans = ParseDocument(document);
// Assert
var factory = SpanFactory.CreateCsHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None),
factory.Code("Foo?\r\n")
.As(new SetModelTypeCodeGenerator("Foo?", "{0}<{1}>")),
factory.Markup("Bar")
.With(new MarkupCodeGenerator())
};
Assert.Equal(expectedSpans, spans.ToArray());
}
[Fact]
public void ParseModelKeyword_HandlesArrays()
{
// Arrange + Act
var document = "@model Foo[[]][]\r\nBar";
var spans = ParseDocument(document);
// Assert
var factory = SpanFactory.CreateCsHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None),
factory.Code("Foo[[]][]\r\n")
.As(new SetModelTypeCodeGenerator("Foo[[]][]", "{0}<{1}>")),
factory.Markup("Bar")
.With(new MarkupCodeGenerator())
};
Assert.Equal(expectedSpans, spans.ToArray());
}
[Fact]
public void ParseModelKeyword_HandlesVSTemplateSyntax()
{
// Arrange + Act
var document = "@model $rootnamespace$.MyModel";
var spans = ParseDocument(document);
// Assert
var factory = SpanFactory.CreateCsHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None),
factory.Code("$rootnamespace$.MyModel")
.As(new SetModelTypeCodeGenerator("$rootnamespace$.MyModel", "{0}<{1}>"))
};
Assert.Equal(expectedSpans, spans.ToArray());
}
[Fact]
public void ParseModelKeyword_ErrorOnMissingModelType()
{
// Arrange + Act
List<RazorError> errors = new List<RazorError>();
var document = "@model ";
var spans = ParseDocument(document, errors);
// Assert
var factory = SpanFactory.CreateCsHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None),
factory.Code(" ")
.As(new SetModelTypeCodeGenerator(String.Empty, "{0}<{1}>")),
};
var expectedErrors = new[]
{
new RazorError("The 'model' keyword must be followed by a type name on the same line.", new SourceLocation(9, 0, 9), 1)
};
Assert.Equal(expectedSpans, spans.ToArray());
Assert.Equal(expectedErrors, errors.ToArray());
}
[Fact]
public void ParseModelKeyword_ErrorOnMultipleModelStatements()
{
// Arrange + Act
List<RazorError> errors = new List<RazorError>();
var document =
@"@model Foo
@model Bar";
var spans = ParseDocument(document, errors);
// Assert
var factory = SpanFactory.CreateCsHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None),
factory.Code("Foo\r\n")
.As(new SetModelTypeCodeGenerator("Foo", "{0}<{1}>")),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None),
factory.Code("Bar")
.As(new SetModelTypeCodeGenerator("Bar", "{0}<{1}>"))
};
var expectedErrors = new[]
{
new RazorError("Only one 'model' statement is allowed in a file.", new SourceLocation(18, 1, 6), 1)
};
expectedSpans.Zip(spans, (exp, span) => new { expected = exp, span = span }).ToList().ForEach(i => Assert.Equal(i.expected, i.span));
Assert.Equal(expectedSpans, spans.ToArray());
Assert.Equal(expectedErrors, errors.ToArray());
}
[Fact]
public void ParseModelKeyword_ErrorOnModelFollowedByInherits()
{
// Arrange + Act
List<RazorError> errors = new List<RazorError>();
var document =
@"@model Foo
@inherits Bar";
var spans = ParseDocument(document, errors);
// Assert
var factory = SpanFactory.CreateCsHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None),
factory.Code("Foo\r\n")
.As(new SetModelTypeCodeGenerator("Foo", "{0}<{1}>")),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("inherits ")
.Accepts(AcceptedCharacters.None),
factory.Code("Bar")
.As(new SetBaseTypeCodeGenerator("Bar"))
};
var expectedErrors = new[]
{
new RazorError("The 'inherits' keyword is not allowed when a 'model' keyword is used.", new SourceLocation(21, 1, 9), 1)
};
expectedSpans.Zip(spans, (exp, span) => new { expected = exp, span = span }).ToList().ForEach(i => Assert.Equal(i.expected, i.span));
Assert.Equal(expectedSpans, spans.ToArray());
Assert.Equal(expectedErrors, errors.ToArray());
}
[Fact]
public void ParseModelKeyword_ErrorOnInheritsFollowedByModel()
{
// Arrange + Act
List<RazorError> errors = new List<RazorError>();
var document =
@"@inherits Bar
@model Foo";
var spans = ParseDocument(document, errors);
// Assert
var factory = SpanFactory.CreateCsHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("inherits ")
.Accepts(AcceptedCharacters.None),
factory.Code("Bar\r\n")
.As(new SetBaseTypeCodeGenerator("Bar")),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("model ")
.Accepts(AcceptedCharacters.None),
factory.Code("Foo")
.As(new SetModelTypeCodeGenerator("Foo", "{0}<{1}>"))
};
var expectedErrors = new[]
{
new RazorError("The 'inherits' keyword is not allowed when a 'model' keyword is used.", new SourceLocation(9, 0, 9), 1)
};
expectedSpans.Zip(spans, (exp, span) => new { expected = exp, span = span }).ToList().ForEach(i => Assert.Equal(i.expected, i.span));
Assert.Equal(expectedSpans, spans.ToArray());
Assert.Equal(expectedErrors, errors.ToArray());
}
private static List<Span> ParseDocument(string documentContents, IList<RazorError> errors = null)
{
errors = errors ?? new List<RazorError>();
var markupParser = new HtmlMarkupParser();
var codeParser = new TestMvcCSharpRazorCodeParser();
var context = new ParserContext(new SeekableTextReader(documentContents), codeParser, markupParser, markupParser);
codeParser.Context = context;
markupParser.Context = context;
markupParser.ParseDocument();
ParserResults results = context.CompleteParse();
foreach (RazorError error in results.ParserErrors)
{
errors.Add(error);
}
return results.Document.Flatten().ToList();
}
private sealed class TestMvcCSharpRazorCodeParser : MvcCSharpRazorCodeParser
{
public bool HasDirective(string directive)
{
Action handler;
return TryGetDirectiveHandler(directive, out handler);
}
}
}
}

View File

@@ -0,0 +1,303 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
using System.Web.Razor;
using System.Web.Razor.Generator;
using System.Web.Razor.Parser;
using System.Web.Razor.Parser.SyntaxTree;
using System.Web.Razor.Test.Framework;
using System.Web.Razor.Text;
using Xunit;
namespace System.Web.Mvc.Razor.Test
{
public class MvcVBRazorCodeParserTest
{
[Fact]
public void Constructor_AddsModelKeyword()
{
var parser = new MvcVBRazorCodeParser();
Assert.True(parser.IsDirectiveDefined(MvcVBRazorCodeParser.ModelTypeKeyword));
}
[Fact]
public void ParseModelKeyword_HandlesSingleInstance()
{
// Arrange + Act
var document = "@ModelType Foo";
var spans = ParseDocument(document);
// Assert
var factory = SpanFactory.CreateVbHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("ModelType ")
.Accepts(AcceptedCharacters.None),
factory.Code("Foo")
.As(new SetModelTypeCodeGenerator("Foo", "{0}(Of {1})"))
};
Assert.Equal(expectedSpans, spans.ToArray());
}
[Fact]
public void ParseModelKeyword_HandlesNullableTypes()
{
// Arrange + Act
var document = "@ModelType Foo?\r\nBar";
var spans = ParseDocument(document);
// Assert
var factory = SpanFactory.CreateVbHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("ModelType ")
.Accepts(AcceptedCharacters.None),
factory.Code("Foo?\r\n")
.As(new SetModelTypeCodeGenerator("Foo?", "{0}(Of {1})")),
factory.Markup("Bar")
};
Assert.Equal(expectedSpans, spans.ToArray());
}
[Fact]
public void ParseModelKeyword_HandlesArrays()
{
// Arrange + Act
var document = "@ModelType Foo(())()\r\nBar";
var spans = ParseDocument(document);
// Assert
var factory = SpanFactory.CreateVbHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("ModelType ")
.Accepts(AcceptedCharacters.None),
factory.Code("Foo(())()\r\n")
.As(new SetModelTypeCodeGenerator("Foo(())()", "{0}(Of {1})")),
factory.Markup("Bar")
};
Assert.Equal(expectedSpans, spans.ToArray());
}
[Fact]
public void ParseModelKeyword_HandlesVSTemplateSyntax()
{
// Arrange + Act
var document = "@ModelType $rootnamespace$.MyModel";
var spans = ParseDocument(document);
// Assert
var factory = SpanFactory.CreateVbHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("ModelType ")
.Accepts(AcceptedCharacters.None),
factory.Code("$rootnamespace$.MyModel")
.As(new SetModelTypeCodeGenerator("$rootnamespace$.MyModel", "{0}(Of {1})"))
};
Assert.Equal(expectedSpans, spans.ToArray());
}
[Fact]
public void ParseModelKeyword_ErrorOnMissingModelType()
{
// Arrange + Act
List<RazorError> errors = new List<RazorError>();
var document = "@ModelType ";
var spans = ParseDocument(document, errors);
// Assert
var factory = SpanFactory.CreateVbHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("ModelType ")
.Accepts(AcceptedCharacters.None),
factory.EmptyVB()
.As(new SetModelTypeCodeGenerator(String.Empty, "{0}(Of {1})"))
.Accepts(AcceptedCharacters.Any)
};
var expectedErrors = new[]
{
new RazorError("The 'ModelType' keyword must be followed by a type name on the same line.", new SourceLocation(10, 0, 10), 1)
};
Assert.Equal(expectedSpans, spans.ToArray());
Assert.Equal(expectedErrors, errors.ToArray());
}
[Fact]
public void ParseModelKeyword_DoesNotAcceptNewlineIfInDesignTimeMode()
{
// Arrange + Act
List<RazorError> errors = new List<RazorError>();
var document = "@ModelType foo\r\n";
var spans = ParseDocument(document, errors, designTimeMode: true);
// Assert
var factory = SpanFactory.CreateVbHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("ModelType ")
.Accepts(AcceptedCharacters.None),
factory.Code("foo")
.As(new SetModelTypeCodeGenerator("foo", "{0}(Of {1})"))
.Accepts(AcceptedCharacters.Any),
factory.Markup("\r\n")
};
Assert.Equal(expectedSpans, spans.ToArray());
Assert.Equal(0, errors.Count);
}
[Fact]
public void ParseModelKeyword_ErrorOnMultipleModelStatements()
{
// Arrange + Act
List<RazorError> errors = new List<RazorError>();
var document =
@"@ModelType Foo
@ModelType Bar";
var spans = ParseDocument(document, errors);
// Assert
var factory = SpanFactory.CreateVbHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("ModelType ")
.Accepts(AcceptedCharacters.None),
factory.Code("Foo\r\n")
.As(new SetModelTypeCodeGenerator("Foo", "{0}(Of {1})")),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("ModelType ")
.Accepts(AcceptedCharacters.None),
factory.Code("Bar")
.As(new SetModelTypeCodeGenerator("Bar", "{0}(Of {1})"))
};
var expectedErrors = new[]
{
new RazorError("Only one 'ModelType' statement is allowed in a file.", new SourceLocation(26, 1, 10), 1)
};
expectedSpans.Zip(spans, (exp, span) => new { expected = exp, span = span }).ToList().ForEach(i => Assert.Equal(i.expected, i.span));
Assert.Equal(expectedSpans, spans.ToArray());
Assert.Equal(expectedErrors, errors.ToArray());
}
[Fact]
public void ParseModelKeyword_ErrorOnModelFollowedByInherits()
{
// Arrange + Act
List<RazorError> errors = new List<RazorError>();
var document =
@"@ModelType Foo
@Inherits Bar";
var spans = ParseDocument(document, errors);
// Assert
var factory = SpanFactory.CreateVbHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("ModelType ")
.Accepts(AcceptedCharacters.None),
factory.Code("Foo\r\n")
.As(new SetModelTypeCodeGenerator("Foo", "{0}(Of {1})")),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("Inherits ")
.Accepts(AcceptedCharacters.None),
factory.Code("Bar")
.As(new SetBaseTypeCodeGenerator("Bar"))
};
var expectedErrors = new[]
{
new RazorError("The 'inherits' keyword is not allowed when a 'ModelType' keyword is used.", new SourceLocation(25, 1, 9), 1)
};
expectedSpans.Zip(spans, (exp, span) => new { expected = exp, span = span }).ToList().ForEach(i => Assert.Equal(i.expected, i.span));
Assert.Equal(expectedSpans, spans.ToArray());
Assert.Equal(expectedErrors, errors.ToArray());
}
[Fact]
public void ParseModelKeyword_ErrorOnInheritsFollowedByModel()
{
// Arrange + Act
List<RazorError> errors = new List<RazorError>();
var document =
@"@Inherits Bar
@ModelType Foo";
var spans = ParseDocument(document, errors);
// Assert
var factory = SpanFactory.CreateVbHtml();
var expectedSpans = new Span[]
{
factory.EmptyHtml(),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("Inherits ")
.Accepts(AcceptedCharacters.None),
factory.Code("Bar\r\n")
.AsBaseType("Bar"),
factory.CodeTransition(SyntaxConstants.TransitionString)
.Accepts(AcceptedCharacters.None),
factory.MetaCode("ModelType ")
.Accepts(AcceptedCharacters.None),
factory.Code("Foo")
.As(new SetModelTypeCodeGenerator("Foo", "{0}(Of {1})"))
};
var expectedErrors = new[]
{
new RazorError("The 'inherits' keyword is not allowed when a 'ModelType' keyword is used.", new SourceLocation(9, 0, 9), 1)
};
expectedSpans.Zip(spans, (exp, span) => new { expected = exp, span = span }).ToList().ForEach(i => Assert.Equal(i.expected, i.span));
Assert.Equal(expectedSpans, spans.ToArray());
Assert.Equal(expectedErrors, errors.ToArray());
}
private static List<Span> ParseDocument(string documentContents, List<RazorError> errors = null, bool designTimeMode = false)
{
errors = errors ?? new List<RazorError>();
var markupParser = new HtmlMarkupParser();
var codeParser = new MvcVBRazorCodeParser();
var context = new ParserContext(new SeekableTextReader(documentContents), codeParser, markupParser, markupParser);
context.DesignTimeMode = designTimeMode;
codeParser.Context = context;
markupParser.Context = context;
markupParser.ParseDocument();
ParserResults results = context.CompleteParse();
foreach (RazorError error in results.ParserErrors)
{
errors.Add(error);
}
return results.Document.Flatten().ToList();
}
}
}

View File

@@ -0,0 +1,109 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Web.Razor.Generator;
using System.Web.Razor.Parser;
using Xunit;
using Assert = Microsoft.TestCommon.AssertEx;
namespace System.Web.Mvc.Razor.Test
{
public class MvcWebPageRazorHostTest
{
[Fact]
public void Constructor()
{
MvcWebPageRazorHost host = new MvcWebPageRazorHost("foo.cshtml", "bar");
Assert.Equal("foo.cshtml", host.VirtualPath);
Assert.Equal("bar", host.PhysicalPath);
Assert.Equal(typeof(WebViewPage).FullName, host.DefaultBaseClass);
}
[Fact]
public void ConstructorRemovesUnwantedNamespaceImports()
{
MvcWebPageRazorHost host = new MvcWebPageRazorHost("foo.cshtml", "bar");
Assert.False(host.NamespaceImports.Contains("System.Web.WebPages.Html"));
// Even though MVC no longer needs to remove the following two namespaces
// (because they are no longer imported by System.Web.WebPages), we want
// to make sure that they don't get introduced again by default.
Assert.False(host.NamespaceImports.Contains("WebMatrix.Data"));
Assert.False(host.NamespaceImports.Contains("WebMatrix.WebData"));
}
#if VB_ENABLED
[Fact]
public void DecorateGodeGenerator_ReplacesVBCodeGeneratorWithMvcSpecificOne() {
// Arrange
MvcWebPageRazorHost host = new MvcWebPageRazorHost("foo.vbhtml", "bar");
var generator = new VBRazorCodeGenerator("someClass", "root.name", "foo.vbhtml", host);
// Act
var result = host.DecorateCodeGenerator(generator);
// Assert
Assert.IsType<MvcVBRazorCodeGenerator>(result);
Assert.Equal("someClass", result.ClassName);
Assert.Equal("root.name", result.RootNamespaceName);
Assert.Equal("foo.vbhtml", result.SourceFileName);
Assert.Same(host, result.Host);
}
#endif
[Fact]
public void DecorateGodeGenerator_ReplacesCSharpCodeGeneratorWithMvcSpecificOne()
{
// Arrange
MvcWebPageRazorHost host = new MvcWebPageRazorHost("foo.cshtml", "bar");
var generator = new CSharpRazorCodeGenerator("someClass", "root.name", "foo.cshtml", host);
// Act
var result = host.DecorateCodeGenerator(generator);
// Assert
Assert.IsType<MvcCSharpRazorCodeGenerator>(result);
Assert.Equal("someClass", result.ClassName);
Assert.Equal("root.name", result.RootNamespaceName);
Assert.Equal("foo.cshtml", result.SourceFileName);
Assert.Same(host, result.Host);
}
[Fact]
public void DecorateCodeParser_ThrowsOnNull()
{
MvcWebPageRazorHost host = new MvcWebPageRazorHost("foo.cshtml", "bar");
Assert.ThrowsArgumentNull(delegate() { host.DecorateCodeParser(null); }, "incomingCodeParser");
}
[Fact]
public void DecorateCodeParser_ReplacesCSharpCodeParserWithMvcSpecificOne()
{
// Arrange
MvcWebPageRazorHost host = new MvcWebPageRazorHost("foo.cshtml", "bar");
var parser = new CSharpCodeParser();
// Act
var result = host.DecorateCodeParser(parser);
// Assert
Assert.IsType<MvcCSharpRazorCodeParser>(result);
}
#if VB_ENABLED
[Fact]
public void DecorateCodeParser_ReplacesVBCodeParserWithMvcSpecificOne() {
// Arrange
MvcWebPageRazorHost host = new MvcWebPageRazorHost("foo.vbhtml", "bar");
var parser = new VBCodeParser();
// Act
var result = host.DecorateCodeParser(parser);
// Assert
Assert.IsType<MvcVBRazorCodeParser>(result);
}
#endif
}
}