示例#1
0
        public void RasConnectionNotificationAsExpected()
        {
            var hRasConn = new IntPtr(1);
            var hEvent   = new Mock <ISafeHandleWrapper>();
            var dwFlags  = RASCN.Connection;

            api.Setup(o => o.RasConnectionNotification(hRasConn, hEvent.Object, dwFlags)).Returns(SUCCESS);
            eventLoggingPolicy.Setup(o => o.LogEvent(It.IsAny <EventLevel>(), It.IsAny <PInvokeInt32CallCompletedTraceEvent>())).Callback(new LogEventCallback(
                                                                                                                                              (level, o1) =>
            {
                Assert.AreEqual(EventLevel.Verbose, level);

                var eventData = (PInvokeInt32CallCompletedTraceEvent)o1;
                Assert.AreEqual(hRasConn, (IntPtr)eventData.Args[nameof(hRasConn)]);
                Assert.AreEqual(hEvent.Object, (ISafeHandleWrapper)eventData.Args[nameof(hEvent)]);
                Assert.AreEqual(dwFlags, (RASCN)eventData.Args[nameof(dwFlags)]);
                Assert.True(eventData.Duration > TimeSpan.Zero);
                Assert.AreEqual(SUCCESS, eventData.Result);
            })).Verifiable();

            var target = new RasApi32LoggingAdvice(api.Object, eventLoggingPolicy.Object);
            var result = target.RasConnectionNotification(hRasConn, hEvent.Object, dwFlags);

            eventLoggingPolicy.Verify();
            Assert.AreEqual(SUCCESS, result);
        }
示例#2
0
        public void RasEnumConnectionsAsExpected()
        {
            var lpCb          = 0;
            var lpConnections = 1;
            var lpRasConn     = new RASCONN[0];

            api.Setup(o => o.RasEnumConnections(lpRasConn, ref It.Ref <int> .IsAny, ref It.Ref <int> .IsAny)).Returns(new RasEnumConnectionsCallback(
                                                                                                                          (RASCONN[] o1, ref int o2, ref int o3) =>
            {
                o2 = 1;
                o3 = 2;
                return(SUCCESS);
            }));

            eventLoggingPolicy.Setup(o => o.LogEvent(It.IsAny <EventLevel>(), It.IsAny <PInvokeInt32CallCompletedTraceEvent>())).Callback(new LogEventCallback(
                                                                                                                                              (level, o1) =>
            {
                Assert.AreEqual(EventLevel.Verbose, level);

                var eventData = (PInvokeInt32CallCompletedTraceEvent)o1;
                Assert.True(eventData.Args.ContainsKey(nameof(lpRasConn)));
                Assert.AreEqual(0, (int)eventData.Args[nameof(lpCb)]);
                Assert.AreEqual(1, (int)eventData.Args[nameof(lpConnections)]);
                Assert.AreEqual(1, (int)eventData.OutArgs[nameof(lpCb)]);
                Assert.AreEqual(2, (int)eventData.OutArgs[nameof(lpConnections)]);
                Assert.True(eventData.Duration > TimeSpan.Zero);
                Assert.AreEqual(SUCCESS, eventData.Result);
            })).Verifiable();

            var target = new RasApi32LoggingAdvice(api.Object, eventLoggingPolicy.Object);
            var result = target.RasEnumConnections(lpRasConn, ref lpCb, ref lpConnections);

            eventLoggingPolicy.Verify();
            Assert.AreEqual(SUCCESS, result);
        }
