当前位置: 首页>>代码示例>>C#>>正文


C# JsonArray.ToText方法代码示例

本文整理汇总了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
//.........这里部分代码省略.........
开发者ID:larsenjo,项目名称:odata.net,代码行数:101,代码来源:WriterProjectedPropertyTests.cs


注:本文中的JsonArray.ToText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。