コード例 #1
0
        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
ファイル: RasDevice.cs プロジェクト: mogikanin/DotRas
        /// <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
ファイル: RasDeviceTest.cs プロジェクト: schifflee/Terminals
        public void GetDeviceByNameTest()
        {
            string        name       = RasDeviceTest.InvalidDeviceName;
            RasDeviceType deviceType = RasDeviceType.Vpn;

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

            Assert.IsNotNull(target);
        }
コード例 #4
0
        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
ファイル: RasDeviceTest.cs プロジェクト: schifflee/Terminals
        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
ファイル: RasDeviceTest.cs プロジェクト: schifflee/Terminals
        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
ファイル: RasDeviceTest.cs プロジェクト: schifflee/Terminals
        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
ファイル: RasDeviceTest.cs プロジェクト: schifflee/Terminals
        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
ファイル: RasDevice.cs プロジェクト: mogikanin/DotRas
 /// <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));
 }