2
0

SshIdentificationTest.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. using System;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using Renci.SshNet.Connection;
  4. namespace Renci.SshNet.Tests.Classes.Connection
  5. {
  6. [TestClass]
  7. public class SshIdentificationTest
  8. {
  9. [TestMethod]
  10. public void Ctor_ProtocolVersionAndSoftwareVersion()
  11. {
  12. const string protocolVersion = "1.5";
  13. const string softwareVersion = "SSH.NET_2020.0.0";
  14. var sshIdentification = new SshIdentification(protocolVersion, softwareVersion);
  15. Assert.AreSame(protocolVersion, sshIdentification.ProtocolVersion);
  16. Assert.AreSame(softwareVersion, sshIdentification.SoftwareVersion);
  17. Assert.IsNull(sshIdentification.Comments);
  18. }
  19. [TestMethod]
  20. public void Ctor_ProtocolVersionAndSoftwareVersion_ProtocolVersionIsNull()
  21. {
  22. const string protocolVersion = null;
  23. const string softwareVersion = "SSH.NET_2020.0.0";
  24. try
  25. {
  26. _ = new SshIdentification(protocolVersion, softwareVersion);
  27. Assert.Fail();
  28. }
  29. catch (ArgumentNullException ex)
  30. {
  31. Assert.IsNull(ex.InnerException);
  32. Assert.AreEqual("protocolVersion", ex.ParamName);
  33. }
  34. }
  35. [TestMethod]
  36. public void Ctor_ProtocolVersionAndSoftwareVersion_SoftwareVersionIsNull()
  37. {
  38. const string protocolVersion = "2.0";
  39. const string softwareVersion = null;
  40. try
  41. {
  42. _ = new SshIdentification(protocolVersion, softwareVersion);
  43. Assert.Fail();
  44. }
  45. catch (ArgumentNullException ex)
  46. {
  47. Assert.IsNull(ex.InnerException);
  48. Assert.AreEqual("softwareVersion", ex.ParamName);
  49. }
  50. }
  51. [TestMethod]
  52. public void Ctor_ProtocolVersionAndSoftwareVersionAndComments()
  53. {
  54. const string protocolVersion = "1.5";
  55. const string softwareVersion = "SSH.NET_2020.0.0";
  56. const string comments = "Beware, dangerous!";
  57. var sshIdentification = new SshIdentification(protocolVersion, softwareVersion, comments);
  58. Assert.AreEqual(protocolVersion, sshIdentification.ProtocolVersion);
  59. Assert.AreEqual(softwareVersion, sshIdentification.SoftwareVersion);
  60. Assert.AreEqual(comments, sshIdentification.Comments);
  61. }
  62. [TestMethod]
  63. public void Ctor_ProtocolVersionAndSoftwareVersionAndComments_CommentsIsNull()
  64. {
  65. const string protocolVersion = "1.5";
  66. const string softwareVersion = "SSH.NET_2020.0.0";
  67. const string comments = null;
  68. var sshIdentification = new SshIdentification(protocolVersion, softwareVersion, comments);
  69. Assert.AreEqual(protocolVersion, sshIdentification.ProtocolVersion);
  70. Assert.AreEqual(softwareVersion, sshIdentification.SoftwareVersion);
  71. Assert.IsNull(sshIdentification.Comments);
  72. }
  73. [TestMethod]
  74. public void Ctor_ProtocolVersionAndSoftwareVersionAndComments_ProtocolVersionIsNull()
  75. {
  76. const string protocolVersion = null;
  77. const string softwareVersion = "SSH.NET_2020.0.0";
  78. const string comments = "Beware!";
  79. try
  80. {
  81. _ = new SshIdentification(protocolVersion, softwareVersion, comments);
  82. Assert.Fail();
  83. }
  84. catch (ArgumentNullException ex)
  85. {
  86. Assert.IsNull(ex.InnerException);
  87. Assert.AreEqual("protocolVersion", ex.ParamName);
  88. }
  89. }
  90. [TestMethod]
  91. public void Ctor_ProtocolVersionAndSoftwareVersionAndComments_SoftwareVersionIsNull()
  92. {
  93. const string protocolVersion = "2.0";
  94. const string softwareVersion = null;
  95. const string comments = "Beware!";
  96. try
  97. {
  98. _ = new SshIdentification(protocolVersion, softwareVersion, comments);
  99. Assert.Fail();
  100. }
  101. catch (ArgumentNullException ex)
  102. {
  103. Assert.IsNull(ex.InnerException);
  104. Assert.AreEqual("softwareVersion", ex.ParamName);
  105. }
  106. }
  107. [TestMethod]
  108. public void ToString_Comments()
  109. {
  110. var sshIdentification = new SshIdentification("2.0", "SSH.NET", "Beware, dangerous");
  111. Assert.AreEqual("SSH-2.0-SSH.NET Beware, dangerous", sshIdentification.ToString());
  112. }
  113. [TestMethod]
  114. public void ToString_CommentsIsNull()
  115. {
  116. var sshIdentification = new SshIdentification("2.0", "SSH.NET_2020.0.0");
  117. Assert.AreEqual("SSH-2.0-SSH.NET_2020.0.0", sshIdentification.ToString());
  118. sshIdentification = new SshIdentification("2.0", "SSH.NET_2020.0.0", null);
  119. Assert.AreEqual("SSH-2.0-SSH.NET_2020.0.0", sshIdentification.ToString());
  120. }
  121. }
  122. }