當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。