ForwardedPortDynamicTest_Start_PortDisposed.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using Renci.SshNet.Common;
  5. namespace Renci.SshNet.Tests.Classes
  6. {
  7. [TestClass]
  8. public class ForwardedPortDynamicTest_Start_PortDisposed
  9. {
  10. private ForwardedPortDynamic _forwardedPort;
  11. private IList<EventArgs> _closingRegister;
  12. private IList<ExceptionEventArgs> _exceptionRegister;
  13. private ObjectDisposedException _actualException;
  14. [TestInitialize]
  15. public void Setup()
  16. {
  17. Arrange();
  18. Act();
  19. }
  20. [TestCleanup]
  21. public void Cleanup()
  22. {
  23. if (_forwardedPort != null)
  24. {
  25. _forwardedPort.Dispose();
  26. _forwardedPort = null;
  27. }
  28. }
  29. protected void Arrange()
  30. {
  31. _closingRegister = new List<EventArgs>();
  32. _exceptionRegister = new List<ExceptionEventArgs>();
  33. _forwardedPort = new ForwardedPortDynamic("host", 22);
  34. _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
  35. _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
  36. _forwardedPort.Dispose();
  37. }
  38. protected void Act()
  39. {
  40. try
  41. {
  42. _forwardedPort.Start();
  43. Assert.Fail();
  44. }
  45. catch (ObjectDisposedException ex)
  46. {
  47. _actualException = ex;
  48. }
  49. }
  50. [TestMethod]
  51. public void StartShouldThrowObjectDisposedException()
  52. {
  53. Assert.IsNotNull(_actualException);
  54. Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName);
  55. }
  56. [TestMethod]
  57. public void ClosingShouldNotHaveFired()
  58. {
  59. Assert.AreEqual(0, _closingRegister.Count);
  60. }
  61. [TestMethod]
  62. public void ExceptionShouldNotHaveFired()
  63. {
  64. Assert.AreEqual(0, _exceptionRegister.Count);
  65. }
  66. }
  67. }