public async Task Skip_OpenRepository_When_Already_Open(string repositoryPath, string solutionPath,
                                                                bool isFolder, int openRepository)
        {
            var repositoryUrl     = "https://github.com/owner/repo";
            var cloneDialogResult = new CloneDialogResult(repositoryPath, repositoryUrl);
            var serviceProvider   = Substitutes.GetServiceProvider();
            var operatingSystem   = serviceProvider.GetOperatingSystem();

            operatingSystem.Directory.DirectoryExists(repositoryPath).Returns(true);
            var dte = Substitute.For <EnvDTE.DTE>();

            serviceProvider.GetService <EnvDTE.DTE>().Returns(dte);
            dte.Solution.FileName.Returns(solutionPath);
            if (isFolder)
            {
                operatingSystem.Directory.DirectoryExists(solutionPath).Returns(true);
            }
            var cloneService = CreateRepositoryCloneService(serviceProvider);

            await cloneService.CloneOrOpenRepository(cloneDialogResult);

            var teamExplorerServices = serviceProvider.GetTeamExplorerServices();

            teamExplorerServices.Received(openRepository).OpenRepository(repositoryPath);
        }
    static void Main(string[] args)
    {
        var subs = new Substitutes {
            { 'a', 'b' }, { 'c', 'd' }
        };

        Console.WriteLine(subs['a']);     //Prints b
        Console.WriteLine(subs['b']);     //Prints a
    }
        public async Task ClonesToRepositoryPathAsync()
        {
            var serviceProvider = Substitutes.GetServiceProvider();
            var operatingSystem = serviceProvider.GetOperatingSystem();
            var vsGitServices   = serviceProvider.GetVSGitServices();
            var cloneService    = CreateRepositoryCloneService(serviceProvider);

            await cloneService.CloneRepository("https://github.com/foo/bar", @"c:\dev\bar");

            operatingSystem.Directory.Received().CreateDirectory(@"c:\dev\bar");
            await vsGitServices.Received().Clone("https://github.com/foo/bar", @"c:\dev\bar", true);
        }
        public async Task UpdatesMetricsWhenRepositoryClonedAsync(string cloneUrl, int numberOfCalls, string counterName)
        {
            var serviceProvider = Substitutes.GetServiceProvider();
            var usageTracker    = serviceProvider.GetUsageTracker();
            var cloneService    = CreateRepositoryCloneService(serviceProvider);

            await cloneService.CloneRepository(cloneUrl, @"c:\dev\bar");

            var model = UsageModel.Create(Guid.NewGuid());

            await usageTracker.Received(numberOfCalls).IncrementCounter(
                Arg.Is <Expression <Func <UsageModel.MeasuresModel, int> > >(x =>
                                                                             ((MemberExpression)x.Body).Member.Name == counterName));
        }
        public async Task Token_response_contains_invalid_grant_when_Authenticator_throws_an_exception()
        {
            var substitutes = new Substitutes();

            substitutes.Authenticator.SignIn(Arg.Any <Credentials>())
            .ThrowsForAnyArgs(new ApplicationException("This is a test"));

            using (var server = CreateTestServerWith(substitutes.InitializeContainer))
            {
                var response = await server.CreateRequest("/token").PostFormAsync(substitutes.LoginForm);

                var content = await response.Content.ReadAsStringAsync();

                Assert.That(content, Contains.Substring(@"""error"":""invalid_grant"""));
                Assert.That(content, Contains.Substring(@"""error_description"":""This is a test"""));
            }
        }
        public async Task UpdatesMetricsWhenCloneOrOpenRepositoryAsync(string cloneUrl, bool dirExists, int numberOfCalls, string counterName)
        {
            var repositoryPath    = @"c:\dev\bar";
            var cloneDialogResult = new CloneDialogResult(repositoryPath, cloneUrl);
            var serviceProvider   = Substitutes.GetServiceProvider();
            var operatingSystem   = serviceProvider.GetOperatingSystem();

            operatingSystem.Directory.DirectoryExists(repositoryPath).Returns(dirExists);
            var usageTracker = serviceProvider.GetUsageTracker();
            var cloneService = CreateRepositoryCloneService(serviceProvider);

            await cloneService.CloneOrOpenRepository(cloneDialogResult);

            await usageTracker.Received(numberOfCalls).IncrementCounter(
                Arg.Is <Expression <Func <UsageModel.MeasuresModel, int> > >(x =>
                                                                             ((MemberExpression)x.Body).Member.Name == counterName));
        }
        public async Task UpdatesMetricsWhenDefaultClonePath(string targetPath, string defaultPath, int numberOfCalls, string counterName)
        {
            var serviceProvider = Substitutes.GetServiceProvider();
            var vsGitServices   = serviceProvider.GetVSGitServices();

            vsGitServices.GetLocalClonePathFromGitProvider().Returns(defaultPath);
            var usageTracker = serviceProvider.GetUsageTracker();
            var cloneService = CreateRepositoryCloneService(serviceProvider);

            await cloneService.CloneRepository("https://github.com/foo/bar", targetPath);

            var model = UsageModel.Create(Guid.NewGuid());

            await usageTracker.Received(numberOfCalls).IncrementCounter(
                Arg.Is <Expression <Func <UsageModel.MeasuresModel, int> > >(x =>
                                                                             ((MemberExpression)x.Body).Member.Name == counterName));
        }