本文整理汇总了C#中System.Net.Http.StreamContent.ReadAsStreamAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StreamContent.ReadAsStreamAsync方法的具体用法?C# StreamContent.ReadAsStreamAsync怎么用?C# StreamContent.ReadAsStreamAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.StreamContent
的用法示例。
在下文中一共展示了StreamContent.ReadAsStreamAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldBeAbleToCreateStreamContent
public void ShouldBeAbleToCreateStreamContent()
{
//Arrange
var ms = new MemoryStream();
var sr = new StreamWriter(ms);
sr.Write("Hello World");
sr.Flush();
ms.Position = 0;
//Act
var content = new StreamContent(ms);
//Assert
Assert.IsNotNull(content);
Assert.AreEqual("Hello World", content.ReadAsStringAsync().Result);
Assert.AreEqual("Hello World", new StreamReader(content.ReadAsStreamAsync().Result).ReadToEnd());
}
示例2: ReadAsStream
public void ReadAsStream ()
{
var ms = new MemoryStream ();
ms.WriteByte (77);
ms.WriteByte (55);
ms.Seek (0, SeekOrigin.Begin);
var sc = new StreamContent (ms);
var res = sc.ReadAsStreamAsync ().Result;
Assert.AreEqual (77, res.ReadByte (), "#1");
}
示例3: ReadAsStreamAsync_ClosedInput
public void ReadAsStreamAsync_ClosedInput ()
{
var stream = new MemoryStream (new byte[] { 1 });
var content = new StreamContent (stream);
Assert.IsTrue (content.LoadIntoBufferAsync ().Wait (3000), "#1");
stream.Close ();
var stream_read = content.ReadAsStreamAsync ().Result;
Assert.IsTrue (stream_read.CanSeek, "#2");
Assert.AreEqual (0, stream_read.Position, "#3");
Assert.AreEqual (1, stream_read.Length, "#4");
}