示例#3
0
        public void RasValidateEntryNameAsExpected()
        {
            var lpszPhoneBook = @"C:\Users\My.pbk";
            var lpszEntryName = "My Entry";

            api.Setup(o => o.RasValidateEntryName(lpszPhoneBook, lpszEntryName)).Returns(SUCCESS);

            eventLoggingPolicy.Setup(o => o.LogEvent(It.IsAny <EventLevel>(), It.IsAny <PInvokeInt32CallCompletedTraceEvent>())).Callback(new LogEventCallback(
                                                                                                                                              (level, o1) =>
            {
                Assert.AreEqual(EventLevel.Verbose, level);

                var eventData = (PInvokeInt32CallCompletedTraceEvent)o1;
                Assert.True(eventData.Args.ContainsKey(nameof(lpszPhoneBook)));
                Assert.True(eventData.Args.ContainsKey(nameof(lpszEntryName)));
                Assert.True(eventData.Duration > TimeSpan.Zero);
                Assert.AreEqual(SUCCESS, eventData.Result);
            })).Verifiable();

            var target = new RasApi32LoggingAdvice(api.Object, eventLoggingPolicy.Object);
            var result = target.RasValidateEntryName(lpszPhoneBook, lpszEntryName);

            eventLoggingPolicy.Verify();
            Assert.AreEqual(SUCCESS, result);
        }
示例#4
0
        public void RasGetErrorStringAsExpected()
        {
            var uErrorValue     = 1;
            var lpszErrorString = new StringBuilder();
            var cBufSize        = 1;

            api.Setup(o => o.RasGetErrorString(uErrorValue, lpszErrorString, cBufSize)).Returns(SUCCESS);

            eventLoggingPolicy.Setup(o => o.LogEvent(It.IsAny <EventLevel>(), It.IsAny <PInvokeInt32CallCompletedTraceEvent>())).Callback(new LogEventCallback(
                                                                                                                                              (level, o1) =>
            {
                Assert.AreEqual(EventLevel.Verbose, level);

                var eventData = (PInvokeInt32CallCompletedTraceEvent)o1;
                Assert.True(eventData.Args.ContainsKey(nameof(uErrorValue)));
                Assert.True(eventData.Args.ContainsKey(nameof(lpszErrorString)));
                Assert.True(eventData.Args.ContainsKey(nameof(cBufSize)));
                Assert.True(eventData.Duration > TimeSpan.Zero);
                Assert.AreEqual(SUCCESS, eventData.Result);
            })).Verifiable();

            var target = new RasApi32LoggingAdvice(api.Object, eventLoggingPolicy.Object);
            var result = target.RasGetErrorString(uErrorValue, lpszErrorString, cBufSize);

            eventLoggingPolicy.Verify();
            Assert.AreEqual(SUCCESS, result);
        }
示例#5
0
        public void RasGetEntryDialParamsAsExpected()
        {
            var           lpszPhoneBook = @"C:\Users\My.pbk";
            RASDIALPARAMS lpDialParams  = new RASDIALPARAMS();
            bool          lpfPassword;

            api.Setup(o => o.RasGetEntryDialParams(lpszPhoneBook, ref It.Ref <RASDIALPARAMS> .IsAny, out It.Ref <bool> .IsAny)).Returns(new RasGetEntryDialParamsCallback(
                                                                                                                                            (string o1, ref RASDIALPARAMS o2, out bool o3) =>
            {
                o3 = true;
                return(SUCCESS);
            }));

            eventLoggingPolicy.Setup(o => o.LogEvent(It.IsAny <EventLevel>(), It.IsAny <PInvokeInt32CallCompletedTraceEvent>())).Callback(new LogEventCallback(
                                                                                                                                              (level, o1) =>
            {
                Assert.AreEqual(EventLevel.Verbose, level);

                var eventData = (PInvokeInt32CallCompletedTraceEvent)o1;
                Assert.True(eventData.Args.ContainsKey(nameof(lpszPhoneBook)));
                Assert.True(eventData.OutArgs.ContainsKey(nameof(lpDialParams)));
                Assert.True(eventData.OutArgs.ContainsKey(nameof(lpfPassword)));
                Assert.True(eventData.Duration > TimeSpan.Zero);
                Assert.AreEqual(SUCCESS, eventData.Result);
            })).Verifiable();


            var target = new RasApi32LoggingAdvice(api.Object, eventLoggingPolicy.Object);
            var result = target.RasGetEntryDialParams(lpszPhoneBook, ref lpDialParams, out lpfPassword);

            eventLoggingPolicy.Verify();
            Assert.AreEqual(SUCCESS, result);
            Assert.True(lpfPassword);
        }
