private void AssertPathsUpdated(IEnumerable <string> expected, ChangedItemsCollection collection)
 {
     Assert.Equal(expected, collection.Added);
     Assert.Equal(expected, collection.Deleted);
     Assert.Equal(expected, collection.Modified);
     Assert.Equal(expected, collection.Unmerged);
 }
        private static ITabCompleter CreateTabCompleter(string join = "-")
        {
            var status = Substitute.For <IRepositoryStatus>();

            var working = new ChangedItemsCollection
            {
                Added    = new[] { $"working{join}added", $"working{join}duplicate" },
                Deleted  = new[] { $"working{join}deleted", $"working{join}duplicate" },
                Modified = new[] { $"working{join}modified", $"working{join}duplicate" },
                Unmerged = new[] { $"working{join}unmerged", $"working{join}duplicate" }
            };

            var index = new ChangedItemsCollection
            {
                Added    = new[] { $"index{join}added" },
                Deleted  = new[] { $"index{join}deleted" },
                Modified = new[] { $"index{join}modified" },
                Unmerged = new[] { $"index{join}unmerged" }
            };

            status.Index.Returns(index);
            status.Working.Returns(working);

            status.LocalBranches.Returns(new[] { "master", "feature1", "feature2" });
            status.Remotes.Returns(new[] { "origin", "other" });
            status.RemoteBranches.Returns(new[] { "origin/remotefeature", "origin/cutfeature" });
            status.Stashes.Returns(new[] { "stash", "wip" });

            return(new TabCompleter(Task.FromResult(status)));
        }
        public void UpdatePaths()
        {
            const string path           = @"c:\some\test\path";
            var          fileCollection = new[] { @"file.txt", @"dir\other.txt" };

            var collection = new ChangedItemsCollection
            {
                Added    = fileCollection,
                Modified = fileCollection,
                Deleted  = fileCollection,
                Unmerged = fileCollection
            };

            var status = Substitute.For <IRepositoryStatus>();

            status.AheadBy.Returns(1);
            status.BehindBy.Returns(2);
            status.Branch.Returns("some-branch");
            status.CurrentWorkingDirectory.Returns(path);
            status.GitDir.Returns(Path.Combine(path, ".git"));
            status.Index.Returns(collection);
            status.Working.Returns(collection);

            // Test with subdirectory
            var cwd1 = Substitute.For <ICurrentWorkingDirectory>();

            cwd1.CWD.Returns(Path.Combine(path, "dir"));
            cwd1.CreateRelativePath(Path.Combine(path, @"file.txt")).Returns(@"..\file");
            cwd1.CreateRelativePath(Path.Combine(path, @"dir\other.txt")).Returns(@"other.txt");

            var copy1    = new ReadonlyCopyRepositoryStatus(status, cwd1);
            var expected = new[] { @"..\file", @"other.txt" };

            AssertPathsUpdated(cwd1.CWD, expected, copy1);
        }
        private static ITabCompleter CreateTabCompleter(string join = "-")
        {
            var status = Substitute.For<IRepositoryStatus>();

            var working = new ChangedItemsCollection
            {
                Added = new[] { $"working{join}added", $"working{join}duplicate" },
                Deleted = new[] { $"working{join}deleted", $"working{join}duplicate" },
                Modified = new[] { $"working{join}modified", $"working{join}duplicate" },
                Unmerged = new[] { $"working{join}unmerged", $"working{join}duplicate" }
            };

            var index = new ChangedItemsCollection
            {
                Added = new[] { $"index{join}added" },
                Deleted = new[] { $"index{join}deleted" },
                Modified = new[] { $"index{join}modified" },
                Unmerged = new[] { $"index{join}unmerged" }
            };

            status.Index.Returns(index);
            status.Working.Returns(working);

            status.LocalBranches.Returns(new[] { "master", "feature1", "feature2" });
            status.Remotes.Returns(new[] { "origin", "other" });
            status.RemoteBranches.Returns(new[] { "origin/remotefeature", "origin/cutfeature" });
            status.Stashes.Returns(new[] { "stash", "wip" });

            return new TabCompleter(Task.FromResult(status));
        }