public void ShouldRegisterForAndResetConnectedEventsWhenNoHandleIsProvided()
        {
            var registeredCallback = new Mock <IRegisteredCallback>();

            var api             = new Mock <IRasApi32>();
            var callbackHandler = new Mock <IRasConnectionNotificationCallbackHandler>();
            var exceptionPolicy = new Mock <IExceptionPolicy>();

            var callbackFactory = new Mock <IRegisteredCallbackFactory>();

            callbackFactory.Setup(o => o.Create(It.IsAny <WaitOrTimerCallback>(), It.IsAny <object>())).Returns(registeredCallback.Object);

            var target = new RasConnectionNotificationService(api.Object, callbackHandler.Object, exceptionPolicy.Object, callbackFactory.Object);

            target.Subscribe(new RasNotificationContext
            {
                Connection             = null,
                OnConnectedCallback    = e => { },
                OnDisconnectedCallback = e => { }
            });

            callbackHandler.Verify(o => o.Initialize(), Times.Once);
            api.Verify(o => o.RasConnectionNotification(INVALID_HANDLE_VALUE, It.IsAny <ISafeHandleWrapper>(), RASCN.Connection), Times.Once);
            api.Verify(o => o.RasConnectionNotification(INVALID_HANDLE_VALUE, It.IsAny <ISafeHandleWrapper>(), RASCN.Disconnection), Times.Once);

            Assert.True(target.IsActive);

            target.Reset();

            registeredCallback.Verify(o => o.Dispose(), Times.Exactly(2));
            Assert.False(target.IsActive);
        }
        public void ThrowsAnExceptionWhenResetAfterDispose()
        {
            var api             = new Mock <IRasApi32>();
            var callbackHandler = new Mock <IRasConnectionNotificationCallbackHandler>();
            var exceptionPolicy = new Mock <IExceptionPolicy>();
            var callbackFactory = new Mock <IRegisteredCallbackFactory>();

            var target = new RasConnectionNotificationService(api.Object, callbackHandler.Object, exceptionPolicy.Object, callbackFactory.Object);

            target.Dispose();

            Assert.Throws <ObjectDisposedException>(() => target.Reset());
        }