Esempio n. 1
0
        internal void SetConnected(RasConnection connection)
        {
            if (connection == null) return;

            _rasConnection = connection;
            Status = RasConnectionState.Connected;
        }
Esempio n. 2
0
        public void HandleTest()
        {
            RasHandle expected = new RasHandle(new IntPtr(1), false);

            RasConnection target = new RasConnection();
            target.Handle = expected;

            RasHandle actual = target.Handle;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 3
0
        public static RasConnection GetActiveConnectionById(Guid entryId)
        {
            RasConnection retval = null;

            foreach (RasConnection connection in GetActiveConnections())
            {
                if (connection.EntryId == entryId)
                {
                    retval = connection;
                    break;
                }
            }

            return(retval);
        }
Esempio n. 4
0
        public static RasConnection GetActiveConnectionByHandle(RasHandle handle)
        {
            if (handle == null)
            {
                ThrowHelper.ThrowArgumentNullException("handle");
            }

            RasConnection retval = null;

            foreach (RasConnection connection in GetActiveConnections())
            {
                if (connection.Handle == handle)
                {
                    retval = connection;
                    break;
                }
            }

            return(retval);
        }
Esempio n. 5
0
        public void GetConnectionStatusTest()
        {
            RasConnectionStatus expected = new RasConnectionStatus()
            {
                ConnectionState = RasConnectionState.Connected
            };

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetConnectionStatus(It.IsAny<RasHandle>())).Returns(expected);

            RasConnection target = new RasConnection();
            RasConnectionStatus actual = target.GetConnectionStatus();

            Assert.AreSame(expected, actual);
        }
Esempio n. 6
0
        public void GetProjectionInfoIkeV2Test()
        {
            RasIkeV2Info expected = new RasIkeV2Info(0, IPAddress.Any, IPAddress.Any, 0, IPAddress.Any, IPAddress.Any, 0, RasIkeV2AuthenticationType.None, 0, new RasIkeV2Options(), RasIPSecEncryptionType.None, null, null);

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetProjectionInfoEx(It.IsAny<RasHandle>())).Returns(expected);

            RasConnection target = new RasConnection();
            RasIkeV2Info actual = (RasIkeV2Info)target.GetProjectionInfo(RasProjectionType.IkeV2);

            Assert.AreSame(expected, actual);
        }
Esempio n. 7
0
        public void GetSubEntryHandleTest()
        {
            RasHandle expected = new RasHandle(new IntPtr(1), true);

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetSubEntryHandle(It.IsAny<RasHandle>(), It.IsAny<int>())).Returns(expected);

            RasConnection target = new RasConnection();
            RasHandle actual = target.GetSubEntryHandle(1);

            Assert.AreSame(expected, actual);
        }
Esempio n. 8
0
        public void EntryNameTest()
        {
            string expected = "Entry Name";

            RasConnection target = new RasConnection();
            target.EntryName = expected;

            string actual = target.EntryName;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 9
0
        public void GetProjectionInfoNullApiResultTest()
        {
            RasPppInfo expected = null;

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetProjectionInfoEx(It.IsAny<RasHandle>())).Returns(expected);

            RasConnection target = new RasConnection();
            RasPppInfo actual = (RasPppInfo)target.GetProjectionInfo(RasProjectionType.Ppp);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 10
0
        public void GetLinkStatisticsTest()
        {
            RasLinkStatistics expected = new RasLinkStatistics(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TimeSpan.MinValue);

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetLinkStatistics(It.IsAny<RasHandle>(), It.IsAny<int>())).Returns(expected);

            RasConnection target = new RasConnection();
            RasLinkStatistics actual = target.GetLinkStatistics();

            Assert.AreSame(expected, actual);
        }
Esempio n. 11
0
        public void GetProjectionInfoCcpTest()
        {
            RasCcpInfo expected = new RasCcpInfo(
                0, 
                RasCompressionType.None, 
                new RasCompressionOptions(NativeMethods.RASCCPO.None),
                RasCompressionType.None, 
                new RasCompressionOptions(NativeMethods.RASCCPO.None));

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetProjectionInfo(It.IsAny<RasHandle>(), NativeMethods.RASPROJECTION.Ccp)).Returns(expected);

            RasConnection target = new RasConnection();
            RasCcpInfo actual = (RasCcpInfo)target.GetProjectionInfo(RasProjectionType.Ccp);

            Assert.AreSame(expected, actual);
        }
Esempio n. 12
0
        public void SubEntryIdTest()
        {
            int expected = 2;

            RasConnection target = new RasConnection();
            target.SubEntryId = expected;

            int actual = target.SubEntryId;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 13
0
        public void ConnectionOptionsTest()
        {
            RasConnectionOptions expected = new RasConnectionOptions()
            {
                AllUsers = true
            };

            RasConnection target = new RasConnection();
            target.ConnectionOptions = expected;

            RasConnectionOptions actual = target.ConnectionOptions;

            Assert.AreSame(expected, actual);
        }
Esempio n. 14
0
        public void UpdateConnectionTest()
        {
            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.UpdateConnection(It.IsAny<RasHandle>(), It.IsAny<int>(), It.IsAny<IPAddress>(), It.IsAny<IPAddress>())).Verifiable();

            RasConnection target = new RasConnection();
            target.UpdateConnection(0, IPAddress.Any, IPAddress.Any);

            mock.Verify();
        }
