本文整理匯總了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);
}