public async Task CanSelectBranches() { var schedulers = new TestSchedulers(); var repositoryFactory = new SimpleRepositoryFactoryMock(); var repositoryDescription = new RepositoryDescription("Name", "PATH TO REPO"); var res = await RepositoryViewModel.Create( schedulers, CancellationToken.None, repositoryFactory, new TestFileSystem(), repositoryDescription, Observable.Return(new CompareOptions())); Assert.IsTrue(res.Is <RepositoryViewModel>()); using var repo = res.Get <RepositoryViewModel>(); var refs = repo.References.Value; Assert.IsNotNull(refs); Assert.AreEqual(2, refs !.Branches.Refs.Count); var master = refs.Branches.Refs.Where(b => b.FriendlyName == "master").FirstOrDefault() ?? throw new InvalidOperationException("Branch master not found."); var work = refs.Branches.Refs.Where(b => b.FriendlyName == "work").FirstOrDefault() ?? throw new InvalidOperationException("Branch work not found."); Assert.IsTrue(master.Selected.Value, "Branch master (HEAD) should be selected."); Assert.IsFalse(work.Selected.Value, "Branch work should not be selected."); Assert.IsTrue(repo.Graph.LogGraphNodes.Value.VariantIndex == 0); var logGraphNodes = repo.Graph.LogGraphNodes.Value.First; using var _1 = repo.Graph.LogGraphNodes .Subscribe(nodes => logGraphNodes = nodes.VariantIndex == 0 ? nodes.First : throw new InvalidOperationException(nodes.Second.Message)); IList <RefSelection>?selectedBranches = null; refs = repo.References.Value; using var _2 = refs !.Branches.SelectedRefs .Subscribe(sb => selectedBranches = sb); Assert.AreEqual(1, selectedBranches.Where(b => b.Selected).Count()); Assert.AreEqual(7, logGraphNodes.Count); // The mock doesn't filter unreachable commits. var nodesWithBranch = logGraphNodes.Where(c => c.Branches.Any()); Assert.AreEqual(2, nodesWithBranch.Count()); Assert.AreEqual("master", nodesWithBranch.First().Branches.First().FirendlyName); work.SelectCommand.Execute(true); Assert.AreEqual(2, logGraphNodes.Where(c => c.Branches.Any()).Count()); _ = selectedBranches ?? throw new InvalidOperationException("Selected branches were not set."); Assert.AreEqual(2, selectedBranches.Where(b => b.Selected).Count()); }
public async Task CanCreateRepositoryViewModel() { var schedulers = new TestSchedulers(); var repositoryFactory = new TestRepositoryFactory(); var repositoryDescription = new RepositoryDescription("Name", "PATH TO REPO"); var res = await RepositoryViewModel.Create( schedulers, CancellationToken.None, repositoryFactory, new TestFileSystem(), repositoryDescription, Observable.Return(new CompareOptions())); Assert.IsTrue(res.Is <RepositoryViewModel>()); using var repo = res.Get <RepositoryViewModel>(); Assert.AreEqual(repositoryDescription, repo.RepositoryDescription); }
public PTagger(IRepositoryFactory repositoryFactory, ISchedulers schedulers, IFileSystem fileSystemService, IObservable <string> pushPathObservable) { CompareOptions = new Configuration.CompareOptionsViewModel(schedulers, new CompareOptions() { Similarity = SimilarityOptions.Default }); var newTabCommand = ReactiveCommand .Create <object?, object?>(p => p, schedulers.Dispatcher) .DisposeWith(_disposable); NewTabCommand = newTabCommand; var newTabObservable = newTabCommand .StartWith((object?)null) .ObserveOn(schedulers.Dispatcher) .Select(_ => new RepositorySelectionViewModel(schedulers, repositoryFactory, fileSystemService)) .Publish(); var openRepositoryFromTab = newTabObservable .SelectMany(newTab => newTab.OpenRepository .Select(openRepository => new { newTab, openRepository })); var pushedRepositoryDesc = pushPathObservable .Where(path => !string.IsNullOrWhiteSpace(path)) .Select(repositoryFactory.DiscoverRepository) .SkipNull() .Select(path => RepositorySelectionViewModel.RepositoryDescriptionFromPath(repositoryFactory, path)); var openRepository = openRepositoryFromTab .Select(openRepo => openRepo.openRepository) .Merge(pushedRepositoryDesc) .SelectMany(desc => Observable .FromAsync(ct => RepositoryViewModel.Create( schedulers, ct, repositoryFactory, fileSystemService, desc, CompareOptions.CompareOptionsObservable))) .Publish(); var openTabObservable = newTabObservable .Select(newTab => new TabType(newTab)) .Merge(openRepository .Select(newRepo => new TabType(newRepo)) .ObserveOn(schedulers.Dispatcher)); var closeTabCommand = ReactiveCommand .Create <TabType, TabType>(tab => tab, schedulers.Dispatcher) .DisposeWith(_disposable); CloseTabCommand = closeTabCommand; var anyTabOpen = OpenedRepositories .MakeObservable() .Select(_ => OpenedRepositories.Any()); var closeAllTabsCommand = ReactiveCommand .Create <object?, IList <TabType> >(anyTabOpen, _ => OpenedRepositories.ToList(), schedulers.Dispatcher) .DisposeWith(_disposable); CloseAllTabsCommand = closeAllTabsCommand; var closeTabObservable = openRepositoryFromTab .Select(openRepo => new TabType(openRepo.newTab)) .Merge(closeTabCommand) .Merge(closeAllTabsCommand .Many()); openTabObservable .Subscribe(tab => OpenedRepositories.Add(tab)) .DisposeWith(_disposable); closeTabObservable .Subscribe(tab => { OpenedRepositories.Remove(tab); DisposeTab(tab); }) .DisposeWith(_disposable); openRepository .Connect() .DisposeWith(_disposable); newTabObservable .Connect() .DisposeWith(_disposable); }