本文整理汇总了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)
}));
}
示例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")
));
}
示例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)
}));
}
示例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);
}
示例5: RunParseTreeRewriterTest
public void RunParseTreeRewriterTest(
string documentContent,
MarkupBlock expectedOutput,
IEnumerable<RazorError> errors,
params string[] tagNames)
{
var providerContext = BuildProviderContext(tagNames);
EvaluateData(providerContext, documentContent, expectedOutput, errors);
}
示例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);
}
示例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);
}
示例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]);
}
示例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);
}
示例10: TagHelperParseTreeRewriter_RewritesNestedTagHelperTagBlocks
public void TagHelperParseTreeRewriter_RewritesNestedTagHelperTagBlocks(
string documentContent,
MarkupBlock expectedOutput)
{
RunParseTreeRewriterTest(documentContent, expectedOutput, "p", "div");
}
示例11: TagHelperParseTreeRewriter_RewritesTagHelpersWithPlainAttributes
public void TagHelperParseTreeRewriter_RewritesTagHelpersWithPlainAttributes(
string documentContent,
MarkupBlock expectedOutput)
{
RunParseTreeRewriterTest(documentContent, expectedOutput, "p");
}
示例12: TagHelperParseTreeRewriter_RewritesSelfClosingTagHelpers
public void TagHelperParseTreeRewriter_RewritesSelfClosingTagHelpers(
string documentContent,
MarkupBlock expectedOutput)
{
RunParseTreeRewriterTest(documentContent, expectedOutput, "p");
}
示例13: TagHelperParseTreeRewriter_RewritesComplexAttributeTagHelperTagBlocks
public void TagHelperParseTreeRewriter_RewritesComplexAttributeTagHelperTagBlocks(
string documentContent,
MarkupBlock expectedOutput)
{
RunParseTreeRewriterTest(documentContent, expectedOutput, "p");
}
示例14: Rewrite_AllowsTagHelperElementOptForIncompleteTextTagInCSharpBlock
public void Rewrite_AllowsTagHelperElementOptForIncompleteTextTagInCSharpBlock(
string documentContent,
MarkupBlock expectedOutput,
RazorError[] expectedErrors)
{
RunParseTreeRewriterTest(documentContent, expectedOutput, expectedErrors, "text");
}
示例15: Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes
public void Rewrite_CreatesErrorForMalformedTagHelpersWithAttributes(
string documentContent,
MarkupBlock expectedOutput,
RazorError[] expectedErrors)
{
RunParseTreeRewriterTest(documentContent, expectedOutput, expectedErrors, "strong", "p");
}