Ejemplo n.º 1
0
        public async Task GetAsync_IfCancelled_Throws()
        {
            var provider = new VisualStudioCredentialProvider(Mock.Of <IVsWebProxy>());

            await Assert.ThrowsAsync <OperationCanceledException>(
                () => provider.GetAsync(
                    _uri,
                    proxy: null,
                    type: CredentialRequestType.Unauthorized,
                    message: "a",
                    isRetry: false,
                    nonInteractive: true,
                    cancellationToken: new CancellationToken(canceled: true)));
        }
Ejemplo n.º 2
0
        public async Task GetAsync_UriIsNull_Throws()
        {
            var provider = new VisualStudioCredentialProvider(Mock.Of <IVsWebProxy>());

            var exception = await Assert.ThrowsAsync <ArgumentNullException>(
                () => provider.GetAsync(
                    uri: null,
                    proxy: Mock.Of <IWebProxy>(),
                    type: CredentialRequestType.Unauthorized,
                    message: "a",
                    isRetry: false,
                    nonInteractive: true,
                    cancellationToken: CancellationToken.None));

            Assert.Equal("uri", exception.ParamName);
        }
Ejemplo n.º 3
0
        public async Task GetAsync_CallsWebProxy_PassesDefaultCredentialsState()
        {
            var vsWebProxy          = new Mock <IVsWebProxy>(MockBehavior.Strict);
            var newState            = (uint)__VsWebProxyState.VsWebProxyState_NoCredentials;
            var expectedCredentials = new NetworkCredential();

            vsWebProxy.Setup(x => x.PrepareWebProxy(
                                 It.Is <string>(u => u == _uri.OriginalString),
                                 It.Is <uint>(s => s == (uint)__VsWebProxyState.VsWebProxyState_DefaultCredentials),
                                 out newState,
                                 It.Is <int>(f => f == 1)))
            .Callback(() =>
            {
                newState = (uint)__VsWebProxyState.VsWebProxyState_PromptForCredentials;

                WebRequest.DefaultWebProxy.Credentials = expectedCredentials;
            })
            .Returns(0)
            .Verifiable();

            var provider = new VisualStudioCredentialProvider(
                vsWebProxy.Object,
                new Lazy <JoinableTaskFactory>(() => _fixture.JoinableTaskFactory));

            var response = await provider.GetAsync(
                _uri,
                proxy : null,
                type : CredentialRequestType.Unauthorized,
                message : "a",
                isRetry : false,
                nonInteractive : true,
                cancellationToken : CancellationToken.None);

            Assert.NotNull(response);
            Assert.Equal(CredentialStatus.Success, response.Status);
            Assert.Same(expectedCredentials, response.Credentials);

            vsWebProxy.Verify();
        }