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 void CreateGraphSimpleTest() { using var repository = new SimpleRepositoryFactoryMock().CreateRepository("./"); var graph = LogGraph.CreateGraph(repository, new List <RefSelection> { new RefSelection("master", "master", true), new RefSelection("work", "work", true) }); var g = graph.ToList(); Assert.AreEqual(7, g.Count); var node = g[0]; Assert.AreEqual("Working tree", node.MessageShort); Assert.IsFalse(node.IsMerge); AssertFromToCount(node, 0, 1); Assert.IsTrue(node.Directions[0].Next.Contains(0)); Assert.AreEqual(0, node.Branches.Count); node = g[1]; Assert.AreEqual("MessageShort 5", node.MessageShort); Assert.IsFalse(node.IsMerge); AssertFromToCount(node, 1, 1); Assert.AreEqual(0, node.Directions.First().Next.First()); Assert.AreEqual(1, node.Branches.Count); Assert.AreEqual("master", node.Branches.First().CanonicalName); node = g[2]; Assert.AreEqual("MessageShort 4", node.MessageShort); Assert.IsFalse(node.IsMerge); AssertFromToCount(node, 1, 2); Assert.IsTrue(node.Directions[0].Next.Contains(0)); Assert.IsTrue(node.Directions[1].Next.Contains(0)); Assert.AreEqual(1, node.Branches.Count); Assert.AreEqual("work", node.Branches.First().CanonicalName); node = g[3]; Assert.AreEqual("MessageShort 3", node.MessageShort); Assert.IsTrue(node.IsMerge); AssertFromToCount(node, 2, 2); Assert.IsTrue(node.Directions[0].Next.Contains(0)); Assert.IsTrue(node.Directions[0].Next.Contains(1)); node = g[4]; Assert.AreEqual("MessageShort 2", node.MessageShort); Assert.IsFalse(node.IsMerge); AssertFromToCount(node, 2, 2); Assert.IsTrue(node.Directions[0].Next.Contains(0)); Assert.IsTrue(node.Directions[1].Next.Contains(1)); node = g[5]; Assert.AreEqual("MessageShort 1", node.MessageShort); Assert.IsFalse(node.IsMerge); AssertFromToCount(node, 2, 2); Assert.IsTrue(node.Directions[0].Next.Contains(0)); Assert.IsTrue(node.Directions[1].Next.Contains(0)); node = g[6]; Assert.AreEqual("MessageShort 0", node.MessageShort); Assert.IsFalse(node.IsMerge); AssertFromToCount(node, 2, 0); AssertGraphConsistency(g); }