public void ConstructorAcceptsActiveParserIfIsSameAsEitherCodeOrMarkupParser() { var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); new ParserContext(new SeekableTextReader(TextReader.Null), codeParser, markupParser, codeParser); new ParserContext(new SeekableTextReader(TextReader.Null), codeParser, markupParser, markupParser); }
public void ParseBlockMethodThrowsArgNullExceptionOnNullContext() { // Arrange CSharpCodeParser parser = new CSharpCodeParser(); // Act and Assert ExceptionAssert.Throws<InvalidOperationException>(() => parser.ParseBlock(), RazorResources.Parser_Context_Not_Set); }
public void DecorateCodeParser_ReplacesCSharpCodeParserWithMvcSpecificOne() { // Arrange MvcWebPageRazorHost host = new MvcWebPageRazorHost("foo.cshtml", "bar"); var parser = new CSharpCodeParser(); // Act var result = host.DecorateCodeParser(parser); // Assert Assert.IsInstanceOfType(result, typeof(MvcCSharpRazorCodeParser)); }
public void ConstructorInitializesProperties() { // Arrange SeekableTextReader expectedBuffer = new SeekableTextReader(TextReader.Null); CSharpCodeParser expectedCodeParser = new CSharpCodeParser(); HtmlMarkupParser expectedMarkupParser = new HtmlMarkupParser(); // Act ParserContext context = new ParserContext(expectedBuffer, expectedCodeParser, expectedMarkupParser, expectedCodeParser); // Assert Assert.NotNull(context.Source); Assert.Same(expectedCodeParser, context.CodeParser); Assert.Same(expectedMarkupParser, context.MarkupParser); Assert.Same(expectedCodeParser, context.ActiveParser); }
public void ConstructorInitializesProperties() { // Arrange LookaheadTextReader expectedBuffer = new BufferingTextReader(TextReader.Null); CSharpCodeParser expectedCodeParser = new CSharpCodeParser(); HtmlMarkupParser expectedMarkupParser = new HtmlMarkupParser(); ParserVisitor expectedListener = new Mock<ParserVisitor>().Object; // Act ParserContext context = new ParserContext(expectedBuffer, expectedCodeParser, expectedMarkupParser, expectedCodeParser, expectedListener); // Assert Assert.IsInstanceOfType(context.Source, typeof(BufferingTextReader)); Assert.AreSame(expectedBuffer, context.Source); Assert.AreSame(expectedCodeParser, context.CodeParser); Assert.AreSame(expectedMarkupParser, context.MarkupParser); Assert.AreSame(expectedCodeParser, context.ActiveParser); Assert.AreSame(expectedListener, context.Visitor); }
private static void RunParseWithListenerTest(Action<RazorParser, TextReader> parserAction) { // Arrange ParserBase markupParser = new MockMarkupParser(); ParserBase codeParser = new CSharpCodeParser(); RazorParser parser = new RazorParser(codeParser, markupParser); TextReader expectedReader = new StringReader("foo"); // Act parserAction(parser, expectedReader); // Assert ParserContext actualContext = markupParser.Context; Assert.NotNull(actualContext); Assert.Same(markupParser, actualContext.MarkupParser); Assert.Same(markupParser, actualContext.ActiveParser); Assert.Same(codeParser, actualContext.CodeParser); }
private static void RunParseWithListenerTest(Action<RazorParser, TextReader, ParserVisitor> parserAction) { // Arrange MarkupParser markupParser = new MockMarkupParser(); ParserBase codeParser = new CSharpCodeParser(); RazorParser parser = new RazorParser(codeParser, markupParser); TextReader expectedReader = new StringReader("foo"); ParserVisitor expectedListener = new Mock<ParserVisitor>().Object; // Act parserAction(parser, expectedReader, expectedListener); // Assert ParserContext actualContext = markupParser.Context; Assert.IsNotNull(actualContext); Assert.AreSame(markupParser, actualContext.MarkupParser); Assert.AreSame(markupParser, actualContext.ActiveParser); Assert.AreSame(codeParser, actualContext.CodeParser); Assert.AreSame(expectedReader, ((BufferingTextReader)actualContext.Source).InnerReader); Assert.AreSame(expectedListener, actualContext.Visitor); }
private ParserContext SetupTestContext(string document) { var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); return SetupTestContext(document, b => { }, codeParser, markupParser, codeParser); }
public void ConstructorRequiresNonNullMarkupParser() { var codeParser = new CSharpCodeParser(); ExceptionAssert.ThrowsArgNull(() => new ParserContext(new BufferingTextReader(TextReader.Null), codeParser, null, codeParser, new Mock<ParserVisitor>().Object), "markupParser"); }
public void ConstructorRequiresNonNullListener() { var codeParser = new CSharpCodeParser(); ExceptionAssert.ThrowsArgNull(() => new ParserContext(new BufferingTextReader(TextReader.Null), codeParser, new HtmlMarkupParser(), codeParser, null), "visitor"); }
private ParserContext SetupTestContext(string document, Action<TextReader> positioningAction) { var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); return SetupTestContext(document, positioningAction, codeParser, markupParser, codeParser); }
private ParserContext SetupTestRun(string document, ParserVisitor listener) { var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); return SetupTestRun(document, b => { }, codeParser, markupParser, codeParser, listener); }
private ParserContext SetupTestRun(string document, Action<TextReader> positioningAction) { var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); return SetupTestRun(document, positioningAction, codeParser, markupParser, codeParser, new Mock<ParserVisitor>().Object); }
public void SwitchActiveParserSetsMarkupParserAsActiveIfCodeParserCurrentlyActive() { // Arrange var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); ParserContext context = SetupTestContext("barbazbiz", b => b.Read(), codeParser, markupParser, codeParser); Assert.Same(codeParser, context.ActiveParser); // Act context.SwitchActiveParser(); // Assert Assert.Same(markupParser, context.ActiveParser); }
public void AddingKeywordToRazorKeywordsListBeforeAccessingTopLevelKeywordsAddsItToTopLevelKeywords() { CSharpCodeParser parser = new CSharpCodeParser(); parser.RazorKeywords.Add(TestExtraKeyword, _ => { Assert.Fail("Should never be called!"); return true; }); Assert.IsTrue(parser.TopLevelKeywords.Contains(TestExtraKeyword)); }
public void DecorateCodeParserDoesNotModifyIncomingParser() { // Arrange ParserBase expected = new CSharpCodeParser(); // Act ParserBase actual = CreateHost().DecorateCodeParser(expected); // Assert Assert.AreSame(expected, actual); }
public void ConstructorRequiresNonNullSource() { var codeParser = new CSharpCodeParser(); ExceptionAssert.ThrowsArgNull(() => new ParserContext(null, codeParser, new HtmlMarkupParser(), codeParser, new Mock<ParserVisitor>().Object), "source"); }
public void ConstructorRequiresNonNullMarkupParser() { var codeParser = new CSharpCodeParser(); Assert.ThrowsArgumentNull(() => new ParserContext(new SeekableTextReader(TextReader.Null), codeParser, null, codeParser), "markupParser"); }
public override ParserBase CreateCodeParser() { CSharpCodeParser parser = new CSharpCodeParser(); parser.RazorKeywords.Add(TestExtraKeyword, _ => { Assert.Fail("Should never be called!"); return true; }); KeywordSet = parser.TopLevelKeywords; return parser; }
public void ConstructorAcceptsActiveParserIfIsSameAsEitherCodeOrMarkupParser() { var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); new ParserContext(new BufferingTextReader(TextReader.Null), codeParser, markupParser, codeParser, new Mock<ParserVisitor>().Object); new ParserContext(new BufferingTextReader(TextReader.Null), codeParser, markupParser, markupParser, new Mock<ParserVisitor>().Object); }
public void SwitchActiveParserSetsCodeParserAsActiveIfMarkupParserCurrentlyActive() { // Arrange var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); ParserContext context = SetupTestRun("barbazbiz", b => b.Read(), codeParser, markupParser, markupParser, new Mock<ParserVisitor>().Object); Assert.AreSame(markupParser, context.ActiveParser); // Act context.SwitchActiveParser(); // Assert Assert.AreSame(codeParser, context.ActiveParser); }
public void ConstructorRequiresNonNullSource() { var codeParser = new CSharpCodeParser(); Assert.ThrowsArgumentNull(() => new ParserContext(null, codeParser, new HtmlMarkupParser(), codeParser), "source"); }