public void ConvertFromPPPoETest()
        {
            RasDeviceType expected = RasDeviceType.PPPoE;

            RasDeviceTypeConverter target = new RasDeviceTypeConverter();
            RasDeviceType          actual = (RasDeviceType)target.ConvertFromString(NativeMethods.RASDT_PPPoE);

            Assert.AreEqual <RasDeviceType>(expected, actual);
        }
예제 #2
0
        /// <summary>
        /// Creates a new device. WARNING: This method does not guarantee the hardware will be installed.
        /// </summary>
        /// <param name="name">The name of the device.</param>
        /// <param name="deviceType">The <see cref="DotRas.RasDeviceType"/> indicating the type of device.</param>
        /// <remarks>
        /// This method essentially creates hardware on machines that may not exist and is exposed due to problems when hardware is installed and not recognized immediately by the remote access service. Using this method does not guarantee the hardware will be installed and may cause the machine to crash when the entry is dialed.
        /// </remarks>
        /// <returns>A new <see cref="DotRas.RasDevice"/> object.</returns>
        /// <exception cref="System.ArgumentException"><paramref name="deviceType"/> is an empty string or null reference (<b>Nothing</b> in Visual Basic).</exception>
        /// <exception cref="System.ArgumentNullException"><paramref name="name"/> is a null reference (<b>Nothing</b> in Visual Basic).</exception>
        public static RasDevice Create(string name, RasDeviceType deviceType)
        {
            if (name == null)
            {
                ThrowHelper.ThrowArgumentNullException("name");
            }

            return(new RasDevice(name, deviceType));
        }
예제 #3
0
        public void GetDeviceByNameTest()
        {
            string        name       = RasDeviceTest.InvalidDeviceName;
            RasDeviceType deviceType = RasDeviceType.Vpn;

            RasDevice target = RasDevice.GetDeviceByName(name, deviceType);

            Assert.IsNotNull(target);
        }
        public void ConvertFromFrameRelayTest()
        {
            RasDeviceType expected = RasDeviceType.FrameRelay;

            RasDeviceTypeConverter target = new RasDeviceTypeConverter();
            RasDeviceType          actual = (RasDeviceType)target.ConvertFromString(NativeMethods.RASDT_FrameRelay);

            Assert.AreEqual <RasDeviceType>(expected, actual);
        }
예제 #5
0
        public void CreateDeviceTest()
        {
            string        name       = "Test Device";
            RasDeviceType deviceType = RasDeviceType.Modem;

            RasDevice target = RasDevice.Create(name, deviceType);

            Assert.AreEqual(name, target.Name);
            Assert.AreEqual <RasDeviceType>(deviceType, target.DeviceType);
        }
예제 #6
0
        public void RasDeviceConstructorTest()
        {
            string        name       = string.Empty;
            RasDeviceType deviceType = RasDeviceType.Vpn;

            RasDevice_Accessor target = new RasDevice_Accessor(name, deviceType);

            Assert.AreEqual(name, target.Name);
            Assert.AreEqual(deviceType, target.DeviceType);
        }
예제 #7
0
        /// <summary>
        /// Converts the given value object to the specified type, using the arguments.
        /// </summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that provides a format context.</param>
        /// <param name="culture">The <see cref="CultureInfo"/> to use as the current culture.</param>
        /// <param name="value">The object to convert.</param>
        /// <param name="destinationType">The type to convert the <paramref name="value"/> parameter to.</param>
        /// <returns>An object that represents the converted value.</returns>
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                RasDeviceType deviceType = (RasDeviceType)value;

                switch (deviceType)
                {
                case RasDeviceType.Modem:
                    return(NativeMethods.RASDT_Modem);

                case RasDeviceType.Isdn:
                    return(NativeMethods.RASDT_Isdn);

                case RasDeviceType.X25:
                    return(NativeMethods.RASDT_X25);

                case RasDeviceType.Vpn:
                    return(NativeMethods.RASDT_Vpn);

                case RasDeviceType.Pad:
                    return(NativeMethods.RASDT_Pad);

                case RasDeviceType.Generic:
                    return(NativeMethods.RASDT_Generic);

                case RasDeviceType.Serial:
                    return(NativeMethods.RASDT_Serial);

                case RasDeviceType.FrameRelay:
                    return(NativeMethods.RASDT_FrameRelay);

                case RasDeviceType.Atm:
                    return(NativeMethods.RASDT_Atm);

                case RasDeviceType.Sonet:
                    return(NativeMethods.RASDT_Sonet);

                case RasDeviceType.SW56:
                    return(NativeMethods.RASDT_SW56);

                case RasDeviceType.Irda:
                    return(NativeMethods.RASDT_Irda);

                case RasDeviceType.Parallel:
                    return(NativeMethods.RASDT_Parallel);

                case RasDeviceType.PPPoE:
                    return(NativeMethods.RASDT_PPPoE);
                }
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
예제 #8
0
        public void DeviceTypeTest()
        {
            string        name     = "Test Device";
            RasDeviceType expected = RasDeviceType.Generic;

            RasDevice target = RasDevice.Create(name, expected);

            RasDeviceType actual;

            actual = target.DeviceType;

            Assert.AreEqual(expected, actual);
        }
