Beispiel #1
0
        public void ReturnsAnExceptionWhenTheFactoryDoesNotReturnAConnection()
        {
            var handle = new IntPtr(1);

            var rasHangUp          = new Mock <IRasHangUp>();
            var rasEnumConnections = new Mock <IRasEnumConnections>();
            var exceptionPolicy    = new Mock <IExceptionPolicy>();

            var waitHandle = new Mock <IValueWaiter <IntPtr> >();

            waitHandle.Setup(o => o.Value).Returns(handle);

            var cancellationTokenSource = new Mock <ITaskCancellationSource>();

            cancellationTokenSource.Setup(o => o.Token).Returns(new CancellationToken());
            var cancellationTokenSourceFactory = new Mock <ITaskCancellationSourceFactory>();

            cancellationTokenSourceFactory.Setup(o => o.Create(It.IsAny <CancellationToken>())).Returns(cancellationTokenSource.Object);

            var completionSource  = new Mock <ITaskCompletionSource <RasConnection> >();
            var cancellationToken = new CancellationToken();

            var target = new StubDefaultRasDialCallbackHandler(_ => null, rasHangUp.Object, rasEnumConnections.Object, exceptionPolicy.Object, waitHandle.Object, cancellationTokenSourceFactory.Object);

            target.Initialize(completionSource.Object, (e) => { }, () => { }, cancellationToken);

            var result = target.OnCallback(new IntPtr(1), 0, new IntPtr(1), 0, RasConnectionState.Connected, 0, 0);

            Assert.IsFalse(result);
            completionSource.Verify(o => o.SetException(It.IsAny <InvalidOperationException>()), Times.Once);
        }
        public void ReturnsAnExceptionWhenTheFactoryDoesNotReturnAConnection()
        {
            var handle = new IntPtr(1);

            waitHandle.Setup(o => o.Value).Returns(handle);

            var target = new StubDefaultRasDialCallbackHandler(_ => null, rasHangUp.Object, rasEnumConnections.Object, exceptionPolicy.Object, waitHandle.Object);

            target.Initialize(completionSource, (e) => { }, () => { }, CancellationToken.None);

            var result = target.OnCallback(new IntPtr(1), 0, new IntPtr(1), 0, RasConnectionState.Connected, 0, 0);

            Assert.IsFalse(result);
            Assert.IsTrue(target.HasEncounteredErrors);
        }