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


C# ObjectContent.ReadAsStringAsync方法代码示例

本文整理汇总了C#中System.Net.Http.ObjectContent.ReadAsStringAsync方法的典型用法代码示例。如果您正苦于以下问题:C# ObjectContent.ReadAsStringAsync方法的具体用法?C# ObjectContent.ReadAsStringAsync怎么用?C# ObjectContent.ReadAsStringAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.ObjectContent的用法示例。


在下文中一共展示了ObjectContent.ReadAsStringAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IEnumerableOfEntityTypeSerializesAsODataFeed

        private void IEnumerableOfEntityTypeSerializesAsODataFeed(string expectedContent, bool json)
        {
            ODataMediaTypeFormatter formatter = CreateFormatter();

            IEnumerable<Employee> collectionOfPerson = new Collection<Employee>() 
            {
                (Employee)TypeInitializer.GetInstance(SupportedTypes.Employee, 0),
                (Employee)TypeInitializer.GetInstance(SupportedTypes.Employee, 1),
            };

            ObjectContent<IEnumerable<Employee>> content = new ObjectContent<IEnumerable<Employee>>(collectionOfPerson,
                formatter, json ? ODataMediaTypes.ApplicationJsonODataMinimalMetadata :
                ODataMediaTypes.ApplicationAtomXmlTypeFeed);

            string actualContent = content.ReadAsStringAsync().Result;

            if (json)
            {
                JsonAssert.Equal(expectedContent, actualContent);
            }
            else
            {
                RegexReplacement replaceUpdateTime = new RegexReplacement(
                    "<updated>*.*</updated>", "<updated>UpdatedTime</updated>");
                Assert.Xml.Equal(expectedContent, actualContent, replaceUpdateTime);
            }
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:27,代码来源:FeedTest.cs

示例2: ArrayOfIntsSerializesAsOData

        private void ArrayOfIntsSerializesAsOData(string expectedContent, bool json)
        {
            ObjectContent<int[]> content = new ObjectContent<int[]>(new int[] { 10, 20, 30, 40, 50 }, _formatter,
                GetMediaType(json));

            AssertEqual(json, expectedContent, content.ReadAsStringAsync().Result);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:7,代码来源:CollectionTest.cs

示例3: ArrayOfBoolsSerializesAsOData

        private void ArrayOfBoolsSerializesAsOData(string expectedContent, bool json)
        {
            ObjectContent<bool[]> content = new ObjectContent<bool[]>(new bool[] { true, false, true, false },
                _formatter, GetMediaType(json));

            AssertEqual(json, expectedContent, content.ReadAsStringAsync().Result);
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:7,代码来源:CollectionTest.cs

示例4: ComplexTypeSerializesAsOData

        private void ComplexTypeSerializesAsOData(string expectedContent, bool json)
        {
            ObjectContent<Person> content = new ObjectContent<Person>(new Person(0, new ReferenceDepthContext(7)),
                _formatter, CollectionTest.GetMediaType(json));


            CollectionTest.AssertEqual(json, expectedContent, content.ReadAsStringAsync().Result);
        }
开发者ID:naulizzang,项目名称:aspnetwebstack,代码行数:8,代码来源:ComplexTypeTest.cs

示例5: ArrayOfIntsSerializesAsOData

        public void ArrayOfIntsSerializesAsOData()
        {
            // Arrange
            ObjectContent<int[]> content = new ObjectContent<int[]>(new int[] { 10, 20, 30, 40, 50 }, _formatter,
                ODataMediaTypes.ApplicationJsonODataMinimalMetadata);

            // Act & Assert
            JsonAssert.Equal(Resources.ArrayOfInt32, content.ReadAsStringAsync().Result);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:9,代码来源:CollectionTest.cs

示例6: ArrayOfBooleansSerializesAsOData

        public void ArrayOfBooleansSerializesAsOData()
        {
            // Arrange
            ObjectContent<bool[]> content = new ObjectContent<bool[]>(new bool[] { true, false, true, false },
                _formatter, ODataMediaTypes.ApplicationJsonODataMinimalMetadata);

            // Act & Assert
            JsonAssert.Equal(Resources.ArrayOfBoolean, content.ReadAsStringAsync().Result);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:9,代码来源:CollectionTest.cs

示例7: EntityTypeSerializesAsODataEntry

        public void EntityTypeSerializesAsODataEntry()
        {
            ODataMediaTypeFormatter formatter = CreateFormatter();
            Employee employee = (Employee)TypeInitializer.GetInstance(SupportedTypes.Employee);
            ObjectContent<Employee> content = new ObjectContent<Employee>(employee, formatter);

            RegexReplacement replaceUpdateTime = new RegexReplacement("<updated>*.*</updated>", "<updated>UpdatedTime</updated>");
            Assert.Xml.Equal(BaselineResource.TestEntityTypeBasic, content.ReadAsStringAsync().Result, regexReplacements: replaceUpdateTime);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:9,代码来源:EntityTypeTest.cs

示例8: render_simple_template

        public void render_simple_template()
        {
            var view = new View("Test1", new {Name = "foo"});
            var content = new ObjectContent<View>(view, _formatter);

            var output = content.ReadAsStringAsync().Result;

            Assert.AreEqual("Hello foo! Welcome to Razor!", output);
        }
开发者ID:jonwingfield,项目名称:WebApiContrib.Formatting.Razor,代码行数:9,代码来源:ViewEngineTests.cs

示例9: ComplexTypeSerializesAsOData

        public void ComplexTypeSerializesAsOData()
        {
            // Arrange
            ObjectContent<Person> content = new ObjectContent<Person>(new Person(0, new ReferenceDepthContext(7)),
                _formatter, ODataMediaTypes.ApplicationJsonODataMinimalMetadata);

            // Act & Assert
            JsonAssert.Equal(Resources.PersonComplexType, content.ReadAsStringAsync().Result);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:9,代码来源:ComplexTypeTest.cs

示例10: render_template_with_embedded_layout

        public void render_template_with_embedded_layout()
        {
            var view = new View("Test2", new { Name = "foo" });
            var content = new ObjectContent<View>(view, _formatter);

            var output = content.ReadAsStringAsync().Result;

            Assert.AreEqual("<html>Hello foo! Welcome to Razor!</html>", output);
        }
开发者ID:jonwingfield,项目名称:WebApiContrib.Formatting.Razor,代码行数:9,代码来源:ViewEngineTests.cs

示例11: render_template_with_specified_resolver

        public void render_template_with_specified_resolver()
        {
            var resolver = new EmbeddedResolver(this.GetType());
            var formatter = new HtmlMediaTypeViewFormatter(null, new RazorViewLocator(), new RazorViewParser(resolver));
            var view = new View("Test2", new { Name = "foo" });
            var content = new ObjectContent<View>(view, formatter);

            var output = content.ReadAsStringAsync().Result;

            Assert.AreEqual("<html>Hello foo! Welcome to Razor!</html>", output);
        }
开发者ID:jonwingfield,项目名称:WebApiContrib.Formatting.Razor,代码行数:11,代码来源:ViewEngineTests.cs

示例12: EntityTypeSerializesAsODataEntry

        public void EntityTypeSerializesAsODataEntry()
        {
            // Arrange
            ODataMediaTypeFormatter formatter = CreateFormatter();
            Employee employee = (Employee)TypeInitializer.GetInstance(SupportedTypes.Employee);
            ObjectContent<Employee> content = new ObjectContent<Employee>(employee, formatter,
                ODataMediaTypes.ApplicationJsonODataMinimalMetadata);

            // Act & Assert
            JsonAssert.Equal(Resources.EmployeeEntry, content.ReadAsStringAsync().Result);
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:11,代码来源:EntityTypeTest.cs

示例13: ListOfStringsSerializesAsOData

        public void ListOfStringsSerializesAsOData()
        {
            List<string> listOfStrings = new List<string>();
            listOfStrings.Add("Frank");
            listOfStrings.Add("Steve");
            listOfStrings.Add("Tom");
            listOfStrings.Add("Chandler");

            ObjectContent<List<string>> content = new ObjectContent<List<string>>(listOfStrings, _formatter);

            Assert.Xml.Equal(BaselineResource.TestListOfStrings, content.ReadAsStringAsync().Result);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:12,代码来源:CollectionTest.cs

示例14: CollectionOfObjectsSerializesAsOData

        public void CollectionOfObjectsSerializesAsOData()
        {
            Collection<object> collectionOfObjects = new Collection<object>();
            collectionOfObjects.Add(1);
            collectionOfObjects.Add("Frank");
            collectionOfObjects.Add(TypeInitializer.GetInstance(SupportedTypes.Person, 2));
            collectionOfObjects.Add(TypeInitializer.GetInstance(SupportedTypes.Employee, 3));

            ObjectContent<Collection<object>> content = new ObjectContent<Collection<object>>(collectionOfObjects, _formatter);

            Assert.Throws<ODataException>(() => content.ReadAsStringAsync().Result);
        }
开发者ID:mikevpeters,项目名称:aspnetwebstack,代码行数:12,代码来源:CollectionTest.cs

示例15: CollectionOfComplexTypeSerializesAsOData

        public void CollectionOfComplexTypeSerializesAsOData()
        {
            IEnumerable<Person> collectionOfPerson = new Collection<Person>() 
            {
                (Person)TypeInitializer.GetInstance(SupportedTypes.Person, 0),
                (Person)TypeInitializer.GetInstance(SupportedTypes.Person, 1),
                (Person)TypeInitializer.GetInstance(SupportedTypes.Person, 2)
            };

            ObjectContent<IEnumerable<Person>> content = new ObjectContent<IEnumerable<Person>>(collectionOfPerson, _formatter);

            Assert.Xml.Equal(BaselineResource.TestCollectionOfPerson, content.ReadAsStringAsync().Result);
        }
开发者ID:Swethach,项目名称:aspnetwebstack,代码行数:13,代码来源:CollectionTest.cs


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