コード例 #1
0
 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);
 }
コード例 #2
0
        public void ParseBlockMethodThrowsArgNullExceptionOnNullContext() {
            // Arrange
            CSharpCodeParser parser = new CSharpCodeParser();

            // Act and Assert
            ExceptionAssert.Throws<InvalidOperationException>(() => parser.ParseBlock(), RazorResources.Parser_Context_Not_Set);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
 private ParserContext SetupTestContext(string document)
 {
     var codeParser = new CSharpCodeParser();
     var markupParser = new HtmlMarkupParser();
     return SetupTestContext(document, b => { }, codeParser, markupParser, codeParser);
 }
コード例 #9
0
 public void ConstructorRequiresNonNullMarkupParser() {
     var codeParser = new CSharpCodeParser();
     ExceptionAssert.ThrowsArgNull(() => new ParserContext(new BufferingTextReader(TextReader.Null), codeParser, null, codeParser, new Mock<ParserVisitor>().Object), "markupParser");
 }
コード例 #10
0
 public void ConstructorRequiresNonNullListener() {
     var codeParser = new CSharpCodeParser();
     ExceptionAssert.ThrowsArgNull(() => new ParserContext(new BufferingTextReader(TextReader.Null), codeParser, new HtmlMarkupParser(), codeParser, null), "visitor");
 }
コード例 #11
0
 private ParserContext SetupTestContext(string document, Action<TextReader> positioningAction)
 {
     var codeParser = new CSharpCodeParser();
     var markupParser = new HtmlMarkupParser();
     return SetupTestContext(document, positioningAction, codeParser, markupParser, codeParser);
 }
コード例 #12
0
 private ParserContext SetupTestRun(string document, ParserVisitor listener) {
     var codeParser = new CSharpCodeParser();
     var markupParser = new HtmlMarkupParser();
     return SetupTestRun(document, b => { }, codeParser, markupParser, codeParser, listener);
 }
コード例 #13
0
 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);
 }
コード例 #14
0
        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);
        }
コード例 #15
0
 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));
 }
コード例 #16
0
        public void DecorateCodeParserDoesNotModifyIncomingParser() {
            // Arrange
            ParserBase expected = new CSharpCodeParser();
            
            // Act
            ParserBase actual = CreateHost().DecorateCodeParser(expected);

            // Assert
            Assert.AreSame(expected, actual);
        }
コード例 #17
0
 public void ConstructorRequiresNonNullSource() {
     var codeParser = new CSharpCodeParser();
     ExceptionAssert.ThrowsArgNull(() => new ParserContext(null, codeParser, new HtmlMarkupParser(), codeParser, new Mock<ParserVisitor>().Object), "source");
 }
コード例 #18
0
 public void ConstructorRequiresNonNullMarkupParser()
 {
     var codeParser = new CSharpCodeParser();
     Assert.ThrowsArgumentNull(() => new ParserContext(new SeekableTextReader(TextReader.Null), codeParser, null, codeParser), "markupParser");
 }
コード例 #19
0
 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;
 }
コード例 #20
0
 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);
 }
コード例 #21
0
        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);
        }
コード例 #22
0
 public void ConstructorRequiresNonNullSource()
 {
     var codeParser = new CSharpCodeParser();
     Assert.ThrowsArgumentNull(() => new ParserContext(null, codeParser, new HtmlMarkupParser(), codeParser), "source");
 }