PortForwardEventArgsTest.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Net;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using Renci.SshNet.Common;
  5. using Renci.SshNet.Tests.Common;
  6. using Renci.SshNet.Tests.Properties;
  7. namespace Renci.SshNet.Tests.Classes.Common
  8. {
  9. /// <summary>
  10. /// Provides data for <see cref="ForwardedPort.RequestReceived"/> event.
  11. /// </summary>
  12. [TestClass]
  13. public class PortForwardEventArgsTest : TestBase
  14. {
  15. [TestMethod]
  16. public void ConstructorShouldThrowArgumentNullExceptionWhenHostIsNull()
  17. {
  18. try
  19. {
  20. _ = new PortForwardEventArgs(null, 80);
  21. }
  22. catch (ArgumentNullException ex)
  23. {
  24. Assert.IsNull(ex.InnerException);
  25. Assert.AreEqual("host", ex.ParamName);
  26. }
  27. }
  28. [TestMethod]
  29. public void ConstructorShouldNotThrowExceptionWhenHostIsEmpty()
  30. {
  31. var host = string.Empty;
  32. var eventArgs = new PortForwardEventArgs(host, 80);
  33. Assert.AreSame(host, eventArgs.OriginatorHost);
  34. }
  35. [TestMethod]
  36. public void ConstructorShouldNotThrowExceptionWhenHostIsInvalidDnsName()
  37. {
  38. const string host = "in_valid_host.";
  39. var eventArgs = new PortForwardEventArgs(host, 80);
  40. Assert.AreSame(host, eventArgs.OriginatorHost);
  41. }
  42. [TestMethod]
  43. public void ConstructorShouldThrowArgumentOutOfRangeExceptionWhenPortIsGreaterThanMaximumValue()
  44. {
  45. const int port = IPEndPoint.MaxPort + 1;
  46. try
  47. {
  48. _ = new PortForwardEventArgs(Resources.HOST, port);
  49. Assert.Fail();
  50. }
  51. catch (ArgumentOutOfRangeException ex)
  52. {
  53. Assert.IsNull(ex.InnerException);
  54. Assert.AreEqual("port", ex.ParamName);
  55. }
  56. }
  57. }
  58. }