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


C# Http.ObjectContent类代码示例

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


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

示例1: GetText

        public HttpResponseMessage GetText(string type, [FromBody] string inputText)
        {
            // if string is empty
            if (string.IsNullOrWhiteSpace(inputText))
            {
                return Request.CreateResponse(HttpStatusCode.NoContent, "Empty string");
            }
            // save to file
            Func.SaveToFile(inputText);

            // parse into revalent models
            Text text = Parser.ParseInputText(inputText);

            // get formatter from type
            var formatter = FormatFactory.GetFormatter(type);

            // create respons content
            var content = new ObjectContent<Text>(
                text,								// What we are serializing
                formatter//,						// The media formatter
                //mediaTypeHeaderValue.MediaType	// The MIME (multimedia internet message exchange )type
                );

            return new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content = content
            };
        }
开发者ID:JrPD,项目名称:XML_CSV_Parser,代码行数:29,代码来源:TextController.cs

示例2: ContainsFormatters

 public static void ContainsFormatters(ObjectContent objectContent, IEnumerable<MediaTypeFormatter> formatters)
 {
     Assert.IsNotNull(objectContent, "objectContent cannot be null.");
     Assert.IsNotNull(formatters, "Test error: formatters must be specified.");
     Assert.IsNotNull(objectContent.Formatters, "Formatters property cannot be null.");
     CollectionAssert.IsSubsetOf(formatters.ToList(), objectContent.Formatters, "Formatters did not include all expected formatters.");
 }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:7,代码来源:ObjectContentAssert.cs

示例3: 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

示例4: 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

示例5: 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

示例6: ContentHeadersAreAddedForXmlMediaType

        public void ContentHeadersAreAddedForXmlMediaType()
        {
            ObjectContent<IEnumerable<Person>> content = new ObjectContent<IEnumerable<Person>>(new Person[] { new Person(0, new ReferenceDepthContext(7)) }, _formatter);
            content.LoadIntoBufferAsync().Wait();

            Assert.Http.Contains(content.Headers, "DataServiceVersion", "3.0;");
            Assert.Http.Contains(content.Headers, "Content-Type", "application/xml; charset=utf-8");
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:8,代码来源:CollectionTest.cs

示例7: 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

示例8: FormatterShouldBeAbleToDeserializeArticle

        public async void FormatterShouldBeAbleToDeserializeArticle()
        {
            var content = new ObjectContent<Article>(_article, _formatter);

            var deserializedItem = await content.ReadAsAsync<Article>(new[] { _formatter });

            Assert.That(_article, Is.SameAs(deserializedItem));
        }
开发者ID:boriphuth,项目名称:webapiunittesting,代码行数:8,代码来源:MediaTypeFormatterTests.cs

示例9: ContentHeadersAreAddedForJsonMediaType

        public void ContentHeadersAreAddedForJsonMediaType()
        {
            HttpContent content = new ObjectContent<Person[]>(new Person[] { new Person(0, new ReferenceDepthContext(7)) }, _formatter, "application/json");
            content.LoadIntoBufferAsync().Wait();

            Assert.Http.Contains(content.Headers, "DataServiceVersion", "3.0;");
            Assert.Equal(content.Headers.ContentType.MediaType, "application/json");
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:8,代码来源:CollectionTest.cs

示例10: CanConvertFromStringReturnsFalseForObjectContent

 public void CanConvertFromStringReturnsFalseForObjectContent()
 {
     ObjectContent objectContent = new ObjectContent<int>(5);
     HttpParameterValueConverter converter = HttpParameterValueConverter.GetValueConverter(objectContent.GetType());
     if (converter.CanConvertFromString)
     {
         Assert.Fail(string.Format("CanConvertFromString was wrong for ObjectContent."));
     }
 }
开发者ID:nuxleus,项目名称:WCFWeb,代码行数:9,代码来源:HttpParameterValueConverterTests.cs

示例11: 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

示例12: 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

示例13: 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

示例14: ContentHeadersAreAddedForJsonMediaType

        public void ContentHeadersAreAddedForJsonMediaType()
        {
            ODataMediaTypeFormatter formatter = new ODataMediaTypeFormatter(GetSampleModel()) { Request = GetSampleRequest() };
            HttpContent content = new ObjectContent<Employee>(new Employee(0, new ReferenceDepthContext(7)), formatter, "application/json");
            content.LoadIntoBufferAsync().Wait();

            Assert.Http.Contains(content.Headers, "DataServiceVersion", "3.0;");
            Assert.Http.Contains(content.Headers, "Content-Type", "application/json; odata=verbose; charset=utf-8");
        }
开发者ID:marojeri,项目名称:aspnetwebstack,代码行数:9,代码来源:EntityTypeTest.cs

示例15: 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


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