當前位置: 首頁>>代碼示例>>C#>>正文


C# Framework.MarkupBlock類代碼示例

本文整理匯總了C#中Microsoft.AspNet.Razor.Test.Framework.MarkupBlock的典型用法代碼示例。如果您正苦於以下問題:C# MarkupBlock類的具體用法?C# MarkupBlock怎麽用?C# MarkupBlock使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MarkupBlock類屬於Microsoft.AspNet.Razor.Test.Framework命名空間,在下文中一共展示了MarkupBlock類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TreesAreDifferentReturnsFalseIfTreeStructureIsSame

 public void TreesAreDifferentReturnsFalseIfTreeStructureIsSame()
 {
     var factory = SpanFactory.CreateCsHtml();
     Block original = new MarkupBlock(
         factory.Markup("<p>"),
         new ExpressionBlock(
             factory.CodeTransition(),
             factory.Code("f")
                    .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)),
         factory.Markup("</p>"));
     factory.Reset();
     Block modified = new MarkupBlock(
         factory.Markup("<p>"),
         new ExpressionBlock(
             factory.CodeTransition(),
             factory.Code("foo")
                    .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)),
         factory.Markup("</p>"));
     original.LinkNodes();
     modified.LinkNodes();
     ITextBuffer oldBuffer = new StringTextBuffer("<p>@f</p>");
     ITextBuffer newBuffer = new StringTextBuffer("<p>@foo</p>");
     Assert.False(BackgroundParser.TreesAreDifferent(
         original, modified, new[] {
             new TextChange(position: 5, oldLength: 0, oldBuffer: oldBuffer, newLength: 2, newBuffer: newBuffer)
         }));
 }
開發者ID:KennyBu,項目名稱:Razor,代碼行數:27,代碼來源:RazorEditorParserTest.cs

示例2: Rewrite_Moves_Whitespace_Preceeding_ExpressionBlock_To_Parent_Block

        public void Rewrite_Moves_Whitespace_Preceeding_ExpressionBlock_To_Parent_Block()
        {
            // Arrange
            var factory = SpanFactory.CreateCsHtml();
            Block start = new MarkupBlock(
                factory.Markup("test"),
                new ExpressionBlock(
                    factory.Code("    ").AsExpression(),
                    factory.CodeTransition(SyntaxConstants.TransitionString),
                    factory.Code("foo").AsExpression()
                    ),
                factory.Markup("test")
                );
            WhiteSpaceRewriter rewriter = new WhiteSpaceRewriter(new HtmlMarkupParser().BuildSpan);

            // Act
            Block actual = rewriter.Rewrite(start);

            factory.Reset();

            // Assert
            ParserTestBase.EvaluateParseTree(actual, new MarkupBlock(
                                                         factory.Markup("test"),
                                                         factory.Markup("    "),
                                                         new ExpressionBlock(
                                                             factory.CodeTransition(SyntaxConstants.TransitionString),
                                                             factory.Code("foo").AsExpression()
                                                             ),
                                                         factory.Markup("test")
                                                         ));
        }
開發者ID:hamaky,項目名稱:Razor,代碼行數:31,代碼來源:WhitespaceRewriterTest.cs

示例3: TreesAreDifferentReturnsTrueIfTreeStructureIsDifferent

 public void TreesAreDifferentReturnsTrueIfTreeStructureIsDifferent()
 {
     var factory = SpanFactory.CreateCsHtml();
     var original = new MarkupBlock(
         factory.Markup("<p>"),
         new ExpressionBlock(
             factory.CodeTransition()),
         factory.Markup("</p>"));
     var modified = new MarkupBlock(
         factory.Markup("<p>"),
         new ExpressionBlock(
             factory.CodeTransition("@"),
             factory.Code("f")
                    .AsImplicitExpression(CSharpCodeParser.DefaultKeywords, acceptTrailingDot: false)),
         factory.Markup("</p>"));
     var oldBuffer = new StringTextBuffer("<p>@</p>");
     var newBuffer = new StringTextBuffer("<p>@f</p>");
     Assert.True(BackgroundParser.TreesAreDifferent(
         original,
         modified,
         new[]
         {
             new TextChange(position: 4, oldLength: 0, oldBuffer: oldBuffer, newLength: 1, newBuffer: newBuffer)
         }));
 }
開發者ID:rohitpoudel,項目名稱:Razor,代碼行數:25,代碼來源:RazorEditorParserTest.cs

