Example #1
0
        public void OpenDevices01()
        {
            DosDevices dosDevices       = new DosDevices();
            Regex      comPortNameRegex = new Regex(@"com\d{1,3}", RegexOptions.IgnoreCase);

            foreach (KeyValuePair <string, string> keyValuePair in dosDevices)
            {
                if (!string.IsNullOrEmpty(keyValuePair.Key) && !comPortNameRegex.IsMatch(keyValuePair.Key))
                {
                    using (SerialPort com1 = new SerialPort(keyValuePair.Key))
                    {
                        Debug.WriteLine($"Checking exception thrown with Key {keyValuePair.Key}");
                        Assert.ThrowsAny <Exception>(() => com1.Open());
                    }
                }

                if (!string.IsNullOrEmpty(keyValuePair.Value) && !comPortNameRegex.IsMatch(keyValuePair.Key))
                {
                    using (SerialPort com1 = new SerialPort(keyValuePair.Value))
                    {
                        Debug.WriteLine($"Checking exception thrown with Value {keyValuePair.Value}");
                        Assert.ThrowsAny <Exception>(() => com1.Open());
                    }
                }
            }
        }
Example #2
0
 public PortName_Property()
 {
     _dosDevices = new DosDevices();
 }