PacketDumpTest.cs 5.6 KB

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