Esempio n. 15
0
        public void PhoneBookPathTest()
        {
            string expected = "C:\\Test.pbk";

            RasConnection target = new RasConnection();
            target.PhoneBookPath = expected;

            string actual = target.PhoneBookPath;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 16
0
        public void DeviceTest()
        {
            RasDevice expected = RasDevice.Create("PPTP", RasDeviceType.Vpn);

            RasConnection target = new RasConnection();
            target.Device = expected;

            RasDevice actual = target.Device;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 17
0
 public void HangUpInvalidPollingIntervalTest()
 {
     RasConnection target = new RasConnection();
     target.HangUp(-1);
 }
Esempio n. 18
0
        public void HangUpTest()
        {
            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.HangUp(It.IsAny<RasHandle>(), It.IsAny<int>())).Verifiable();

            RasConnection target = new RasConnection();
            target.HangUp();

            mock.Verify();
        }
Esempio n. 19
0
        public void ClearLinkStatisticsTest()
        {
            bool expected = true;

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.ClearLinkStatistics(It.IsAny<RasHandle>(), It.IsAny<int>())).Returns(expected);

            RasConnection target = new RasConnection();
            bool actual = target.ClearLinkStatistics();

            Assert.AreEqual(expected, actual);
        }
Esempio n. 20
0
        public void ConnectionOptionsNullTest()
        {
            RasConnection target = new RasConnection();
            target.ConnectionOptions = null;

            RasConnectionOptions actual = target.ConnectionOptions;

            Assert.IsNotNull(actual);
        }
Esempio n. 21
0
 public void GetSubEntryHandleArgumentExceptionForZeroTest()
 {
     RasConnection target = new RasConnection();
     target.GetSubEntryHandle(0);
 }
Esempio n. 22
0
        public void SessionIdTest()
        {
            Luid expected = Luid.NewLuid();

            RasConnection target = new RasConnection();
            target.SessionId = expected;

            Luid actual = target.SessionId;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 23
0
        public void GetNapStatusTest()
        {
            RasNapStatus expected = new RasNapStatus(RasIsolationState.Unknown, DateTime.MinValue);

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetNapStatus(It.IsAny<RasHandle>())).Returns(expected);

            RasConnection target = new RasConnection();
            RasNapStatus actual = target.GetNapStatus();

            Assert.AreSame(expected, actual);
        }
Esempio n. 24
0
        public void CorrelationIdTest()
        {
            Guid expected = Guid.NewGuid();

            RasConnection target = new RasConnection();
            target.CorrelationId = expected;

            Guid actual = target.CorrelationId;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 25
0
        public void GetProjectionInfoLcpTest()
        {
            RasLcpInfo expected = new RasLcpInfo(false, 0, RasLcpAuthenticationType.None, RasLcpAuthenticationDataType.None, 0, RasLcpAuthenticationType.None, RasLcpAuthenticationDataType.None, 0, false, 0, 0, null, new RasLcpOptions(), new RasLcpOptions());

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetProjectionInfo(It.IsAny<RasHandle>(), NativeMethods.RASPROJECTION.Lcp)).Returns(expected);

            RasConnection target = new RasConnection();
            RasLcpInfo actual = (RasLcpInfo)target.GetProjectionInfo(RasProjectionType.Lcp);

            Assert.AreSame(expected, actual);
        }
Esempio n. 26
0
 public void GetIpAddress(out string ipAddress, out RasConnection oldConn)
 {
     ipAddress = "";
     var conns = RasConnection.GetActiveConnections();
     oldConn = conns.FirstOrDefault(conn => conn.Device.DeviceType.ToString().ToLower() == "pppoe");
     if (oldConn != null)
     {
         try
         {
             RasIPInfo ipAddresses = (RasIPInfo) oldConn.GetProjectionInfo(RasProjectionType.IP);
             ipAddress = ipAddresses.IPAddress.ToString();
         }
         catch (Exception ex)
         {
             LogServer.WriteLog(ex, "changeIp");
         }
     }
 }
Esempio n. 27
0
        public void GetProjectionInfoSlipTest()
        {
            RasSlipInfo expected = new RasSlipInfo(0, IPAddress.Any);

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetProjectionInfo(It.IsAny<RasHandle>(), NativeMethods.RASPROJECTION.Slip)).Returns(expected);

            RasConnection target = new RasConnection();
            RasSlipInfo actual = (RasSlipInfo)target.GetProjectionInfo(RasProjectionType.Slip);

            Assert.AreSame(expected, actual);
        }
