| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 | using System;using System.Collections.Generic;using Microsoft.VisualStudio.TestTools.UnitTesting;using Renci.SshNet.Common;namespace Renci.SshNet.Tests.Classes{    [TestClass]    public class ForwardedPortDynamicTest_Start_PortDisposed    {        private ForwardedPortDynamic _forwardedPort;        private IList<EventArgs> _closingRegister;        private IList<ExceptionEventArgs> _exceptionRegister;        private ObjectDisposedException _actualException;        [TestInitialize]        public void Setup()        {            Arrange();            Act();        }        [TestCleanup]        public void Cleanup()        {            if (_forwardedPort != null)            {                _forwardedPort.Dispose();                _forwardedPort = null;            }        }        protected void Arrange()        {            _closingRegister = new List<EventArgs>();            _exceptionRegister = new List<ExceptionEventArgs>();            _forwardedPort = new ForwardedPortDynamic("host", 22);            _forwardedPort.Closing += (sender, args) => _closingRegister.Add(args);            _forwardedPort.Exception += (sender, args) => _exceptionRegister.Add(args);            _forwardedPort.Dispose();        }        protected void Act()        {            try            {                _forwardedPort.Start();                Assert.Fail();            }            catch (ObjectDisposedException ex)            {                _actualException = ex;            }        }        [TestMethod]        public void StartShouldThrowObjectDisposedException()        {            Assert.IsNotNull(_actualException);            Assert.AreEqual(_forwardedPort.GetType().FullName, _actualException.ObjectName);        }        [TestMethod]        public void ClosingShouldNotHaveFired()        {            Assert.AreEqual(0, _closingRegister.Count);        }        [TestMethod]        public void ExceptionShouldNotHaveFired()        {            Assert.AreEqual(0, _exceptionRegister.Count);        }    }}
 |