ForwardedPortDynamicTest_Dispose_PortDisposed.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_Dispose_PortDisposed
  9. {
  10. private ForwardedPortDynamic _forwardedPort;
  11. private IList<EventArgs> _closingRegister;
  12. private IList<ExceptionEventArgs> _exceptionRegister;
  13. [TestInitialize]
  14. public void Setup()
  15. {
  16. Arrange();
  17. Act();
  18. }
  19. [TestCleanup]
  20. public void Cleanup()
  21. {
  22. if (_forwardedPort != null)
  23. {
  24. _forwardedPort.Dispose();
  25. _forwardedPort = null;
  26. }
  27. }
  28. protected void Arrange()
  29. {
  30. _closingRegister = new List<EventArgs>();
  31. _exceptionRegister = new List<ExceptionEventArgs>();
  32. _forwardedPort = new ForwardedPortDynamic("host", 22);
  33. _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);
  34. _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);
  35. _forwardedPort.Dispose();
  36. }
  37. protected void Act()
  38. {
  39. _forwardedPort.Dispose();
  40. }
  41. [TestMethod]
  42. public void ClosingShouldNotHaveFired()
  43. {
  44. Assert.AreEqual(0, _closingRegister.Count);
  45. }
  46. [TestMethod]
  47. public void ExceptionShouldNotHaveFired()
  48. {
  49. Assert.AreEqual(0, _exceptionRegister.Count);
  50. }
  51. }
  52. }