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


C# StringContent.ReadAsStreamAsync方法代码示例

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


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

示例1: TextMediaTypeFormatter_CanReadTextStream

        public void TextMediaTypeFormatter_CanReadTextStream(string encoding)
        {
            var mediaTypeFormatter = new TextMediaTypeFormatter();
            var expected = "this is my text £!";
            HttpContent content = new StringContent(expected, Encoding.GetEncoding(encoding));

            var formatterLogger = new Mock<IFormatterLogger>();
            var result = mediaTypeFormatter.ReadFromStreamAsync(typeof(string), content.ReadAsStreamAsync().Result, content, formatterLogger.Object);

            Assert.Equal(result.Result.ToString(), expected);
        }
开发者ID:wongatech,项目名称:HealthMonitoring,代码行数:11,代码来源:TextMediaTypeFormatterTests.cs

示例2: Can_Read_the_spec_sample

        public async Task Can_Read_the_spec_sample()
        {
            // Arrange
            var sample = TestHelper.SPEC_SAMPLE_JSON;
            var sampleContent = new StringContent(sample);

            // Act
            var doc = await Formatter.ReadFromStreamAsync(typeof(ISirenEntity), await sampleContent.ReadAsStreamAsync(), sampleContent, null);

            // Assert
            var sirenDoc = Assert.IsAssignableFrom<ISirenEntity>(doc);
            TestHelper.AssertIsSpecSample(sirenDoc);
        }
开发者ID:dariogriffo,项目名称:WebApiContrib.Formatting.JilSiren.Net,代码行数:13,代码来源:FormatterTest.cs

示例3: PrimitiveTypesDeserializeAsOData

        public void PrimitiveTypesDeserializeAsOData(Type valueType, object value, MediaTypeHeaderValue mediaType,
            string resourceName)
        {
            string entity = Resources.GetString(resourceName);
            Assert.NotNull(entity);

            object expectedValue = value;

            ODataConventionModelBuilder modelBuilder = new ODataConventionModelBuilder();
            modelBuilder.EntitySet<WorkItem>("WorkItems");
            IEdmModel model = modelBuilder.GetEdmModel();

            object actualValue;

            using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/WorkItems(10)/ID"))
            {
                HttpConfiguration config = new HttpConfiguration();
                config.Routes.MapODataServiceRoute("default", "", model);
                request.SetConfiguration(config);
                request.ODataProperties().RouteName = "default";
                request.ODataProperties().Model = model;

                ODataMediaTypeFormatter formatter = CreateFormatter(request);
                formatter.SupportedMediaTypes.Add(mediaType);

                using (StringContent content = new StringContent(entity))
                {
                    content.Headers.ContentType = mediaType;

                    using (Stream stream = content.ReadAsStreamAsync().Result)
                    {
                        actualValue = formatter.ReadFromStreamAsync(valueType, stream, content,
                            new Mock<IFormatterLogger>().Object).Result;
                    }
                }
            }

            Assert.Equal(expectedValue, actualValue);
        }
开发者ID:nicholaspei,项目名称:aspnetwebstack,代码行数:39,代码来源:PrimitiveTypesTest.cs

示例4: Posting_NonDerivedType_To_Action_Expecting_BaseType_Throws

        public void Posting_NonDerivedType_To_Action_Expecting_BaseType_Throws()
        {
            StringContent content = new StringContent("{ '__metadata' : { 'type' : 'System.Web.Http.OData.Builder.TestModels.Motorcycle' } }");
            content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json;odata=verbose");
            IODataRequestMessage oDataRequest = new ODataMessageWrapper(content.ReadAsStreamAsync().Result, content.Headers);
            ODataMessageReader reader = new ODataMessageReader(oDataRequest, new ODataMessageReaderSettings(), _model);

            ODataDeserializerProvider deserializerProvider = new DefaultODataDeserializerProvider();

            ODataDeserializerContext context = new ODataDeserializerContext { Model = _model };
            context.Path = new ODataPath(new ActionPathSegment(_model.EntityContainers().Single().FunctionImports().Single(f => f.Name == "PostMotorcycle_When_Expecting_Car")));

            Assert.Throws<ODataException>(
                () => new ODataEntityDeserializer(deserializerProvider).Read(reader, typeof(Car), context),
                "An entry with type 'System.Web.Http.OData.Builder.TestModels.Motorcycle' was found, " +
                "but it is not assignable to the expected type 'System.Web.Http.OData.Builder.TestModels.Car'. " +
                "The type specified in the entry must be equal to either the expected type or a derived type.");
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:18,代码来源:InheritanceTests.cs

示例5: CreateJsonLightRequest

        private static IODataRequestMessage CreateJsonLightRequest(string body)
        {
            HttpContent content = new StringContent(body);
            HttpContentHeaders headers = content.Headers;
            headers.ContentType = MediaTypeHeaderValue.Parse("application/json;odata.metadata=full");

            return new ODataMessageWrapper(content.ReadAsStreamAsync().Result, headers);
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:8,代码来源:ODataMessageReaderLearningTests.cs


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