示例#1
0
        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);
        }
示例#2
0
 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);
 }
示例#3
0
        public void DecorateCodeParserDoesNotModifyIncomingParser()
        {
            // Arrange
            var expected = new CSharpCodeParser();

            // Act
            var actual = CreateHost().DecorateCodeParser(expected);

            // Assert
            Assert.Same(expected, actual);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
 private ParserContext SetupTestContext(string document, Action<TextReader> positioningAction)
 {
     var codeParser = new CSharpCodeParser();
     var markupParser = new HtmlMarkupParser();
     return SetupTestContext(document, positioningAction, codeParser, markupParser, codeParser);
 }
示例#7
0
 private ParserContext SetupTestContext(string document)
 {
     var codeParser = new CSharpCodeParser();
     var markupParser = new HtmlMarkupParser();
     return SetupTestContext(document, b => { }, codeParser, markupParser, codeParser);
 }
示例#8
0
        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);
        }