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()); }
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"); }
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"); }