public void LibGit2Configuration_TryGetValue_Name_Exists_ReturnsTrueOutString() { string repoPath = CreateRepository(out string workDirPath); Git(repoPath, workDirPath, "config --local user.name john.doe").AssertSuccess(); var trace = new NullTrace(); var git = new LibGit2(trace); using (var config = git.GetConfiguration(repoPath)) { bool result = config.TryGetValue("user.name", out string value); Assert.True(result); Assert.NotNull(value); Assert.Equal("john.doe", value); } }
public void LibGit2Configuration_Enumerate_CallbackReturnsTrue_InvokesCallbackForEachEntry() { string repoPath = CreateRepository(out string workDirPath); Git(repoPath, workDirPath, "config --local foo.name lancelot").AssertSuccess(); Git(repoPath, workDirPath, "config --local foo.quest seek-holy-grail").AssertSuccess(); Git(repoPath, workDirPath, "config --local foo.favcolor blue").AssertSuccess(); var expectedVisitedEntries = new List <(string name, string value)> { ("foo.name", "lancelot"), ("foo.quest", "seek-holy-grail"), ("foo.favcolor", "blue") }; var trace = new NullTrace(); var git = new LibGit2(trace); using (var config = git.GetConfiguration(repoPath)) { var actualVisitedEntries = new List <(string name, string value)>(); bool cb(string name, string value) { if (name.StartsWith("foo.")) { actualVisitedEntries.Add((name, value)); } // Continue enumeration return(true); } config.Enumerate(cb); Assert.Equal(expectedVisitedEntries, actualVisitedEntries); } }