PasswordConnectionInfoTest.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Net;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using Renci.SshNet.Tests.Common;
  5. using Renci.SshNet.Tests.Properties;
  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. [TestMethod]
  15. public void Test_ConnectionInfo_Host_Is_Null()
  16. {
  17. try
  18. {
  19. _ = new PasswordConnectionInfo(null, Resources.USERNAME, Resources.PASSWORD);
  20. Assert.Fail();
  21. }
  22. catch (ArgumentNullException ex)
  23. {
  24. Assert.IsNull(ex.InnerException);
  25. Assert.AreEqual("host", ex.ParamName);
  26. }
  27. }
  28. [TestMethod]
  29. [ExpectedException(typeof(ArgumentNullException))]
  30. public void Test_ConnectionInfo_Username_Is_Null()
  31. {
  32. _ = new PasswordConnectionInfo(Resources.HOST, null, Resources.PASSWORD);
  33. }
  34. [TestMethod]
  35. [ExpectedException(typeof(ArgumentNullException))]
  36. public void Test_ConnectionInfo_Password_Is_Null()
  37. {
  38. _ = new PasswordConnectionInfo(Resources.HOST, Resources.USERNAME, (string)null);
  39. }
  40. [TestMethod]
  41. [ExpectedException(typeof(ArgumentException))]
  42. public void Test_ConnectionInfo_Username_Is_Whitespace()
  43. {
  44. _ = new PasswordConnectionInfo(Resources.HOST, " ", Resources.PASSWORD);
  45. }
  46. [TestMethod]
  47. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  48. public void Test_ConnectionInfo_SmallPortNumber()
  49. {
  50. _ = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MinPort - 1, Resources.USERNAME, Resources.PASSWORD);
  51. }
  52. [TestMethod]
  53. [ExpectedException(typeof(ArgumentOutOfRangeException))]
  54. public void Test_ConnectionInfo_BigPortNumber()
  55. {
  56. _ = new PasswordConnectionInfo(Resources.HOST, IPEndPoint.MaxPort + 1, Resources.USERNAME, Resources.PASSWORD);
  57. }
  58. }
  59. }