示例4: TreesAreDifferentReturnsFalseForAddedContent

        public void TreesAreDifferentReturnsFalseForAddedContent(string content)
        {
            // Arrange
            var factory = SpanFactory.CreateCsHtml();
            var blockFactory = new BlockFactory(factory);
            var original = new MarkupBlock(
                blockFactory.MarkupTagBlock("<p>"),
                blockFactory.TagHelperBlock(
                    tagName: "div",
                    tagMode: TagMode.StartTagAndEndTag,
                    start: new SourceLocation(3, 0, 3),
                    startTag: blockFactory.MarkupTagBlock("<div>"),
                    children: new SyntaxTreeNode[]
                    {
                        factory.Markup($"{Environment.NewLine}{Environment.NewLine}")
                    },
                    endTag: blockFactory.MarkupTagBlock("</div>")),
                blockFactory.MarkupTagBlock("</p>"));

            factory.Reset();

            var modified = new MarkupBlock(
                blockFactory.MarkupTagBlock("<p>"),
                blockFactory.TagHelperBlock(
                    tagName: "div",
                    tagMode: TagMode.StartTagAndEndTag,
                    start: new SourceLocation(3, 0, 3),
                    startTag: blockFactory.MarkupTagBlock("<div>"),
                    children: new SyntaxTreeNode[]
                    {
                        factory.Markup($"{Environment.NewLine}{content}{Environment.NewLine}")
                    },
                    endTag: blockFactory.MarkupTagBlock("</div>")),
                blockFactory.MarkupTagBlock("</p>"));
            original.LinkNodes();
            modified.LinkNodes();

            var oldBuffer = new StringTextBuffer($"<p><div>{Environment.NewLine}{Environment.NewLine}</div></p>");
            var newBuffer = new StringTextBuffer(
                $"<p><div>{Environment.NewLine}{content}{Environment.NewLine}</div></p>");

            // Act
            var treesAreDifferent = BackgroundParser.TreesAreDifferent(
                original,
                modified,
                new[]
                {
                    new TextChange(
                        position: 8 + Environment.NewLine.Length,
                        oldLength: 0,
                        oldBuffer: oldBuffer,
                        newLength: content.Length,
                        newBuffer: newBuffer)
                });

            // Assert
            Assert.False(treesAreDifferent);
        }
開發者ID:huoxudong125,項目名稱:Razor,代碼行數:58,代碼來源:RazorEditorParserTest.cs

示例5: RunParseTreeRewriterTest

        public void RunParseTreeRewriterTest(
            string documentContent,
            MarkupBlock expectedOutput,
            IEnumerable<RazorError> errors,
            params string[] tagNames)
        {
            var providerContext = BuildProviderContext(tagNames);

            EvaluateData(providerContext, documentContent, expectedOutput, errors);
        }
開發者ID:rahulchrty,項目名稱:Razor,代碼行數:10,代碼來源:TagHelperRewritingTestBase.cs

示例6: Rewrite_CanHandleInvalidChildrenWithWhitespace

        public void Rewrite_CanHandleInvalidChildrenWithWhitespace()
        {
            // Arrange
            var factory = CreateDefaultSpanFactory();
            var blockFactory = new BlockFactory(factory);
            var documentContent = $"<p>{Environment.NewLine}    <strong>{Environment.NewLine}        Hello" +
                $"{Environment.NewLine}    </strong>{Environment.NewLine}</p>";
            var newLineLength = Environment.NewLine.Length;
            var expectedErrors = new[] {
                new RazorError(
                    RazorResources.FormatTagHelperParseTreeRewriter_InvalidNestedTag("strong", "p", "br"),
                    absoluteIndex: 7 + newLineLength,
                    lineIndex: 1,
                    columnIndex: 9 + newLineLength,
                    length: 8),
                new RazorError(
                    RazorResources.FormatTagHelperParseTreeRewriter_CannotHaveNonTagContent("p", "br"),
                    absoluteIndex: 23 + newLineLength * 2,
                    lineIndex: 2,
                    columnIndex: 23 + newLineLength * 2,
                    length: 5),
                new RazorError(
                    RazorResources.FormatTagHelperParseTreeRewriter_InvalidNestedTag("strong", "p", "br"),
                    absoluteIndex: 32 + newLineLength * 3,
                    lineIndex: 3,
                    columnIndex: 32 + newLineLength * 3,
                    length: 9),
            };
            var expectedOutput = new MarkupBlock(
                new MarkupTagHelperBlock("p",
                    factory.Markup(Environment.NewLine + "    "),
                    blockFactory.MarkupTagBlock("<strong>"),
                    factory.Markup(Environment.NewLine + "        Hello" + Environment.NewLine + "    "),
                    blockFactory.MarkupTagBlock("</strong>"),
                    factory.Markup(Environment.NewLine)));
            var descriptors = new TagHelperDescriptor[]
                {
                    new TagHelperDescriptor
                    {
                        TagName = "p",
                        TypeName = "PTagHelper",
                        AssemblyName = "SomeAssembly",
                        AllowedChildren = new[] { "br" },
                    }
                };
            var descriptorProvider = new TagHelperDescriptorProvider(descriptors);

            // Act & Assert
            EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors);
        }
開發者ID:antiufo,項目名稱:Razor,代碼行數:50,代碼來源:TagHelperParseTreeRewriterTest.cs

示例7: EvaluateData

        public void EvaluateData(
            TagHelperDescriptorProvider provider,
            string documentContent,
            MarkupBlock expectedOutput,
            IEnumerable<RazorError> expectedErrors)
        {
            var errorSink = new ErrorSink();
            var results = ParseDocument(documentContent, errorSink);
            var rewritingContext = new RewritingContext(results.Document, errorSink);
            new TagHelperParseTreeRewriter(provider).Rewrite(rewritingContext);
            var rewritten = rewritingContext.SyntaxTree;
            var actualErrors = errorSink.Errors.OrderBy(error => error.Location.AbsoluteIndex)
                                               .ToList();

            EvaluateRazorErrors(actualErrors, expectedErrors.ToList());
            EvaluateParseTree(rewritten, expectedOutput);
        }
