Esempio n. 1
0
        private void VerifyExceptionAfterOpen(int newWriteBufferSize, Type expectedException)
        {
            using (SerialPort com = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName))
            {
                int originalWriteBufferSize = com.WriteBufferSize;

                com.Open();
                try
                {
                    com.WriteBufferSize = newWriteBufferSize;
                    Fail("Err_561567anhbp!!! expected exception {0} and nothing was thrown", expectedException);
                }
                catch (Exception e)
                {
                    if (e.GetType() != expectedException)
                    {
                        Fail("Err_21288ajpbam!!! expected exception {0} and {1} was thrown", expectedException, e.GetType());
                    }
                    else if (originalWriteBufferSize != com.WriteBufferSize)
                    {
                        Fail("Err_454987ahbopa!!! expected WriteBufferSize={0} and actual={1}", originalWriteBufferSize, com.WriteBufferSize);
                    }
                    else if (TCSupport.SufficientHardwareRequirements(TCSupport.SerialPortRequirements.NullModem))
                    {
                        VerifyWriteBufferSize(com, originalWriteBufferSize);
                    }
                }
            }
        }
Esempio n. 2
0
    private bool VerifyExceptionAfterOpen(int newWriteBufferSize, Type expectedException)
    {
        bool       retValue = true;
        SerialPort com      = new SerialPort(TCSupport.LocalMachineSerialInfo.FirstAvailablePortName);
        int        originalWriteBufferSize = com.WriteBufferSize;

        com.Open();
        try
        {
            com.WriteBufferSize = newWriteBufferSize;
            Console.WriteLine("Err_561567anhbp!!! expected exception {0} and nothing was thrown", expectedException);
            retValue = false;
        }
        catch (Exception e)
        {
            if (e.GetType() != expectedException)
            {
                Console.WriteLine("Err_21288ajpbam!!! expected exception {0} and {1} was thrown", expectedException, e.GetType());
                retValue = false;
            }
            else if (originalWriteBufferSize != com.WriteBufferSize)
            {
                Console.WriteLine("Err_454987ahbopa!!! expected WriteBufferSize={0} and actual={1}", originalWriteBufferSize, com.WriteBufferSize);
                retValue = false;
            }
            else if (TCSupport.SufficientHardwareRequirements(TCSupport.SerialPortRequirements.NullModem) && !VerifyWriteBufferSize(com, originalWriteBufferSize))
            {
                Console.WriteLine("Err_56459847ahjpba!!! Verifying actual write after exception thrown failed");
                retValue = false;
            }
        }
        finally
        {
            if (com.IsOpen)
            {
                com.Close();
            }
        }
        return(retValue);
    }