本文整理汇总了C#中Document.AssertXml方法的典型用法代码示例。如果您正苦于以下问题:C# Document.AssertXml方法的具体用法?C# Document.AssertXml怎么用?C# Document.AssertXml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.AssertXml方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MergeDocText_HyperlinkQueryString
public void MergeDocText_HyperlinkQueryString()
{
var doc = new Document();
var builder = new DocumentBuilder(doc);
builder.InsertRun("^ ");
builder.InsertField("HYPERLINK \"https://google.com/q=%7b%7bQuery%7d%7d\"");
builder.InsertRun(" $");
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph>
<Run>^ </Run>
<FieldStart></FieldStart>
<Run>HYPERLINK ""https://google.com/q=%7b%7bQuery%7d%7d""</Run>
<FieldSeparator></FieldSeparator>
<FieldEnd></FieldEnd>
<Run> $</Run>
</Paragraph>
</Body>
</Section>
</Document>
");
var data = new
{
Query = "Arnold Schwarzenegger",
};
doc.Merge(data);
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph>
<Run>^ </Run>
<FieldStart></FieldStart>
<Run>HYPERLINK ""</Run>
<Run>https://google.com/q=</Run>
<Run>Arnold%20Schwarzenegger</Run>
<Run>""</Run>
<FieldSeparator></FieldSeparator>
<FieldEnd></FieldEnd>
<Run> $</Run>
</Paragraph>
</Body>
</Section>
</Document>
");
}
示例2: ExportXml_EmptyDocument
public void ExportXml_EmptyDocument()
{
var doc = new Document();
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph>
</Paragraph>
</Body>
</Section>
</Document>");
}
示例3: ExportImportXml_SimpleText
public void ExportImportXml_SimpleText()
{
var exportDoc = new Document();
var exportBuilder = new DocumentBuilder(exportDoc);
exportBuilder.Write("Hello World");
var exportBodyXml = exportDoc.Export(exportDoc.Sections.Cast<Section>().Single().Body, DocumentTextFormat.Xml);
var importDoc = new Document();
importDoc.Import(importDoc.Sections.Cast<Section>().Single().Body, DocumentTextFormat.Xml, exportBodyXml);
importDoc.AssertXml(importDoc.Sections.Cast<Section>().Single().Body, exportBodyXml);
}
示例4: ExportXml_SimpleText
public void ExportXml_SimpleText()
{
var doc = new Document();
var builder = new DocumentBuilder(doc);
builder.Write("Hello World");
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph>
<Run>Hello World</Run>
</Paragraph>
</Body>
</Section>
</Document>");
}
示例5: ImportExportXml_Table
public void ImportExportXml_Table()
{
var doc = new Document();
var importBodyXml = @"
<Body>
<Table>
<Row>
<Cell>
<Paragraph>
<Run>Number</Run>
</Paragraph>
</Cell>
<Cell>
<Paragraph>
<Run>Name</Run>
</Paragraph>
</Cell>
<Cell>
<Paragraph>
<Run>Yes/No</Run>
</Paragraph>
</Cell>
</Row>
<Row>
<Cell>
<Paragraph>
<Run>1</Run>
</Paragraph>
</Cell>
<Cell>
<Paragraph>
<Run>J. Doe</Run>
</Paragraph>
</Cell>
<Cell>
<Paragraph>
<Run>Yes</Run>
</Paragraph>
</Cell>
</Row>
<Row>
<Cell>
<Paragraph>
<Run>2</Run>
</Paragraph>
</Cell>
<Cell>
<Paragraph>
<Run>A. Smith</Run>
</Paragraph>
</Cell>
<Cell>
<Paragraph>
<Run>No</Run>
</Paragraph>
</Cell>
</Row>
</Table>
</Body>
";
doc.Import(doc.Sections.Cast<Section>().Single().Body, DocumentTextFormat.Xml, importBodyXml);
doc.AssertXml(doc.Sections.Cast<Section>().Single().Body, importBodyXml);
}
示例6: CloneRegion_RepeatableThatSpansParagraphs
public void CloneRegion_RepeatableThatSpansParagraphs()
{
var doc = new Document();
var runTexts1 = new[] { "^", "{{ PrecedingField }}", "{{ each Items }}", };
var onlySection = doc.Sections.Cast<Section>().Single();
var onlyPara = onlySection.Body.Paragraphs.Cast<Paragraph>().Single();
onlyPara.ParagraphFormat.SpaceBefore = 10;
onlyPara.ParagraphFormat.SpaceAfter = 1;
doc.Import(onlyPara, DocumentTextFormat.Xml, "<Paragraph>\r\n" + string.Join("\r\n", runTexts1.Select(t => "<Run>" + t + "</Run>")) + "\r\n</Paragraph>");
var runs1 = onlyPara.ChildNodes.Cast<Run>().ToArray();
var newPara = new Paragraph(doc);
newPara.ParagraphFormat.SpaceBefore = 1;
newPara.ParagraphFormat.SpaceAfter = 10;
onlySection.Body.ChildNodes.Add(newPara);
var runTexts2 = new[] { "{{ Sequence }}", "{{ end each }}", "$", };
doc.Import(newPara, DocumentTextFormat.Xml, "<Paragraph>\r\n" + string.Join("\r\n", runTexts2.Select(t => "<Run>" + t + "</Run>")) + "\r\n</Paragraph>");
var runs2 = newPara.ChildNodes.Cast<Run>().ToArray();
Container<Document, Node, DocumentToken<Node>, Type, object, string> root;
MergeTemplateError<DocumentToken<Node>>[] errors;
MergeTemplateCompiler.Compile(typeof(object), TokenParser, ExpressionParser, Scanner.GetTokens(doc), null, true, out root, out errors);
var repeatable = root.Children.OfType<IRegion<DocumentToken<Node>>>().OfType<Repeatable<Document, Node, DocumentToken<Node>, Type, object, string>>().Single();
Assert.AreEqual(runs1[2], repeatable.StartToken.Start);
Assert.AreEqual(runs2[1], repeatable.EndToken.Start);
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph paragraphformat_spacebefore='10' paragraphformat_spaceafter='1'>
<Run>^</Run>
<Run>{{ PrecedingField }}</Run>
<Run>{{ each Items }}</Run>
</Paragraph>
<Paragraph paragraphformat_spacebefore='1' paragraphformat_spaceafter='10'>
<Run>{{ Sequence }}</Run>
<Run>{{ end each }}</Run>
<Run>$</Run>
</Paragraph>
</Body>
</Section>
</Document>");
var existingInnerTokens = repeatable.GetInnerTokens().ToArray();
var clonedTokens = Writer.CloneRegion(doc,
new Tuple<DocumentToken<Node>, DocumentToken<Node>[], DocumentToken<Node>>(repeatable.StartToken, existingInnerTokens, repeatable.EndToken));
AssertText(doc, @"^{{ PrecedingField }}{{ each Items }}
{{ Sequence }}{{ end each }}
{{ each Items }}
{{ Sequence }}{{ end each }}$
");
Assert.AreNotEqual(repeatable.StartToken, clonedTokens.Item1);
Assert.AreNotEqual(repeatable.StartToken.Start, clonedTokens.Item1.Start);
Assert.AreNotEqual(repeatable.StartToken.End, clonedTokens.Item1.End);
Assert.AreEqual(existingInnerTokens.Length, clonedTokens.Item2.Length);
Assert.AreNotEqual(repeatable.EndToken, clonedTokens.Item3);
Assert.AreNotEqual(repeatable.EndToken.Start, clonedTokens.Item3.Start);
Assert.AreNotEqual(repeatable.EndToken.End, clonedTokens.Item3.End);
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph paragraphformat_spacebefore='10' paragraphformat_spaceafter='1'>
<Run>^</Run>
<Run>{{ PrecedingField }}</Run>
<Run>{{ each Items }}</Run>
</Paragraph>
<Paragraph paragraphformat_spacebefore='1' paragraphformat_spaceafter='10'>
<Run>{{ Sequence }}</Run>
<Run>{{ end each }}</Run>
</Paragraph>
<Paragraph paragraphformat_spacebefore='10' paragraphformat_spaceafter='1'>
<Run>{{ each Items }}</Run>
</Paragraph>
<Paragraph paragraphformat_spacebefore='1' paragraphformat_spaceafter='10'>
<Run>{{ Sequence }}</Run>
<Run>{{ end each }}</Run>
<Run>$</Run>
</Paragraph>
//.........这里部分代码省略.........
示例7: CloneRegion_RepeatableWithNoNestedRegions_NodesAndFieldsAreCloned
public void CloneRegion_RepeatableWithNoNestedRegions_NodesAndFieldsAreCloned()
{
var doc = new Document();
var runTexts = new[] { "^", "{{ PrecedingField }}", "{{ each Items }}", "{{ Sequence }}", "{{ end each }}", "$" };
var importedNodes = doc.Import(doc.Sections.Cast<Section>().Single().Body.Paragraphs.Cast<Paragraph>().Single(),
DocumentTextFormat.Xml,
"<Paragraph>\r\n" + string.Join("\r\n", runTexts.Select(t => "<Run>" + t + "</Run>")) + "\r\n</Paragraph>"
);
var runs = importedNodes.Cast<Run>().ToArray();
var root = MergeTemplateCompiler.Compile<Document, Node, DocumentToken<Node>, Type, object, string>(typeof(object), TokenParser, ExpressionParser, Scanner.GetTokens(doc));
var repeatable = root.Children.OfType<IRegion<DocumentToken<Node>>>().OfType<Repeatable<Document, Node, DocumentToken<Node>, Type, object, string>>().Single();
Assert.AreEqual(runs[2], repeatable.StartToken.Start);
Assert.AreEqual(runs[4], repeatable.EndToken.Start);
var existingInnerTokens = repeatable.GetInnerTokens().ToArray();
var clonedTokens = Writer.CloneRegion(doc,
new Tuple<DocumentToken<Node>, DocumentToken<Node>[], DocumentToken<Node>>(repeatable.StartToken, existingInnerTokens, repeatable.EndToken));
AssertText(doc, "^{{ PrecedingField }}{{ each Items }}{{ Sequence }}{{ end each }}{{ each Items }}{{ Sequence }}{{ end each }}$\r\n");
Assert.AreNotEqual(repeatable.StartToken, clonedTokens.Item1);
Assert.AreNotEqual(repeatable.StartToken.Start, clonedTokens.Item1.Start);
Assert.AreNotEqual(repeatable.StartToken.End, clonedTokens.Item1.End);
Assert.AreEqual(existingInnerTokens.Length, clonedTokens.Item2.Length);
Assert.AreNotEqual(repeatable.EndToken, clonedTokens.Item3);
Assert.AreNotEqual(repeatable.EndToken.Start, clonedTokens.Item3.Start);
Assert.AreNotEqual(repeatable.EndToken.End, clonedTokens.Item3.End);
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph>
<Run>^</Run>
<Run>{{ PrecedingField }}</Run>
<Run>{{ each Items }}</Run>
<Run>{{ Sequence }}</Run>
<Run>{{ end each }}</Run>
<Run>{{ each Items }}</Run>
<Run>{{ Sequence }}</Run>
<Run>{{ end each }}</Run>
<Run>$</Run>
</Paragraph>
</Body>
</Section>
</Document>");
}
示例8: MergeDocText_RepeatableInHeaderAndFooter
public void MergeDocText_RepeatableInHeaderAndFooter()
{
var doc = new Document();
var builder = new DocumentBuilder(doc);
builder.Write("{{ Name }}");
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.Write("{{ each Items }}");
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.Write("{{ end each }}");
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph>
<Run>{{ Name }}</Run>
</Paragraph>
</Body>
<HeaderFooter headerfootertype='HeaderPrimary' islinkedtoprevious='False' storytype='PrimaryHeader'>
<Paragraph>
<Run>{{ each Items }}</Run>
</Paragraph>
</HeaderFooter>
<HeaderFooter headerfootertype='FooterPrimary' islinkedtoprevious='False' storytype='PrimaryFooter'>
<Paragraph>
<Run>{{ end each }}</Run>
</Paragraph>
</HeaderFooter>
</Section>
</Document>");
var data = new
{
Name = "Shopping List",
Items = new[] {
new {Name = "Milk" },
new {Name = "Eggs" },
new {Name = "Artisan Bread" }
},
};
doc.Merge(data);
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph>
<Run>Milk</Run>
</Paragraph>
</Body>
</Section>
<Section>
<Body>
<Paragraph>
<Run>Eggs</Run>
</Paragraph>
</Body>
</Section>
<Section>
<Body>
<Paragraph>
<Run>Artisan Bread</Run>
</Paragraph>
</Body>
</Section>
</Document>");
}
示例9: MergeDocText_HyperlinkUrl
public void MergeDocText_HyperlinkUrl()
{
var doc = new Document();
var builder = new DocumentBuilder(doc);
builder.InsertRun("^ ");
builder.InsertField("HYPERLINK \"%7b%7bUrl%7d%7d\"");
builder.InsertRun(" $");
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph>
<Run>^ </Run>
<FieldStart></FieldStart>
<Run>HYPERLINK ""%7b%7bUrl%7d%7d""</Run>
<FieldSeparator></FieldSeparator>
<FieldEnd></FieldEnd>
<Run> $</Run>
</Paragraph>
</Body>
</Section>
</Document>
");
var data = new
{
Url = "https://www.google.com",
};
doc.Merge(data);
doc.AssertXml(@"
<Document>
<Section>
<Body>
<Paragraph>
<Run>^ </Run>
<FieldStart></FieldStart>
<Run>HYPERLINK ""</Run>
<Run>https://www.google.com</Run>
<Run>""</Run>
<FieldSeparator></FieldSeparator>
<FieldEnd></FieldEnd>
<Run> $</Run>
</Paragraph>
</Body>
</Section>
</Document>
");
}