public void ParseBlockMethodThrowsArgNullExceptionOnNullContext() { // Arrange var parser = new CSharpCodeParser(); // Act and Assert var exception = Assert.Throws<InvalidOperationException>(() => parser.ParseBlock()); Assert.Equal(RazorResources.Parser_Context_Not_Set, exception.Message); }
public void ConstructorAcceptsActiveParserIfIsSameAsEitherCodeOrMarkupParser() { var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); var errorSink = new ErrorSink(); new ParserContext( new SeekableTextReader(TextReader.Null), codeParser, markupParser, codeParser, errorSink); new ParserContext( new SeekableTextReader(TextReader.Null), codeParser, markupParser, markupParser, errorSink); }
public void DecorateCodeParserDoesNotModifyIncomingParser() { // Arrange var expected = new CSharpCodeParser(); // Act var actual = CreateHost().DecorateCodeParser(expected); // Assert Assert.Same(expected, actual); }
public void ConstructorInitializesProperties() { // Arrange var expectedBuffer = new SeekableTextReader(TextReader.Null); var expectedCodeParser = new CSharpCodeParser(); var expectedMarkupParser = new HtmlMarkupParser(); // Act var context = new ParserContext(expectedBuffer, expectedCodeParser, expectedMarkupParser, expectedCodeParser, new ErrorSink()); // Assert Assert.NotNull(context.Source); Assert.Same(expectedCodeParser, context.CodeParser); Assert.Same(expectedMarkupParser, context.MarkupParser); Assert.Same(expectedCodeParser, context.ActiveParser); }
private static void RunParseWithListenerTest(Action<RazorParser, TextReader> parserAction) { // Arrange var markupParser = new MockMarkupParser(); var codeParser = new CSharpCodeParser(); var parser = new RazorParser(codeParser, markupParser, tagHelperDescriptorResolver: null); var expectedReader = new StringReader("foo"); // Act parserAction(parser, expectedReader); // Assert var actualContext = markupParser.Context; Assert.NotNull(actualContext); Assert.Same(markupParser, actualContext.MarkupParser); Assert.Same(markupParser, actualContext.ActiveParser); Assert.Same(codeParser, actualContext.CodeParser); }
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 SetupTestContext(string document) { var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); return SetupTestContext(document, b => { }, codeParser, markupParser, codeParser); }
public void SwitchActiveParserSetsMarkupParserAsActiveIfCodeParserCurrentlyActive() { // Arrange var codeParser = new CSharpCodeParser(); var markupParser = new HtmlMarkupParser(); var context = SetupTestContext("barbazbiz", b => b.Read(), codeParser, markupParser, codeParser); Assert.Same(codeParser, context.ActiveParser); // Act context.SwitchActiveParser(); // Assert Assert.Same(markupParser, context.ActiveParser); }