public void GetProjectionInfoIkeV2Test() { var expected = new RasIkeV2Info(0, IPAddress.Any, IPAddress.Any, 0, IPAddress.Any, IPAddress.Any, 0, RasIkeV2AuthenticationType.None, 0, new RasIkeV2Options(), RasIPSecEncryptionType.None, null, null); var mock = new Mock <IRasHelper>(); RasHelper.Instance = mock.Object; mock.Setup(o => o.GetProjectionInfoEx(It.IsAny <RasHandle>())).Returns(expected); var target = new RasConnection(); var actual = (RasIkeV2Info)target.GetProjectionInfo(RasProjectionType.IkeV2); Assert.AreSame(expected, actual); }
public void GetProjectionInfoIkeV2NullResultTest() { RasIkeV2Info expected = null; var result = 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()); var mock = new Mock <IRasHelper>(); RasHelper.Instance = mock.Object; mock.Setup(o => o.GetProjectionInfoEx(It.IsAny <RasHandle>())).Returns(result); var target = new RasConnection(); var actual = (RasIkeV2Info)target.GetProjectionInfo(RasProjectionType.IkeV2); Assert.AreEqual(expected, actual); }
public void GetProjectionInfoPppNullResultTest() { RasPppInfo expected = null; RasIkeV2Info result = 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(result); RasConnection target = new RasConnection(); RasPppInfo actual = (RasPppInfo)target.GetProjectionInfo(RasProjectionType.Ppp); Assert.AreEqual(expected, actual); }
public object GetProjectionInfoEx(RasHandle handle) { object retval = null; int size = Marshal.SizeOf(typeof(NativeMethods.RAS_PROJECTION_INFO)); IntPtr lpdwSize = new IntPtr(size); bool retry = false; do { NativeMethods.RAS_PROJECTION_INFO projectionInfo = new NativeMethods.RAS_PROJECTION_INFO(); projectionInfo.version = GetCurrentApiVersion(); IntPtr pRasProjection = IntPtr.Zero; try { pRasProjection = Marshal.AllocHGlobal(lpdwSize); Marshal.StructureToPtr(projectionInfo, pRasProjection, true); int ret = SafeNativeMethods.Instance.GetProjectionInfoEx(handle, pRasProjection, ref lpdwSize); if (ret == NativeMethods.ERROR_BUFFER_TOO_SMALL) { retry = true; } else if (ret == NativeMethods.SUCCESS) { projectionInfo = Utilities.PtrToStructure<NativeMethods.RAS_PROJECTION_INFO>(pRasProjection); // Use the object located at the end of the structure since the union will cause portability issues on 64-bit platforms. IntPtr pInfo = new IntPtr(pRasProjection.ToInt64() + size); switch (projectionInfo.type) { case NativeMethods.RASPROJECTION_INFO_TYPE.Ppp: NativeMethods.RASPPP_PROJECTION_INFO ppp = Utilities.PtrToStructure<NativeMethods.RASPPP_PROJECTION_INFO>(pInfo); ReadOnlyCollection<byte> interfaceIdentifier = null; if (ppp.interfaceIdentifier != null && ppp.interfaceIdentifier.Length > 0) { interfaceIdentifier = new ReadOnlyCollection<byte>(new List<byte>(ppp.interfaceIdentifier)); } ReadOnlyCollection<byte> serverInterfaceIdentifier = null; if (ppp.serverInterfaceIdentifier != null && ppp.serverInterfaceIdentifier.Length > 0) { serverInterfaceIdentifier = new ReadOnlyCollection<byte>(new List<byte>(ppp.serverInterfaceIdentifier)); } retval = new RasPppInfo( ppp.ipv4NegotiationError, new IPAddress(ppp.ipv4Address.addr), new IPAddress(ppp.ipv4ServerAddress.addr), ppp.ipv4Options, ppp.ipv4ServerOptions, ppp.ipv6NegotiationError, interfaceIdentifier, serverInterfaceIdentifier, ppp.bundled, ppp.multilink, ppp.authenticationProtocol, ppp.authenticationData, ppp.serverAuthenticationProtocol, ppp.serverAuthenticationData, ppp.eapTypeId, ppp.serverEapTypeId, new RasLcpOptions(ppp.lcpOptions), new RasLcpOptions(ppp.serverLcpOptions), ppp.ccpCompressionAlgorithm, ppp.serverCcpCompressionAlgorithm, new RasCompressionOptions(ppp.ccpOptions), new RasCompressionOptions(ppp.serverCcpOptions)); break; case NativeMethods.RASPROJECTION_INFO_TYPE.IkeV2: NativeMethods.RASIKEV2_PROJECTION_INFO ikev2 = Utilities.PtrToStructure<NativeMethods.RASIKEV2_PROJECTION_INFO>(pInfo); RasIkeV2Options ikev2Options = new RasIkeV2Options(); Utilities.SetRasIkeV2Options(ikev2Options, ikev2.options); retval = new RasIkeV2Info( ikev2.ipv4NegotiationError, new IPAddress(ikev2.ipv4Address.addr), new IPAddress(ikev2.ipv4ServerAddress.addr), ikev2.ipv6NegotiationError, new IPAddress(ikev2.ipv6Address.addr), new IPAddress(ikev2.ipv6ServerAddress.addr), ikev2.prefixLength, ikev2.authenticationProtocol, ikev2.eapTypeId, ikev2Options, ikev2.encryptionMethod, Utilities.CreateIPv4AddressCollection(ikev2.ipv4ServerAddresses, ikev2.numIPv4ServerAddresses), Utilities.CreateIPv6AddressCollection(ikev2.ipv6ServerAddresses, ikev2.numIPv6ServerAddresses)); break; } retry = false; } else { ThrowHelper.ThrowRasException(ret); } } catch (EntryPointNotFoundException) { ThrowHelper.ThrowNotSupportedException(Resources.Exception_NotSupportedOnPlatform); } finally { if (pRasProjection != IntPtr.Zero) { Marshal.FreeHGlobal(pRasProjection); } } } while (retry); return retval; }