ForwardedPortLocalTest_Stop_PortDisposed.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 ForwardedPortLocalTest_Stop_PortDisposed
  9. {
  10. private ForwardedPortLocal _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 ForwardedPortLocal("boundHost", "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.Stop();
  40. }
  41. [TestMethod]
  42. public void IsStartedShouldReturnFalse()
  43. {
  44. Assert.IsFalse(_forwardedPort.IsStarted);
  45. }
  46. [TestMethod]
  47. public void ClosingShouldNotHaveFired()
  48. {
  49. Assert.AreEqual(0, _closingRegister.Count);
  50. }
  51. [TestMethod]
  52. public void ExceptionShouldNotHaveFired()
  53. {
  54. Assert.AreEqual(0, _exceptionRegister.Count);
  55. }
  56. }
  57. }