public void SuspendResumPortOpenClose()
        {
            SuspendResumePort port = new SuspendResumePort(
                delegate { return(new SerialPort()); },
                delegate(Stream stream) { });

            port.Open();
            port.Close();
            Assert.AreEqual(1, port.Opened, "port.Open");
        }
        public void SuspendResumPortOpenSuspendResumeClose()
        {
            SuspendResumePort port = new SuspendResumePort(
                delegate { return(new SerialPort()); },
                delegate(Stream stream) { });

            port.Open();
            port.Suspend();
            port.Resume(TimeSpan.FromSeconds(0.01));
            Thread.Sleep(500);
            port.Close();
            Assert.AreEqual(2, port.Opened, "port.Open");
        }
        public void SuspendResumPortOpenRetryClose()
        {
            int invocations = 0;

            SuspendResumePort port = new SuspendResumePort(
                delegate
            {
                invocations++;
                if (invocations == 2)
                {
                    return(new SerialPort());
                }
                return(null);
            },
                delegate(Stream stream) { });

            port.Open();

            Thread.Sleep(3000);

            port.Close();
            Assert.AreEqual(1, port.Opened, "port.Open");
        }