2
0

PipeStreamTest_Dispose.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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.IsTrue(_pipeStream.CanRead);
  30. }
  31. [TestMethod]
  32. public void Flush_ShouldNotThrow()
  33. {
  34. _pipeStream.Flush();
  35. }
  36. [TestMethod]
  37. public void Length_ShouldNotThrow()
  38. {
  39. _ = _pipeStream.Length;
  40. }
  41. [TestMethod]
  42. public void Position_Getter_ShouldReturnZero()
  43. {
  44. Assert.AreEqual(0, _pipeStream.Position);
  45. }
  46. [TestMethod]
  47. public void Position_Setter_ShouldThrowNotSupportedException()
  48. {
  49. try
  50. {
  51. _pipeStream.Position = 0;
  52. Assert.Fail();
  53. }
  54. catch (NotSupportedException)
  55. {
  56. }
  57. }
  58. [TestMethod]
  59. public void Read_ByteArrayAndOffsetAndCount_ShouldNotThrow()
  60. {
  61. Assert.AreEqual(0, _pipeStream.Read(new byte[1], 0, 1));
  62. }
  63. [TestMethod]
  64. public void ReadByte_ShouldNotThrow()
  65. {
  66. Assert.AreEqual(-1, _pipeStream.ReadByte());
  67. }
  68. [TestMethod]
  69. public void Seek_ShouldThrowNotSupportedException()
  70. {
  71. try
  72. {
  73. _pipeStream.Seek(0, SeekOrigin.Begin);
  74. Assert.Fail();
  75. }
  76. catch (NotSupportedException)
  77. {
  78. }
  79. }
  80. [TestMethod]
  81. public void SetLength_ShouldThrowNotSupportedException()
  82. {
  83. try
  84. {
  85. _pipeStream.SetLength(0);
  86. Assert.Fail();
  87. }
  88. catch (NotSupportedException)
  89. {
  90. }
  91. }
  92. [TestMethod]
  93. public void Write_ByteArrayAndOffsetAndCount_ShouldThrowObjectDisposedException()
  94. {
  95. var buffer = new byte[0];
  96. const int offset = 0;
  97. const int count = 0;
  98. try
  99. {
  100. _pipeStream.Write(buffer, offset, count);
  101. Assert.Fail();
  102. }
  103. catch (ObjectDisposedException)
  104. {
  105. }
  106. }
  107. [TestMethod]
  108. public void WriteByte_ShouldThrowObjectDisposedException()
  109. {
  110. const byte b = 0x0a;
  111. try
  112. {
  113. _pipeStream.WriteByte(b);
  114. Assert.Fail();
  115. }
  116. catch (ObjectDisposedException)
  117. {
  118. }
  119. }
  120. }
  121. }