예제 #9
0
        public void GetDeviceByNameCaseSensitiveTest()
        {
            string        name       = RasDeviceTest.ValidDeviceName;
            RasDeviceType deviceType = RasDeviceType.Vpn;

            RasDevice expected = RasDevice.Create(name, deviceType);
            RasDevice actual   = RasDevice.GetDeviceByName(name, deviceType, true);

            RasDeviceComparer comparer = new RasDeviceComparer();
            bool target = comparer.Compare(expected, actual) == 0;

            Assert.IsTrue(target);
        }
예제 #10
0
        public static ReadOnlyCollection <RasDevice> GetDevicesByType(RasDeviceType deviceType)
        {
            Collection <RasDevice> tempCollection = new Collection <RasDevice>();

            foreach (RasDevice device in RasDevice.GetDevices())
            {
                if (device.DeviceType == deviceType)
                {
                    tempCollection.Add(device);
                }
            }

            return(new ReadOnlyCollection <RasDevice>(tempCollection));
        }
예제 #11
0
        public void GetDeviceByName1TestWithExactMatchOnly()
        {
            string        name           = RasDeviceTest.ValidDeviceName;
            RasDeviceType deviceType     = RasDeviceType.Vpn;
            bool          exactMatchOnly = true;

            RasDevice expected = RasDevice.Create(name, deviceType);

            RasDevice actual;

            actual = RasDevice.GetDeviceByName(name, deviceType, exactMatchOnly);

            RasDeviceComparer comparer = new RasDeviceComparer();
            bool target = comparer.Compare(expected, actual) == 0;

            Assert.IsTrue(target);
        }
예제 #12
0
        public void GetDevicesByTypeTest()
        {
            RasDeviceType deviceType = RasDeviceType.Vpn;

            Collection <RasDevice> tempDevices = new Collection <RasDevice>();

            foreach (RasDevice device in RasDevice.GetDevices())
            {
                if (device.DeviceType == deviceType)
                {
                    tempDevices.Add(device);
                }
            }

            ReadOnlyCollection <RasDevice> expected = new ReadOnlyCollection <RasDevice>(tempDevices);
            ReadOnlyCollection <RasDevice> actual   = RasDevice.GetDevicesByType(deviceType);

            CollectionAssert.AreEqual(expected, actual, new RasDeviceComparer());
        }
예제 #13
0
        public static RasDevice GetDeviceByName(string name, RasDeviceType deviceType, bool exactMatchOnly)
        {
            if (name == null)
            {
                ThrowHelper.ThrowArgumentNullException("name");
            }

            RasDevice retval = null;

            foreach (RasDevice device in RasDevice.GetDevices())
            {
                if (device.DeviceType == deviceType && ((!exactMatchOnly && device.Name.ToLower(CultureInfo.CurrentCulture).Contains(name.ToLower(CultureInfo.CurrentCulture))) || (exactMatchOnly && string.Compare(name, device.Name, false, CultureInfo.CurrentCulture) == 0)))
                {
                    retval = device;
                    break;
                }
            }

            return(retval);
        }
예제 #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DotRas.RasDevice"/> class.
 /// </summary>
 /// <param name="name">The name of the device.</param>
 /// <param name="deviceType">The type of the device.</param>
 private RasDevice(string name, RasDeviceType deviceType)
 {
     Name       = name;
     DeviceType = deviceType;
 }
예제 #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DotRas.RasDevice"/> class.
 /// </summary>
 /// <param name="name">The name of the device.</param>
 /// <param name="deviceType">The type of the device.</param>
 private RasDevice(string name, RasDeviceType deviceType)
 {
     this.Name       = name;
     this.DeviceType = deviceType;
 }
예제 #16
0
 public static RasDevice GetDeviceByName(string name, RasDeviceType deviceType)
 {
     return(RasDevice.GetDeviceByName(name, deviceType, false));
 }