開發者ID:rahulchrty,項目名稱:Razor,代碼行數:17,代碼來源:TagHelperRewritingTestBase.cs

示例8: Rewrite_CanHandleWithoutEndTagTagStructure

        public void Rewrite_CanHandleWithoutEndTagTagStructure(string documentContent, MarkupBlock expectedOutput)
        {
            // Arrange
            var descriptors = new TagHelperDescriptor[]
                {
                    new TagHelperDescriptor
                    {
                        TagName = "input",
                        TypeName = "InputTagHelper",
                        AssemblyName = "SomeAssembly",
                        TagStructure = TagStructure.WithoutEndTag,
                    }
                };
            var descriptorProvider = new TagHelperDescriptorProvider(descriptors);

            // Act & Assert
            EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors: new RazorError[0]);
        }
開發者ID:antiufo,項目名稱:Razor,代碼行數:18,代碼來源:TagHelperBlockRewriterTest.cs

示例9: LocateOwnerReturnsNullIfNoSpanReturnsTrueForOwnsSpan

        public void LocateOwnerReturnsNullIfNoSpanReturnsTrueForOwnsSpan()
        {
            // Arrange
            var factory = SpanFactory.CreateCsHtml();
            var block = new MarkupBlock(
                factory.Markup("Foo "),
                new StatementBlock(
                    factory.CodeTransition(),
                    factory.Code("bar").AsStatement()),
                factory.Markup(" Baz"));
            var change = new TextChange(128, 1, new StringTextBuffer("Foo @bar Baz"), 1, new StringTextBuffer("Foo @bor Baz"));

            // Act
            var actual = block.LocateOwner(change);

            // Assert
            Assert.Null(actual);
        }
開發者ID:rohitpoudel,項目名稱:Razor,代碼行數:18,代碼來源:BlockTest.cs

示例10: TagHelperParseTreeRewriter_RewritesNestedTagHelperTagBlocks

 public void TagHelperParseTreeRewriter_RewritesNestedTagHelperTagBlocks(
     string documentContent,
     MarkupBlock expectedOutput)
 {
     RunParseTreeRewriterTest(documentContent, expectedOutput, "p", "div");
 }
開發者ID:rohitpoudel,項目名稱:Razor,代碼行數:6,代碼來源:TagHelperParseTreeRewriterTest.cs

示例11: TagHelperParseTreeRewriter_RewritesTagHelpersWithPlainAttributes

 public void TagHelperParseTreeRewriter_RewritesTagHelpersWithPlainAttributes(
     string documentContent,
     MarkupBlock expectedOutput)
 {
     RunParseTreeRewriterTest(documentContent, expectedOutput, "p");
 }
開發者ID:rohitpoudel,項目名稱:Razor,代碼行數:6,代碼來源:TagHelperParseTreeRewriterTest.cs

示例12: TagHelperParseTreeRewriter_RewritesSelfClosingTagHelpers

 public void TagHelperParseTreeRewriter_RewritesSelfClosingTagHelpers(
     string documentContent,
     MarkupBlock expectedOutput)
 {
     RunParseTreeRewriterTest(documentContent, expectedOutput, "p");
 }
開發者ID:rohitpoudel,項目名稱:Razor,代碼行數:6,代碼來源:TagHelperParseTreeRewriterTest.cs

示例13: TagHelperParseTreeRewriter_RewritesComplexAttributeTagHelperTagBlocks

 public void TagHelperParseTreeRewriter_RewritesComplexAttributeTagHelperTagBlocks(
     string documentContent,
     MarkupBlock expectedOutput)
 {
     RunParseTreeRewriterTest(documentContent, expectedOutput, "p");
 }
開發者ID:rohitpoudel,項目名稱:Razor,代碼行數:6,代碼來源:TagHelperParseTreeRewriterTest.cs

示例14: Rewrite_AllowsTagHelperElementOptForIncompleteTextTagInCSharpBlock

 public void Rewrite_AllowsTagHelperElementOptForIncompleteTextTagInCSharpBlock(
     string documentContent,
     MarkupBlock expectedOutput,
     RazorError[] expectedErrors)
 {
     RunParseTreeRewriterTest(documentContent, expectedOutput, expectedErrors, "text");
 }
開發者ID:rohitpoudel,項目名稱:Razor,代碼行數:7,代碼來源:TagHelperParseTreeRewriterTest.cs

示例15: Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes

 public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes(
     string documentContent,
     MarkupBlock expectedOutput,
     RazorError[] expectedErrors)
 {
     RunParseTreeRewriterTest(documentContent, expectedOutput, expectedErrors, "strong", "p");
 }
開發者ID:rohitpoudel,項目名稱:Razor,代碼行數:7,代碼來源:TagHelperParseTreeRewriterTest.cs


注:本文中的Microsoft.AspNet.Razor.Test.Framework.MarkupBlock類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。