Пример #1
0
        public void ParseDocumentMethodThrowsArgNullExceptionOnNullContext() {
            // Arrange
            HtmlMarkupParser parser = new HtmlMarkupParser();

            // Act and Assert
            ExceptionAssert.Throws<InvalidOperationException>(() => parser.ParseDocument(), RazorResources.Parser_Context_Not_Set);
        }
        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 static List<Span> ParseDocument(string documentContents, List<RazorError> errors = null) {
     errors = errors ?? new List<RazorError>();
     var reader = new BufferingTextReader(new StringReader(documentContents));
     var markupParser = new HtmlMarkupParser();
     var parserConsumerMock = new Mock<ParserVisitor>();
     List<Span> spans = new List<Span>();
     parserConsumerMock.Setup(consumer => consumer.VisitSpan(It.IsAny<Span>())).Callback<Span>(span => spans.Add(span));
     parserConsumerMock.Setup(consumer => consumer.VisitError(It.IsAny<RazorError>())).Callback<RazorError>(error => errors.Add(error));
     var codeParser = new TestMvcVBRazorCodeParser();
     var context = new ParserContext(reader, codeParser, markupParser, markupParser, parserConsumerMock.Object);
     codeParser.Context = context;
     markupParser.Context = context;
     markupParser.ParseDocument();
     return spans;
 }