public void ParsesExistingDataCorrectly()
        {
            ModifiedPathsDatabase modifiedPathsDatabase = CreateModifiedPathsDatabase(ExistingEntries);

            modifiedPathsDatabase.Count.ShouldEqual(3);
            modifiedPathsDatabase.Contains("file.txt", isFolder: false).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir/file2.txt", isFolder: false).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir1/dir2/file3.txt", isFolder: false).ShouldBeTrue();
        }
        private static void TestAddingPath(string pathToAdd, string pathInList, bool isFolder = false)
        {
            ModifiedPathsDatabase modifiedPathsDatabase = CreateModifiedPathsDatabase(initialContents: $"A {DefaultEntry}\r\n");
            bool isRetryable;

            modifiedPathsDatabase.TryAdd(pathToAdd, isFolder, out isRetryable);
            modifiedPathsDatabase.Count.ShouldEqual(2);
            modifiedPathsDatabase.Contains(pathInList, isFolder).ShouldBeTrue();
            modifiedPathsDatabase.Contains(ToGitPathSeparators(pathInList), isFolder).ShouldBeTrue();
            modifiedPathsDatabase.GetAllModifiedPaths().ShouldContainSingle(x => string.Compare(x, ToGitPathSeparators(pathInList), GVFSPlatform.Instance.Constants.PathComparison) == 0);
        }
        private static void TestAddingPath(string pathToAdd, string pathInList, bool isFolder = false)
        {
            ModifiedPathsDatabase mpd = CreateModifiedPathsDatabase(initialContents: $"A {DefaultEntry}\r\n");
            bool isRetryable;

            mpd.TryAdd(pathToAdd, isFolder, out isRetryable);
            mpd.Count.ShouldEqual(2);
            mpd.Contains(pathInList, isFolder).ShouldBeTrue();
            mpd.Contains(ToGitPathSeparators(pathInList), isFolder).ShouldBeTrue();
            mpd.GetAllModifiedPaths().ShouldContainSingle(x => string.Compare(x, ToGitPathSeparators(pathInList), StringComparison.OrdinalIgnoreCase) == 0);
        }
        public void RemoveEntriesWithParentFolderEntry()
        {
            ModifiedPathsDatabase modifiedPathsDatabase = CreateModifiedPathsDatabase(EntriesToCompress);

            modifiedPathsDatabase.RemoveEntriesWithParentFolderEntry(new MockTracer());
            modifiedPathsDatabase.Count.ShouldEqual(5);
            modifiedPathsDatabase.Contains("file.txt", isFolder: false).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir/", isFolder: true).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir1/dir2", isFolder: false).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir1/dir2/", isFolder: true).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir1/file.txt", isFolder: false).ShouldBeTrue();
        }
        public void AddsDefaultEntry()
        {
            ModifiedPathsDatabase modifiedPathsDatabase = CreateModifiedPathsDatabase(initialContents: string.Empty);

            modifiedPathsDatabase.Count.ShouldEqual(1);
            modifiedPathsDatabase.Contains(DefaultEntry, isFolder: false).ShouldBeTrue();
        }
        public void EntryNotAddedIfParentDirectoryExists()
        {
            ModifiedPathsDatabase modifiedPathsDatabase = CreateModifiedPathsDatabase(initialContents: "A dir/\r\n");

            modifiedPathsDatabase.Count.ShouldEqual(1);
            modifiedPathsDatabase.Contains("dir", isFolder: true).ShouldBeTrue();

            // Try adding a file for the directory that is in the modified paths
            modifiedPathsDatabase.TryAdd("dir/file.txt", isFolder: false, isRetryable: out _);
            modifiedPathsDatabase.Count.ShouldEqual(1);
            modifiedPathsDatabase.Contains("dir", isFolder: true).ShouldBeTrue();

            // Try adding a directory for the directory that is in the modified paths
            modifiedPathsDatabase.TryAdd("dir/dir2", isFolder: true, isRetryable: out _);
            modifiedPathsDatabase.Count.ShouldEqual(1);
            modifiedPathsDatabase.Contains("dir", isFolder: true).ShouldBeTrue();

            // Try adding a file for a directory that is not in the modified paths
            modifiedPathsDatabase.TryAdd("dir2/file.txt", isFolder: false, isRetryable: out _);
            modifiedPathsDatabase.Count.ShouldEqual(2);
            modifiedPathsDatabase.Contains("dir", isFolder: true).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir2/file.txt", isFolder: false).ShouldBeTrue();

            // Try adding a directory for a the directory that is not in the modified paths
            modifiedPathsDatabase.TryAdd("dir2/dir", isFolder: true, isRetryable: out _);
            modifiedPathsDatabase.Count.ShouldEqual(3);
            modifiedPathsDatabase.Contains("dir", isFolder: true).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir2/file.txt", isFolder: false).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir2/dir", isFolder: true).ShouldBeTrue();

            // Try adding a file in a subdirectory that is in the modified paths
            modifiedPathsDatabase.TryAdd("dir2/dir/file.txt", isFolder: false, isRetryable: out _);
            modifiedPathsDatabase.Count.ShouldEqual(3);
            modifiedPathsDatabase.Contains("dir", isFolder: true).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir2/file.txt", isFolder: false).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir2/dir", isFolder: true).ShouldBeTrue();

            // Try adding a directory for a subdirectory that is in the modified paths
            modifiedPathsDatabase.TryAdd("dir2/dir/dir3", isFolder: true, isRetryable: out _);
            modifiedPathsDatabase.Count.ShouldEqual(3);
            modifiedPathsDatabase.Contains("dir", isFolder: true).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir2/file.txt", isFolder: false).ShouldBeTrue();
            modifiedPathsDatabase.Contains("dir2/dir", isFolder: true).ShouldBeTrue();
        }