PasswordConnectionInfoTest.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Tests.Common;
  3. using Renci.SshNet.Tests.Properties;
  4. using System;
  5. using System.Net;
  6. namespace Renci.SshNet.Tests.Classes
  7. {
  8. /// <summary>
  9. /// Provides connection information when password authentication method is used
  10. /// </summary>
  11. [TestClass]
  12. public class PasswordConnectionInfoTest : TestBase
  13. {
  14. [WorkItem(703), TestMethod]
  15. [TestCategory("PasswordConnectionInfo")]
  16. public void Test_ConnectionInfo_Host_Is_Null()
  17. {
  18. try
  19. {
  20. _ = new PasswordConnectionInfo(null, Resources.USERNAME, Resources.PASSWORD);
  21. Assert.Fail();
  22. }
  23. catch (ArgumentNullException ex)
  24. {
  25. Assert.IsNull(ex.InnerException);
  26. Assert.AreEqual("host", ex.ParamName);
  27. }
  28. }
  29. [WorkItem(703), TestMethod]
  30. [TestCategory("PasswordConnectionInfo")]
  31. [ExpectedException(typeof(ArgumentException))]
  32. public void Test_ConnectionInfo_Username_Is_Null()
  33. {
  34. _ = new PasswordConnectionInfo(Resources.HOST, null, Resources.PASSWORD);
  35. }
  36. [WorkItem(703), TestMethod]
  37. [TestCategory("PasswordConnectionInfo")]
  38. [ExpectedException(typeof(ArgumentNullException))]
  39. public void Test_ConnectionInfo_Password_Is_Null()
  40. {
  41. _ = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, (string)null);
  42. }
  43. [TestMethod]
  44. [TestCategory("PasswordConnectionInfo")]
  45. [Description("Test passing whitespace to username parameter.")]
  46. [ExpectedException(typeof(ArgumentException))]
  47. public void Test_ConnectionInfo_Username_Is_Whitespace()
  48. {
  49. _ = new PasswordConnectionInfo(Resources.HOST, " ", Resources.PASSWORD);
  50. }
  51. [WorkItem(703), TestMethod]
  52. [TestCategory("PasswordConnectionInfo")]
  53. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  54. public void Test_ConnectionInfo_SmallPortNumber()
  55. {
  56. _ = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MinPort - 1, Resources.USERNAME, Resources.PASSWORD);
  57. }
  58. [WorkItem(703), TestMethod]
  59. [TestCategory("PasswordConnectionInfo")]
  60. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  61. public void Test_ConnectionInfo_BigPortNumber()
  62. {
  63. _ = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MaxPort + 1, Resources.USERNAME, Resources.PASSWORD);
  64. }
  65. }
  66. }