PacketDumpTest.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Renci.SshNet.Common;
  4. using Renci.SshNet.Tests.Common;
  5. namespace Renci.SshNet.Tests.Classes.Common
  6. {
  7. [TestClass]
  8. public class PacketDumpTest
  9. {
  10. [TestMethod]
  11. public void Create_ByteArrayAndIndentLevel_DataIsNull()
  12. {
  13. const byte[] data = null;
  14. try
  15. {
  16. _ = PacketDump.Create(data, 0);
  17. Assert.Fail();
  18. }
  19. catch (ArgumentNullException ex)
  20. {
  21. Assert.IsNull(ex.InnerException);
  22. Assert.AreEqual("data", ex.ParamName);
  23. }
  24. }
  25. [TestMethod]
  26. public void Create_ByteArrayAndIndentLevel_IndentLevelLessThanZero()
  27. {
  28. var data = new byte[0];
  29. try
  30. {
  31. _ = PacketDump.Create(data, -1);
  32. Assert.Fail();
  33. }
  34. catch (ArgumentOutOfRangeException ex)
  35. {
  36. Assert.IsNull(ex.InnerException);
  37. ArgumentExceptionAssert.MessageEquals("Cannot be less than zero.", ex);
  38. Assert.AreEqual("indentLevel", ex.ParamName);
  39. }
  40. }
  41. [TestMethod]
  42. public void Create_ByteArrayAndIndentLevel_DataIsEmpty()
  43. {
  44. var data = new byte[0];
  45. var actual = PacketDump.Create(data, 2);
  46. Assert.AreEqual(string.Empty, actual);
  47. }
  48. [TestMethod]
  49. public void Create_ByteArrayAndIndentLevel_DataIsMultipleOfLineWidth_IndentLevelTwo()
  50. {
  51. var data = new byte[]
  52. {
  53. 0x07, 0x00, 0x1f, 0x65, 0x20, 0x62, 0x09, 0x44, 0x7f, 0x0d, 0x0a, 0x36, 0x80, 0x53, 0x53, 0x48,
  54. 0x2e, 0x4e, 0x45, 0x54, 0x20, 0x32, 0x30, 0x32, 0x30, 0x20, 0xf6, 0x7a, 0x32, 0x7f, 0x1f, 0x7e
  55. };
  56. var expected = " 00000000 07 00 1F 65 20 62 09 44 7F 0D 0A 36 80 53 53 48 ...e b.D...6.SSH" +
  57. Environment.NewLine +
  58. " 00000010 2E 4E 45 54 20 32 30 32 30 20 F6 7A 32 7F 1F 7E .NET 2020 .z2..~";
  59. var actual = PacketDump.Create(data, 2);
  60. Assert.AreEqual(expected, actual);
  61. }
  62. [TestMethod]
  63. public void Create_ByteArrayAndIndentLevel_DataIsMultipleOfLineWidth_IndentLevelZero()
  64. {
  65. var data = new byte[]
  66. {
  67. 0x07, 0x00, 0x1f, 0x65, 0x20, 0x62, 0x09, 0x44, 0x7f, 0x0d, 0x0a, 0x36, 0x80, 0x53, 0x53, 0x48,
  68. 0x2e, 0x4e, 0x45, 0x54, 0x20, 0x32, 0x30, 0x32, 0x30, 0x20, 0xf6, 0x7a, 0x32, 0x7f, 0x1f, 0x7e
  69. };
  70. var expected = "00000000 07 00 1F 65 20 62 09 44 7F 0D 0A 36 80 53 53 48 ...e b.D...6.SSH" +
  71. Environment.NewLine +
  72. "00000010 2E 4E 45 54 20 32 30 32 30 20 F6 7A 32 7F 1F 7E .NET 2020 .z2..~";
  73. var actual = PacketDump.Create(data, 0);
  74. Assert.AreEqual(expected, actual);
  75. }
  76. [TestMethod]
  77. public void Create_ByteArrayAndIndentLevel_DataIsLineWith()
  78. {
  79. var data = new byte[]
  80. {
  81. 0x07, 0x00, 0x1f, 0x65, 0x20, 0x62, 0x09, 0x44, 0x7f, 0x0d, 0x0a, 0x36, 0x80, 0x53, 0x53, 0x48
  82. };
  83. var expected = " 00000000 07 00 1F 65 20 62 09 44 7F 0D 0A 36 80 53 53 48 ...e b.D...6.SSH";
  84. var actual = PacketDump.Create(data, 2);
  85. Assert.AreEqual(expected, actual);
  86. }
  87. [TestMethod]
  88. public void Create_ByteArrayAndIndentLevel_DataIsLessThanLineWith()
  89. {
  90. var data = new byte[]
  91. {
  92. 0x07, 0x00, 0x1f, 0x65, 0x20, 0x62, 0x09, 0x44, 0x7f, 0x0d, 0x0a, 0x36, 0x80, 0x53
  93. };
  94. var expected = " 00000000 07 00 1F 65 20 62 09 44 7F 0D 0A 36 80 53 ...e b.D...6.S";
  95. var actual = PacketDump.Create(data, 2);
  96. Assert.AreEqual(expected, actual);
  97. }
  98. [TestMethod]
  99. public void Create_ByteArrayAndIndentLevel_DataIsGreaterThanLineWidthButLessThanMultipleOfLineWidth()
  100. {
  101. var data = new byte[]
  102. {
  103. 0x07, 0x00, 0x1f, 0x65, 0x20, 0x62, 0x09, 0x44, 0x7f, 0x0d, 0x0a, 0x36, 0x80, 0x53, 0x53, 0x48,
  104. 0x2e, 0x4e, 0x45, 0x54
  105. };
  106. var expected = " 00000000 07 00 1F 65 20 62 09 44 7F 0D 0A 36 80 53 53 48 ...e b.D...6.SSH" +
  107. Environment.NewLine +
  108. " 00000010 2E 4E 45 54 .NET";
  109. var actual = PacketDump.Create(data, 2);
  110. Assert.AreEqual(expected, actual);
  111. }
  112. [TestMethod]
  113. public void Create_ByteArrayAndIndentLevel_DataIsGreaterThanMultipleOfLineWidth()
  114. {
  115. var data = new byte[]
  116. {
  117. 0x07, 0x00, 0x1f, 0x65, 0x20, 0x62, 0x09, 0x44, 0x7f, 0x0d, 0x0a, 0x36, 0x80, 0x53, 0x53, 0x48,
  118. 0x2e, 0x4e, 0x45, 0x54, 0x20, 0x32, 0x30, 0x32, 0x30, 0x20, 0xf6, 0x7a, 0x32, 0x7f, 0x1f, 0x7e,
  119. 0x78, 0x54, 0x00, 0x52
  120. };
  121. var expected = " 00000000 07 00 1F 65 20 62 09 44 7F 0D 0A 36 80 53 53 48 ...e b.D...6.SSH" +
  122. Environment.NewLine +
  123. " 00000010 2E 4E 45 54 20 32 30 32 30 20 F6 7A 32 7F 1F 7E .NET 2020 .z2..~" +
  124. Environment.NewLine +
  125. " 00000020 78 54 00 52 xT.R";
  126. var actual = PacketDump.Create(data, 2);
  127. Assert.AreEqual(expected, actual);
  128. }
  129. }
  130. }