示例#6
0
        public void RasGetConnectionStatisticsAsExpected()
        {
            var hRasConn     = new IntPtr(1);
            var lpStatistics = new RAS_STATS();

            api.Setup(o => o.RasGetConnectionStatistics(hRasConn, ref It.Ref <RAS_STATS> .IsAny)).Returns(SUCCESS);

            eventLoggingPolicy.Setup(o => o.LogEvent(It.IsAny <EventLevel>(), It.IsAny <PInvokeInt32CallCompletedTraceEvent>())).Callback(new LogEventCallback(
                                                                                                                                              (level, o1) =>
            {
                Assert.AreEqual(EventLevel.Verbose, level);

                var eventData = (PInvokeInt32CallCompletedTraceEvent)o1;
                Assert.True(eventData.Args.ContainsKey(nameof(hRasConn)));
                Assert.True(eventData.OutArgs.ContainsKey(nameof(lpStatistics)));
                Assert.True(eventData.Duration > TimeSpan.Zero);
                Assert.AreEqual(SUCCESS, eventData.Result);
            })).Verifiable();

            var target = new RasApi32LoggingAdvice(api.Object, eventLoggingPolicy.Object);
            var result = target.RasGetConnectionStatistics(hRasConn, ref lpStatistics);

            eventLoggingPolicy.Verify();
            Assert.AreEqual(SUCCESS, result);
        }
示例#7
0
        public void RasDialAsExpected()
        {
            var lpRasDialExtensions = new RASDIALEXTENSIONS();
            var lpszPhoneBook       = @"C:\Users\My.pbk";

            var          lpRasDialParams = new RASDIALPARAMS();
            var          dwNotifierType  = NotifierType.RasDialFunc2;
            RasDialFunc2 lpvNotifier     = null;
            var          lphRasConn      = IntPtr.Zero;

            api.Setup(o => o.RasDial(ref It.Ref <RASDIALEXTENSIONS> .IsAny, lpszPhoneBook, ref It.Ref <RASDIALPARAMS> .IsAny, dwNotifierType, lpvNotifier, out It.Ref <IntPtr> .IsAny)).Returns(new RasDialCallback(
                                                                                                                                                                                                    (ref RASDIALEXTENSIONS o1, string o2, ref RASDIALPARAMS o3, NotifierType o4, RasDialFunc2 o5, out IntPtr o6) =>
            {
                o6 = new IntPtr(1);
                return(SUCCESS);
            }));

            eventLoggingPolicy.Setup(o => o.LogEvent(It.IsAny <EventLevel>(), It.IsAny <PInvokeInt32CallCompletedTraceEvent>())).Callback(new LogEventCallback(
                                                                                                                                              (level, o1) =>
            {
                Assert.AreEqual(EventLevel.Verbose, level);

                var eventData = (PInvokeInt32CallCompletedTraceEvent)o1;
                Assert.True(eventData.Args.ContainsKey(nameof(lpRasDialExtensions)));
                Assert.True(eventData.Args.ContainsKey(nameof(lpszPhoneBook)));
                Assert.True(eventData.Args.ContainsKey(nameof(lpRasDialParams)));
                Assert.True(eventData.Args.ContainsKey(nameof(dwNotifierType)));
                Assert.True(eventData.Args.ContainsKey(nameof(lpvNotifier)));
                Assert.True(eventData.OutArgs.ContainsKey(nameof(lphRasConn)));

                Assert.True(eventData.Duration > TimeSpan.Zero);
                Assert.AreEqual(SUCCESS, eventData.Result);
            })).Verifiable();

            var target = new RasApi32LoggingAdvice(api.Object, eventLoggingPolicy.Object);
            var result = target.RasDial(ref lpRasDialExtensions, lpszPhoneBook, ref lpRasDialParams, dwNotifierType, null, out lphRasConn);

            eventLoggingPolicy.Verify();
            Assert.AreEqual(SUCCESS, result);
            Assert.AreEqual(new IntPtr(1), lphRasConn);
        }