Esempio n. 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DotRas.RasConnectionEventArgs"/> class.
 /// </summary>
 /// <param name="connection">The <see cref="DotRas.RasConnection"/> that caused the event.</param>
 public RasConnectionEventArgs(RasConnection connection)
 {
     this.Connection = connection;
 }
Esempio n. 29
0
        public void GetProjectionInfoPppTest()
        {
            RasPppInfo expected = new RasPppInfo(0, IPAddress.Any, IPAddress.Any, new RasIPOptions(NativeMethods.RASIPO.None), new RasIPOptions(NativeMethods.RASIPO.None), 0, null, null, false, false, RasLcpAuthenticationType.None, RasLcpAuthenticationDataType.None, RasLcpAuthenticationType.None, RasLcpAuthenticationDataType.None, 0, 0, new RasLcpOptions(), new RasLcpOptions(), RasCompressionType.None, RasCompressionType.None, new RasCompressionOptions(), new RasCompressionOptions());

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetProjectionInfoEx(It.IsAny<RasHandle>())).Returns(expected);

            RasConnection target = new RasConnection();
            RasPppInfo actual = (RasPppInfo)target.GetProjectionInfo(RasProjectionType.Ppp);

            Assert.AreSame(expected, actual);
        }
Esempio n. 30
0
        public void GetActiveConnectionByNameRelativePathTest()
        {
            string entryName = "Test";
            string phoneBookPath = ".\\Test.pbk";

            RasConnection expected = new RasConnection()
            {
                EntryName = entryName,
                PhoneBookPath = System.IO.Path.GetFullPath(phoneBookPath)
            };

            ReadOnlyCollection<RasConnection> connections = new ReadOnlyCollection<RasConnection>(
                new RasConnection[] { expected });

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetActiveConnections()).Returns(connections);

            RasConnection actual = RasConnection.GetActiveConnectionByName(entryName, phoneBookPath);

            Assert.AreSame(expected, actual);
        }
Esempio n. 31
0
        public void GetActiveConnectionByHandleTest()
        {
            RasHandle handle = new RasHandle(new IntPtr(1), false);

            RasConnection expected = new RasConnection()
            {
                Handle = handle
            };

            ReadOnlyCollection<RasConnection> connections = new ReadOnlyCollection<RasConnection>(
                new RasConnection[] { expected });

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetActiveConnections()).Returns(connections);

            RasConnection actual = RasConnection.GetActiveConnectionByHandle(handle);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 32
0
 public void GetSubEntryHandleArgumentExceptionForNegativeTest()
 {
     RasConnection target = new RasConnection();
     target.GetSubEntryHandle(-1);
 }
Esempio n. 33
0
        private void ConnectionStateChanged(object obj, bool timedOut)
        {
            lock (this.lockObject)
            {
                if (this.EnableRaisingEvents)
                {
                    try
                    {
                        // Retrieve the active connections to compare against the last state that was checked.
                        ReadOnlyCollection <RasConnection> connections = RasConnection.GetActiveConnections();
                        RasConnection connection = null;

                        switch (((RasConnectionWatcherStateObject)obj).ChangeType)
                        {
                        case NativeMethods.RASCN.Connection:
                            connection = FindEntry(connections, this._lastState);
                            if (connection != null)
                            {
                                this.OnConnected(new RasConnectionEventArgs(connection));
                            }

                            this._lastState = connections;

                            break;

                        case NativeMethods.RASCN.Disconnection:
                            // The handle has not been set or it's invalid, the item that has disconnected will need to be
                            // determined.
                            connection = FindEntry(this._lastState, connections);
                            if (connection != null)
                            {
                                this.OnDisconnected(new RasConnectionEventArgs(connection));
                            }

                            if (this.Handle != null)
                            {
                                // The handle that was being monitored has been disconnected.
                                this.Handle = null;
                            }

                            this._lastState = connections;

                            break;

                        case NativeMethods.RASCN.BandwidthAdded:
                            if (this.Handle != null && !this.Handle.IsInvalid)
                            {
                                this.OnBandwidthAdded(EventArgs.Empty);
                            }

                            break;

                        case NativeMethods.RASCN.BandwidthRemoved:
                            if (this.Handle != null && !this.Handle.IsInvalid)
                            {
                                this.OnBandwidthRemoved(EventArgs.Empty);
                            }

                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        this.OnError(new System.IO.ErrorEventArgs(ex));
                    }
                }
            }
        }
Esempio n. 34
0
        public void GetActiveConnectionByIdTest()
        {
            Guid entryId = Guid.NewGuid();

            RasConnection expected = new RasConnection()
            {
                EntryId = entryId
            };

            ReadOnlyCollection<RasConnection> connections = new ReadOnlyCollection<RasConnection>(
                new RasConnection[] { expected });

            Mock<IRasHelper> mock = new Mock<IRasHelper>();
            RasHelper.Instance = mock.Object;

            mock.Setup(o => o.GetActiveConnections()).Returns(connections);

            RasConnection actual = RasConnection.GetActiveConnectionById(entryId);

            Assert.AreSame(expected, actual);
        }