public void ReadStreamMultipleTimes() { FileInfo file = null; Stream stream = null; try { file = new FileInfo("ReadStreamMultipleTimes"); stream = file.Create(); // attempting to read this stream twice is an error... InputStreamResource res = new InputStreamResource(stream, "A temporary resource."); Stream streamOne = res.InputStream; Stream streamTwo; Assert.Throws <InvalidOperationException>(() => streamTwo = res.InputStream); // should bail here } finally { try { if (stream != null) { stream.Close(); } if (file != null && file.Exists) { file.Delete(); } } catch {} } }
public void Instantiation() { FileInfo file = null; Stream stream = null; try { file = new FileInfo("Instantiation"); stream = file.Create(); InputStreamResource res = new InputStreamResource(stream, "A temporary resource."); Assert.IsTrue(res.IsOpen); Assert.IsTrue(res.Exists); Assert.IsNotNull(res.InputStream); } finally { try { if (stream != null) { stream.Close(); } if (file != null && file.Exists) { file.Delete(); } } catch {} } }