Exemple #1
0
        public async Task GitHubHostProvider_GetSupportedAuthenticationModes_WithMetadata(string uriString, string gitHubAuthModes,
                                                                                          string installedVersion, bool verifiablePasswordAuthentication, AuthenticationModes expectedModes)
        {
            var targetUri = new Uri(uriString);

            var context = new TestCommandContext {
            };

            if (gitHubAuthModes != null)
            {
                context.Environment.Variables.Add(GitHubConstants.EnvironmentVariables.AuthenticationModes, gitHubAuthModes);
            }

            var ghApiMock  = new Mock <IGitHubRestApi>(MockBehavior.Strict);
            var ghAuthMock = new Mock <IGitHubAuthentication>(MockBehavior.Strict);

            var metaInfo = new GitHubMetaInfo
            {
                InstalledVersion = installedVersion,
                VerifiablePasswordAuthentication = verifiablePasswordAuthentication
            };

            ghApiMock.Setup(x => x.GetMetaInfoAsync(targetUri)).ReturnsAsync(metaInfo);

            var provider = new GitHubHostProvider(context, ghApiMock.Object, ghAuthMock.Object);

            AuthenticationModes actualModes = await provider.GetSupportedAuthenticationModesAsync(targetUri);

            Assert.Equal(expectedModes, actualModes);
        }
        protected override async Task <bool> RunInternalAsync(StringBuilder log, IList <string> additionalFiles)
        {
            var targetUri = new Uri("https://github.com");

            log.AppendLine($"Using '{targetUri}' as API target.");

            log.Append("Querying '/meta' endpoint...");
            GitHubMetaInfo metaInfo = await _api.GetMetaInfoAsync(targetUri);

            log.AppendLine(" OK");

            return(true);
        }
        public async Task GitHubHostProvider_GetSupportedAuthenticationModes_NotDotCom_NewInstanceWithPassword_ReturnsBasicAndOAuth()
        {
            var targetUri = new Uri("https://ghe.io");
            var metaInfo  = new GitHubMetaInfo
            {
                InstalledVersion = "100.0",
                VerifiablePasswordAuthentication = true
            };

            var expectedModes = AuthenticationModes.Basic | AuthenticationModes.OAuth;

            var context    = new TestCommandContext();
            var ghAuthMock = new Mock <IGitHubAuthentication>(MockBehavior.Strict);

            var ghApiMock = new Mock <IGitHubRestApi>(MockBehavior.Strict);

            ghApiMock.Setup(x => x.GetMetaInfoAsync(targetUri)).ReturnsAsync(metaInfo);

            var provider = new GitHubHostProvider(context, ghApiMock.Object, ghAuthMock.Object);

            AuthenticationModes actualModes = await provider.GetSupportedAuthenticationModesAsync(targetUri);

            Assert.Equal(expectedModes, actualModes);
        }