public async Task Application_ConfigureAsync_HelperSetWithOthersFollowing_ClearsEntriesSetsHelper()
        {
            const string emptyHelper    = "";
            const string gcmConfigName  = "manager-core";
            const string executablePath = "/usr/local/share/gcm-core/git-credential-manager-core";
            string       key            = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}";

            IConfigurableComponent application = new Application(new TestCommandContext(), executablePath);

            var environment = new Mock <IEnvironment>();

            var config = new TestGitConfiguration();

            config.Dictionary[key] = new List <string>
            {
                "bar", emptyHelper, executablePath, "foo"
            };

            await application.ConfigureAsync(
                environment.Object, EnvironmentVariableTarget.User,
                config, GitConfigurationLevel.Global);

            Assert.Single(config.Dictionary);
            Assert.True(config.Dictionary.TryGetValue(key, out var actualValues));
            Assert.Equal(2, actualValues.Count);
            Assert.Equal(emptyHelper, actualValues[0]);
            Assert.Equal(gcmConfigName, actualValues[1]);
        }
        public async Task AzureReposHostProvider_ConfigureAsync_UseHttpPathUnset_SetsUseHttpPathTrue()
        {
            var provider = new AzureReposHostProvider(new TestCommandContext());

            var environment = new TestEnvironment();
            var config      = new TestGitConfiguration();

            await provider.ConfigureAsync(
                environment, EnvironmentVariableTarget.User,
                config, GitConfigurationLevel.Global);

            Assert.Single(config.Dictionary);
            Assert.True(config.Dictionary.TryGetValue(AzDevUseHttpPathKey, out IList <string> actualValues));
            Assert.Single(actualValues);
            Assert.Equal("true", actualValues[0]);
        }
        public async Task AzureReposHostProvider_UnconfigureAsync_UseHttpPathSet_RemovesEntry()
        {
            var provider = new AzureReposHostProvider(new TestCommandContext());

            var environment = new TestEnvironment();
            var config      = new TestGitConfiguration(new Dictionary <string, IList <string> >
            {
                [AzDevUseHttpPathKey] = new List <string> {
                    "true"
                }
            });

            await provider.UnconfigureAsync(
                environment, EnvironmentVariableTarget.User,
                config, GitConfigurationLevel.Global);

            Assert.Empty(config.Dictionary);
        }
        public async Task Application_UnconfigureAsync_User_PathSet_RemovesFromUserPath()
        {
            const string directoryPath  = @"X:\Install Location";
            const string executablePath = @"X:\Install Location\git-credential-manager-core.exe";

            IConfigurableComponent application = new Application(new TestCommandContext(), executablePath);

            var environment = new Mock <IEnvironment>();

            environment.Setup(x => x.IsDirectoryOnPath(directoryPath)).Returns(true);

            var config = new TestGitConfiguration();

            await application.UnconfigureAsync(
                environment.Object, EnvironmentVariableTarget.User,
                config, GitConfigurationLevel.Global);

            environment.Verify(x => x.RemoveDirectoryFromPath(directoryPath, EnvironmentVariableTarget.User), Times.Once);
        }
        public async Task Application_ConfigureAsync_User_PathSet_DoesNothing()
        {
            const string directoryPath  = @"X:\Install Location";
            const string executablePath = @"X:\Install Location\git-credential-manager-core.exe";

            IConfigurableComponent application = new Application(new TestCommandContext(), executablePath);

            var environment = new Mock <IEnvironment>();

            environment.Setup(x => x.IsDirectoryOnPath(directoryPath)).Returns(true);

            var config = new TestGitConfiguration();

            await application.ConfigureAsync(
                environment.Object, EnvironmentVariableTarget.User,
                config, GitConfigurationLevel.Global);

            environment.Verify(x => x.AddDirectoryToPath(It.IsAny <string>(), It.IsAny <EnvironmentVariableTarget>()), Times.Never);
        }
        public async Task Application_UnconfigureAsync_HelperSet_RemovesEntries()
        {
            const string emptyHelper    = "";
            const string gcmConfigName  = "manager-core";
            const string executablePath = "/usr/local/share/gcm-core/git-credential-manager-core";
            string       key            = $"{Constants.GitConfiguration.Credential.SectionName}.{Constants.GitConfiguration.Credential.Helper}";

            IConfigurableComponent application = new Application(new TestCommandContext(), executablePath);

            var environment = new Mock <IEnvironment>();
            var config      = new TestGitConfiguration(new Dictionary <string, IList <string> >
            {
                [key] = new List <string> {
                    emptyHelper, gcmConfigName
                }
            });

            await application.UnconfigureAsync(
                environment.Object, EnvironmentVariableTarget.User,
                config, GitConfigurationLevel.Global);

            Assert.Empty(config.Dictionary);
        }