本文整理汇总了C#中JsonArray.ToText方法的典型用法代码示例。如果您正苦于以下问题:C# JsonArray.ToText方法的具体用法?C# JsonArray.ToText怎么用?C# JsonArray.ToText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonArray
的用法示例。
在下文中一共展示了JsonArray.ToText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateExpectedResults
private WriterTestExpectedResults CreateExpectedResults(WriterTestConfiguration testConfiguration, ProjectedPropertiesTestCase testCase, bool withModel)
{
if (testCase.ExpectedException != null)
{
ExpectedException expectedException = testCase.ExpectedException(withModel);
if (expectedException != null)
{
return new WriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
ExpectedException2 = expectedException
};
}
}
if (testConfiguration.Format == ODataFormat.Atom)
{
#region Atom expected result
var atomExpectedResults = new AtomWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
Xml = new XElement("properties", testCase.ExpectedProperties.OrderBy(p => p).Select(p => new XElement(p))).ToString(),
FragmentExtractor = (result) =>
{
// Navigation links
IEnumerable<string> actualProperties;
if (result == null)
{
actualProperties = new string[0];
}
else
{
actualProperties = result.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName)
.Where(link => link.Attribute(TestAtomConstants.AtomLinkRelationAttributeName).Value.StartsWith(TestAtomConstants.ODataNavigationPropertiesRelatedLinkRelationPrefix))
.Select(link => link.Attribute(TestAtomConstants.AtomLinkTitleAttributeName).Value);
// Named stream links
actualProperties = actualProperties.Concat(result.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName)
.Where(link => link.Attribute(TestAtomConstants.AtomLinkRelationAttributeName).Value.StartsWith(TestAtomConstants.ODataStreamPropertyEditMediaRelatedLinkRelationPrefix))
.Select(link => link.Attribute(TestAtomConstants.AtomLinkTitleAttributeName).Value));
// Association links
actualProperties = actualProperties.Concat(result.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName)
.Where(link => link.Attribute(TestAtomConstants.AtomLinkRelationAttributeName).Value.StartsWith(TestAtomConstants.ODataNavigationPropertiesAssociationLinkRelationPrefix))
.Select(link => link.Attribute(TestAtomConstants.AtomLinkTitleAttributeName).Value));
// Properties
actualProperties = actualProperties.Concat(result.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomContentElementName)
.Elements(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.AtomPropertiesElementName)
.Elements().Where(e => e.Name.Namespace == TestAtomConstants.ODataXNamespace)
.Select(pe => pe.Name.LocalName));
}
return new XElement("properties",
actualProperties.OrderBy(p => p).Select(p => new XElement(p)));
}
};
if (testCase.NestedPayload)
{
var originalFragmentExtractor = atomExpectedResults.FragmentExtractor;
atomExpectedResults.FragmentExtractor = (result) =>
{
// Verify that the Wrapping_ID property is not written
this.Assert.IsNull(result
.Element(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomContentElementName)
.Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.AtomPropertiesElementName),
"There should be no other property but the nav link and thus no m:properties in the content.");
XElement expandedNavLinkElement = result.Elements(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomLinkElementName)
.Where(link => link.Attribute(TestAtomConstants.AtomLinkRelationAttributeName).Value
.StartsWith(TestAtomConstants.ODataNavigationPropertiesRelatedLinkRelationPrefix + "Wrapping_ExpandedEntry"))
.SingleOrDefault();
return originalFragmentExtractor(
expandedNavLinkElement == null
? null
: expandedNavLinkElement
.Element(TestAtomConstants.ODataMetadataXNamespace + TestAtomConstants.ODataInlineElementName)
.Element(TestAtomConstants.AtomXNamespace + TestAtomConstants.AtomEntryElementName));
};
}
return atomExpectedResults;
#endregion Atom expected result
}
else if (testConfiguration.Format == ODataFormat.Json)
{
#region JSON Light expected result
JsonArray expectedJson = new JsonArray();
foreach (var p in testCase.ExpectedProperties.Distinct().OrderBy(p => p))
{
expectedJson.Add(new JsonPrimitiveValue(p));
}
var jsonExpectedResults = new JsonWriterTestExpectedResults(this.Settings.ExpectedResultSettings)
{
Json = expectedJson.ToText(/*writingJsonLight*/ true, testConfiguration.MessageWriterSettings.Indent),
FragmentExtractor = (result) =>
{
// Everything except association links
IEnumerable<string> actualProperties;
if (result == null)
{
actualProperties = new string[0];
}
else
//.........这里部分代码省略.........