7
7
using System . Text ;
8
8
using Microsoft . Git . CredentialManager . Interop ;
9
9
using Microsoft . Git . CredentialManager . Interop . Posix . Native ;
10
+ using Microsoft . Git . CredentialManager . Tests . Objects ;
10
11
using Xunit ;
11
12
12
13
namespace Microsoft . Git . CredentialManager . Tests . Interop
@@ -16,7 +17,8 @@ public class LibGit2Tests
16
17
[ Fact ]
17
18
public void LibGit2_GetRepositoryPath_NotInsideRepository_ReturnsNull ( )
18
19
{
19
- var git = new LibGit2 ( ) ;
20
+ var trace = new NullTrace ( ) ;
21
+ var git = new LibGit2 ( trace ) ;
20
22
string randomPath = Path . Combine ( Path . GetTempPath ( ) , $ "{ Guid . NewGuid ( ) : N} ") ;
21
23
Directory . CreateDirectory ( randomPath ) ;
22
24
@@ -28,20 +30,97 @@ public void LibGit2_GetRepositoryPath_NotInsideRepository_ReturnsNull()
28
30
[ Fact ]
29
31
public void LibGit2_GetConfiguration_ReturnsConfiguration ( )
30
32
{
31
- var git = new LibGit2 ( ) ;
33
+ var trace = new NullTrace ( ) ;
34
+ var git = new LibGit2 ( trace ) ;
32
35
using ( var config = git . GetConfiguration ( ) )
33
36
{
34
37
Assert . NotNull ( config ) ;
35
38
}
36
39
}
37
40
41
+ [ Fact ]
42
+ public void LibGit2Configuration_Enumerate_CallbackReturnsTrue_InvokesCallbackForEachEntry ( )
43
+ {
44
+ string repoPath = CreateRepository ( ) ;
45
+ Git ( repoPath , "config --local foo.name lancelot" ) . AssertSuccess ( ) ;
46
+ Git ( repoPath , "config --local foo.quest seek-holy-grail" ) . AssertSuccess ( ) ;
47
+ Git ( repoPath , "config --local foo.favcolor blue" ) . AssertSuccess ( ) ;
48
+
49
+ var expectedVisitedEntries = new List < ( string name , string value ) >
50
+ {
51
+ ( "foo.name" , "lancelot" ) ,
52
+ ( "foo.quest" , "seek-holy-grail" ) ,
53
+ ( "foo.favcolor" , "blue" )
54
+ } ;
55
+
56
+ var trace = new NullTrace ( ) ;
57
+ var git = new LibGit2 ( trace ) ;
58
+ using ( var config = git . GetConfiguration ( repoPath ) )
59
+ {
60
+ var actualVisitedEntries = new List < ( string name , string value ) > ( ) ;
61
+
62
+ bool cb ( string name , string value )
63
+ {
64
+ if ( name . StartsWith ( "foo." ) )
65
+ {
66
+ actualVisitedEntries . Add ( ( name , value ) ) ;
67
+ }
68
+
69
+ // Continue enumeration
70
+ return true ;
71
+ }
72
+
73
+ config . Enumerate ( cb ) ;
74
+
75
+ Assert . Equal ( expectedVisitedEntries , actualVisitedEntries ) ;
76
+ }
77
+ }
78
+
79
+ [ Fact ]
80
+ public void LibGit2Configuration_Enumerate_CallbackReturnsFalse_InvokesCallbackForEachEntryUntilReturnsFalse ( )
81
+ {
82
+ string repoPath = CreateRepository ( ) ;
83
+ Git ( repoPath , "config --local foo.name lancelot" ) . AssertSuccess ( ) ;
84
+ Git ( repoPath , "config --local foo.quest seek-holy-grail" ) . AssertSuccess ( ) ;
85
+ Git ( repoPath , "config --local foo.favcolor blue" ) . AssertSuccess ( ) ;
86
+
87
+ var expectedVisitedEntries = new List < ( string name , string value ) >
88
+ {
89
+ ( "foo.name" , "lancelot" ) ,
90
+ ( "foo.quest" , "seek-holy-grail" )
91
+ } ;
92
+
93
+ var trace = new NullTrace ( ) ;
94
+ var git = new LibGit2 ( trace ) ;
95
+ using ( var config = git . GetConfiguration ( repoPath ) )
96
+ {
97
+ var actualVisitedEntries = new List < ( string name , string value ) > ( ) ;
98
+
99
+ bool cb ( string name , string value )
100
+ {
101
+ if ( name . StartsWith ( "foo." ) )
102
+ {
103
+ actualVisitedEntries . Add ( ( name , value ) ) ;
104
+ }
105
+
106
+ // Stop enumeration after 2 'foo' entries
107
+ return actualVisitedEntries . Count < 2 ;
108
+ }
109
+
110
+ config . Enumerate ( cb ) ;
111
+
112
+ Assert . Equal ( expectedVisitedEntries , actualVisitedEntries ) ;
113
+ }
114
+ }
115
+
38
116
[ Fact ]
39
117
public void LibGit2Configuration_TryGetValue_Name_Exists_ReturnsTrueOutString ( )
40
118
{
41
119
string repoPath = CreateRepository ( ) ;
42
120
Git ( repoPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
43
121
44
- var git = new LibGit2 ( ) ;
122
+ var trace = new NullTrace ( ) ;
123
+ var git = new LibGit2 ( trace ) ;
45
124
using ( var config = git . GetConfiguration ( repoPath ) )
46
125
{
47
126
bool result = config . TryGetValue ( "user.name" , out string value ) ;
@@ -56,7 +135,8 @@ public void LibGit2Configuration_TryGetValue_Name_DoesNotExists_ReturnsFalse()
56
135
{
57
136
string repoPath = CreateRepository ( ) ;
58
137
59
- var git = new LibGit2 ( ) ;
138
+ var trace = new NullTrace ( ) ;
139
+ var git = new LibGit2 ( trace ) ;
60
140
using ( var config = git . GetConfiguration ( repoPath ) )
61
141
{
62
142
string randomName = $ "{ Guid . NewGuid ( ) : N} .{ Guid . NewGuid ( ) : N} ";
@@ -72,7 +152,8 @@ public void LibGit2Configuration_TryGetValue_SectionProperty_Exists_ReturnsTrueO
72
152
string repoPath = CreateRepository ( ) ;
73
153
Git ( repoPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
74
154
75
- var git = new LibGit2 ( ) ;
155
+ var trace = new NullTrace ( ) ;
156
+ var git = new LibGit2 ( trace ) ;
76
157
using ( var config = git . GetConfiguration ( repoPath ) )
77
158
{
78
159
bool result = config . TryGetValue ( "user" , "name" , out string value ) ;
@@ -87,7 +168,8 @@ public void LibGit2Configuration_TryGetValue_SectionProperty_DoesNotExists_Retur
87
168
{
88
169
string repoPath = CreateRepository ( ) ;
89
170
90
- var git = new LibGit2 ( ) ;
171
+ var trace = new NullTrace ( ) ;
172
+ var git = new LibGit2 ( trace ) ;
91
173
using ( var config = git . GetConfiguration ( repoPath ) )
92
174
{
93
175
string randomSection = Guid . NewGuid ( ) . ToString ( "N" ) ;
@@ -104,7 +186,8 @@ public void LibGit2Configuration_TryGetValue_SectionScopeProperty_Exists_Returns
104
186
string repoPath = CreateRepository ( ) ;
105
187
Git ( repoPath , "config --local user.example.com.name john.doe" ) . AssertSuccess ( ) ;
106
188
107
- var git = new LibGit2 ( ) ;
189
+ var trace = new NullTrace ( ) ;
190
+ var git = new LibGit2 ( trace ) ;
108
191
using ( var config = git . GetConfiguration ( repoPath ) )
109
192
{
110
193
bool result = config . TryGetValue ( "user" , "example.com" , "name" , out string value ) ;
@@ -120,7 +203,8 @@ public void LibGit2Configuration_TryGetValue_SectionScopeProperty_NullScope_Retu
120
203
string repoPath = CreateRepository ( ) ;
121
204
Git ( repoPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
122
205
123
- var git = new LibGit2 ( ) ;
206
+ var trace = new NullTrace ( ) ;
207
+ var git = new LibGit2 ( trace ) ;
124
208
using ( var config = git . GetConfiguration ( repoPath ) )
125
209
{
126
210
bool result = config . TryGetValue ( "user" , null , "name" , out string value ) ;
@@ -135,7 +219,8 @@ public void LibGit2Configuration_TryGetValue_SectionScopeProperty_DoesNotExists_
135
219
{
136
220
string repoPath = CreateRepository ( ) ;
137
221
138
- var git = new LibGit2 ( ) ;
222
+ var trace = new NullTrace ( ) ;
223
+ var git = new LibGit2 ( trace ) ;
139
224
using ( var config = git . GetConfiguration ( repoPath ) )
140
225
{
141
226
string randomSection = Guid . NewGuid ( ) . ToString ( "N" ) ;
@@ -153,7 +238,8 @@ public void LibGit2Configuration_GetString_Name_Exists_ReturnsString()
153
238
string repoPath = CreateRepository ( ) ;
154
239
Git ( repoPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
155
240
156
- var git = new LibGit2 ( ) ;
241
+ var trace = new NullTrace ( ) ;
242
+ var git = new LibGit2 ( trace ) ;
157
243
using ( var config = git . GetConfiguration ( repoPath ) )
158
244
{
159
245
string value = config . GetValue ( "user.name" ) ;
@@ -167,7 +253,8 @@ public void LibGit2Configuration_GetString_Name_DoesNotExists_ThrowsException()
167
253
{
168
254
string repoPath = CreateRepository ( ) ;
169
255
170
- var git = new LibGit2 ( ) ;
256
+ var trace = new NullTrace ( ) ;
257
+ var git = new LibGit2 ( trace ) ;
171
258
using ( var config = git . GetConfiguration ( repoPath ) )
172
259
{
173
260
string randomName = $ "{ Guid . NewGuid ( ) : N} .{ Guid . NewGuid ( ) : N} ";
@@ -181,7 +268,8 @@ public void LibGit2Configuration_GetString_SectionProperty_Exists_ReturnsString(
181
268
string repoPath = CreateRepository ( ) ;
182
269
Git ( repoPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
183
270
184
- var git = new LibGit2 ( ) ;
271
+ var trace = new NullTrace ( ) ;
272
+ var git = new LibGit2 ( trace ) ;
185
273
using ( var config = git . GetConfiguration ( repoPath ) )
186
274
{
187
275
string value = config . GetValue ( "user" , "name" ) ;
@@ -195,7 +283,8 @@ public void LibGit2Configuration_GetString_SectionProperty_DoesNotExists_ThrowsE
195
283
{
196
284
string repoPath = CreateRepository ( ) ;
197
285
198
- var git = new LibGit2 ( ) ;
286
+ var trace = new NullTrace ( ) ;
287
+ var git = new LibGit2 ( trace ) ;
199
288
using ( var config = git . GetConfiguration ( repoPath ) )
200
289
{
201
290
string randomSection = Guid . NewGuid ( ) . ToString ( "N" ) ;
@@ -210,7 +299,8 @@ public void LibGit2Configuration_GetString_SectionScopeProperty_Exists_ReturnsSt
210
299
string repoPath = CreateRepository ( ) ;
211
300
Git ( repoPath , "config --local user.example.com.name john.doe" ) . AssertSuccess ( ) ;
212
301
213
- var git = new LibGit2 ( ) ;
302
+ var trace = new NullTrace ( ) ;
303
+ var git = new LibGit2 ( trace ) ;
214
304
using ( var config = git . GetConfiguration ( repoPath ) )
215
305
{
216
306
string value = config . GetValue ( "user" , "example.com" , "name" ) ;
@@ -225,7 +315,8 @@ public void LibGit2Configuration_GetString_SectionScopeProperty_NullScope_Return
225
315
string repoPath = CreateRepository ( ) ;
226
316
Git ( repoPath , "config --local user.name john.doe" ) . AssertSuccess ( ) ;
227
317
228
- var git = new LibGit2 ( ) ;
318
+ var trace = new NullTrace ( ) ;
319
+ var git = new LibGit2 ( trace ) ;
229
320
using ( var config = git . GetConfiguration ( repoPath ) )
230
321
{
231
322
string value = config . GetValue ( "user" , null , "name" ) ;
@@ -239,7 +330,8 @@ public void LibGit2Configuration_GetString_SectionScopeProperty_DoesNotExists_Th
239
330
{
240
331
string repoPath = CreateRepository ( ) ;
241
332
242
- var git = new LibGit2 ( ) ;
333
+ var trace = new NullTrace ( ) ;
334
+ var git = new LibGit2 ( trace ) ;
243
335
using ( var config = git . GetConfiguration ( repoPath ) )
244
336
{
245
337
string randomSection = Guid . NewGuid ( ) . ToString ( "N" ) ;
@@ -259,7 +351,8 @@ public void LibGit2Configuration_GetRepositoryPath_ReturnsRepositoryPath()
259
351
string fileL1Path = Path . Combine ( directoryL0Path , "inner-file.txt" ) ;
260
352
string directoryL1Path = Path . Combine ( directoryL0Path , "sub-directory" ) ;
261
353
262
- var git = new LibGit2 ( ) ;
354
+ var trace = new NullTrace ( ) ;
355
+ var git = new LibGit2 ( trace ) ;
263
356
264
357
// Create files and directories
265
358
Directory . CreateDirectory ( directoryL0Path ) ;
0 commit comments