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); }
public void SetsAutoInitToTrueWhenGitIgnore() { var creationService = Substitutes.RepositoryCreationService; var provider = Substitutes.GetServiceProvider(creationService: creationService); var account = Substitute.For <IAccount>(); var modelService = Substitute.For <IModelService>(); modelService.GetAccounts().Returns(Observable.Return(new List <IAccount> { account })); var vm = GetMeAViewModel(provider, modelService: modelService); vm.RepositoryName = "Krieger"; vm.BaseRepositoryPath = @"c:\dev"; vm.SelectedAccount = account; vm.KeepPrivate = false; vm.SelectedGitIgnoreTemplate = GitIgnoreItem.Create("VisualStudio"); vm.CreateRepository.Execute(); creationService .Received() .CreateRepository( Arg.Is <NewRepository>(r => r.Name == "Krieger" && r.Private == false && r.AutoInit == true && r.LicenseTemplate == null && r.GitignoreTemplate == "VisualStudio"), account, @"c:\dev", Args.ApiClient); }
public void SetsAutoInitToTrueWhenLicenseSelected() { var creationService = Substitutes.RepositoryCreationService; var provider = Substitutes.GetServiceProvider(creationService: creationService); var account = Substitute.For <IAccount>(); var hosts = provider.GetRepositoryHosts(); var host = hosts.GitHubHost; hosts.LookupHost(Args.HostAddress).Returns(host); host.ModelService.GetAccounts().Returns(Observable.Return(new List <IAccount> { account })); var vm = GetMeAViewModel(provider); vm.RepositoryName = "Krieger"; vm.BaseRepositoryPath = @"c:\dev"; vm.SelectedAccount = account; vm.KeepPrivate = false; vm.SelectedLicense = new LicenseItem("mit", "MIT"); vm.CreateRepository.Execute(null); creationService .Received() .CreateRepository( Arg.Is <NewRepository>(r => r.Name == "Krieger" && r.Private == false && r.AutoInit == true && r.LicenseTemplate == "mit" && r.GitignoreTemplate == null), account, @"c:\dev", Args.ApiClient); }
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 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)); }
public async Task DisplaysUserErrorWhenCreationFailsAsync() { var creationService = Substitutes.RepositoryCreationService; var provider = Substitutes.GetServiceProvider(creationService: creationService); creationService.CreateRepository(Args.NewRepository, Args.Account, Args.String, Args.ApiClient) .Returns(Observable.Throw <Unit>(new InvalidOperationException("Could not create a repository on GitHub"))); var vm = GetMeAViewModel(provider); vm.RepositoryName = "my-repo"; using (var handlers = ReactiveTestHelper.OverrideHandlersForTesting()) { await vm.CreateRepository.Execute().Catch(Observable.Return(Unit.Default)); Assert.That("Could not create a repository on GitHub", Is.EqualTo(handlers.LastError.ErrorMessage)); } }
public void CreatesRepositoryOnlineViaApiAndThenClonesIt() { var cloneService = Substitutes.RepositoryCloneService; var provider = Substitutes.GetServiceProvider(cloneService); var newRepository = new NewRepository("octokit.net"); var repository = new TestRepository("octokit.net", "https://github.com/octokit/octokit.net"); var account = Substitute.For <IAccount>(); account.Login.Returns("octokit"); account.IsUser.Returns(false); var apiClient = Substitute.For <IApiClient>(); apiClient.CreateRepository(newRepository, "octokit", false) .Returns(Observable.Return(repository)); var creator = provider.GetRepositoryCreationService(); creator.CreateRepository(newRepository, account, @"c:\dev", apiClient).Subscribe(); apiClient.Received().CreateRepository(newRepository, "octokit", false); }