PipeStreamTest_Dispose.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using System;
  2. using System.IO;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using Renci.SshNet.Common;
  5. using Renci.SshNet.Tests.Common;
  6. namespace Renci.SshNet.Tests.Classes
  7. {
  8. [TestClass]
  9. public class PipeStreamTest_Dispose : TestBase
  10. {
  11. private PipeStream _pipeStream;
  12. protected override void OnInit()
  13. {
  14. base.OnInit();
  15. Arrange();
  16. Act();
  17. }
  18. private void Arrange()
  19. {
  20. _pipeStream = new PipeStream();
  21. }
  22. private void Act()
  23. {
  24. _pipeStream.Dispose();
  25. }
  26. [TestMethod]
  27. public void CanRead_ShouldReturnTrue()
  28. {
  29. Assert.IsFalse(_pipeStream.CanRead);
  30. }
  31. [TestMethod]
  32. public void Flush_ShouldThrowObjectDisposedException()
  33. {
  34. try
  35. {
  36. _pipeStream.Flush();
  37. Assert.Fail();
  38. }
  39. catch (ObjectDisposedException)
  40. {
  41. }
  42. }
  43. [TestMethod]
  44. public void MaxBufferLength_Getter_ShouldReturnTwoHundredMegabyte()
  45. {
  46. Assert.AreEqual(200 * 1024 * 1024, _pipeStream.MaxBufferLength);
  47. }
  48. [TestMethod]
  49. public void MaxBufferLength_Setter_ShouldModifyMaxBufferLength()
  50. {
  51. var newValue = new Random().Next(1, int.MaxValue);
  52. _pipeStream.MaxBufferLength = newValue;
  53. Assert.AreEqual(newValue, _pipeStream.MaxBufferLength);
  54. }
  55. [TestMethod]
  56. public void Length_ShouldThrowObjectDisposedException()
  57. {
  58. try
  59. {
  60. var value = _pipeStream.Length;
  61. Assert.Fail("" + value);
  62. }
  63. catch (ObjectDisposedException)
  64. {
  65. }
  66. }
  67. [TestMethod]
  68. public void Position_Getter_ShouldReturnZero()
  69. {
  70. Assert.AreEqual(0, _pipeStream.Position);
  71. }
  72. [TestMethod]
  73. public void Position_Setter_ShouldThrowNotSupportedException()
  74. {
  75. try
  76. {
  77. _pipeStream.Position = 0;
  78. Assert.Fail();
  79. }
  80. catch (NotSupportedException)
  81. {
  82. }
  83. }
  84. [TestMethod]
  85. public void Read_ByteArrayAndOffsetAndCount_ShouldThrowObjectDisposedException()
  86. {
  87. var buffer = new byte[0];
  88. const int offset = 0;
  89. const int count = 0;
  90. try
  91. {
  92. _pipeStream.Read(buffer, offset, count);
  93. Assert.Fail();
  94. }
  95. catch (ObjectDisposedException)
  96. {
  97. }
  98. }
  99. [TestMethod]
  100. public void ReadByte_ShouldThrowObjectDisposedException()
  101. {
  102. try
  103. {
  104. _pipeStream.ReadByte();
  105. Assert.Fail();
  106. }
  107. catch (ObjectDisposedException)
  108. {
  109. }
  110. }
  111. [TestMethod]
  112. public void Seek_ShouldThrowNotSupportedException()
  113. {
  114. try
  115. {
  116. _pipeStream.Seek(0, SeekOrigin.Begin);
  117. Assert.Fail();
  118. }
  119. catch (NotSupportedException)
  120. {
  121. }
  122. }
  123. [TestMethod]
  124. public void SetLength_ShouldThrowNotSupportedException()
  125. {
  126. try
  127. {
  128. _pipeStream.SetLength(0);
  129. Assert.Fail();
  130. }
  131. catch (NotSupportedException)
  132. {
  133. }
  134. }
  135. [TestMethod]
  136. public void Write_ByteArrayAndOffsetAndCount_ShouldThrowObjectDisposedException()
  137. {
  138. var buffer = new byte[0];
  139. const int offset = 0;
  140. const int count = 0;
  141. try
  142. {
  143. _pipeStream.Write(buffer, offset, count);
  144. Assert.Fail();
  145. }
  146. catch (ObjectDisposedException)
  147. {
  148. }
  149. }
  150. [TestMethod]
  151. public void WriteByte_ShouldThrowObjectDisposedException()
  152. {
  153. const byte b = 0x0a;
  154. try
  155. {
  156. _pipeStream.WriteByte(b);
  157. Assert.Fail();
  158. }
  159. catch (ObjectDisposedException)
  160. {
  161. }
  162. }
  163. }
  164. }