本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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.");
}
示例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);
}