1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
- using System . Linq ;
5
4
using LibGit2Sharp . Tests . TestHelpers ;
6
5
using Xunit ;
7
6
@@ -11,12 +10,10 @@ public class FilterFixture : BaseFixture
11
10
{
12
11
private const int GitPassThrough = - 30 ;
13
12
14
- readonly Func < FilterSource , IEnumerable < string > , int > checkPassThrough = ( source , attr ) => GitPassThrough ;
15
13
readonly Func < Stream , Stream , int > successCallback = ( reader , writer ) => 0 ;
16
- readonly Func < FilterSource , IEnumerable < string > , int > checkSuccess = ( source , attr ) => 0 ;
17
14
18
15
private const string FilterName = "the-filter" ;
19
- readonly List < string > attributes = new List < string > { "test" } ;
16
+ readonly List < FilterAttribute > attributes = new List < FilterAttribute > { new FilterAttribute ( "test" ) } ;
20
17
21
18
[ Fact ]
22
19
public void CanRegisterFilterWithSingleAttribute ( )
@@ -55,101 +52,6 @@ public void SameFilterIsEqual()
55
52
Assert . Equal ( filter , filter ) ;
56
53
}
57
54
58
- [ Fact ]
59
- public void CheckCallbackNotMadeWhenFileStagedAndFilterNotRegistered ( )
60
- {
61
- bool called = false ;
62
- Func < FilterSource , IEnumerable < string > , int > callback = ( source , attr ) =>
63
- {
64
- called = true ;
65
- return GitPassThrough ;
66
- } ;
67
-
68
- string repoPath = InitNewRepository ( ) ;
69
-
70
- new FakeFilter ( FilterName + 4 , attributes , callback ) ;
71
-
72
- using ( var repo = CreateTestRepository ( repoPath ) )
73
- {
74
- StageNewFile ( repo ) ;
75
- }
76
-
77
- Assert . False ( called ) ;
78
- }
79
-
80
- [ Fact ]
81
- public void CheckCallbackMadeWhenFileStaged ( )
82
- {
83
- bool called = false ;
84
- Func < FilterSource , IEnumerable < string > , int > checkCallBack = ( source , attr ) =>
85
- {
86
- called = true ;
87
- return GitPassThrough ;
88
- } ;
89
- string repoPath = InitNewRepository ( ) ;
90
-
91
- var filter = new FakeFilter ( FilterName + 5 , attributes , checkCallBack ) ;
92
-
93
- var filterRegistration = GlobalSettings . RegisterFilter ( filter ) ;
94
- using ( var repo = CreateTestRepository ( repoPath ) )
95
- {
96
- StageNewFile ( repo ) ;
97
- Assert . True ( called ) ;
98
- }
99
-
100
- GlobalSettings . DeregisterFilter ( filterRegistration ) ;
101
- }
102
-
103
- [ Fact ]
104
- public void ApplyCallbackMadeWhenCheckCallbackReturnsZero ( )
105
- {
106
- bool called = false ;
107
-
108
- Func < Stream , Stream , int > applyCallback = ( reader , writer ) =>
109
- {
110
- called = true ;
111
- return 0 ; //successCallback
112
- } ;
113
-
114
- string repoPath = InitNewRepository ( ) ;
115
- var filter = new FakeFilter ( FilterName + 6 , attributes , checkSuccess , applyCallback ) ;
116
-
117
- var filterRegistration = GlobalSettings . RegisterFilter ( filter ) ;
118
- using ( var repo = CreateTestRepository ( repoPath ) )
119
- {
120
- StageNewFile ( repo ) ;
121
- }
122
-
123
- GlobalSettings . DeregisterFilter ( filterRegistration ) ;
124
-
125
- Assert . True ( called ) ;
126
- }
127
-
128
- [ Fact ]
129
- public void ApplyCallbackNotMadeWhenCheckCallbackReturnsPassThrough ( )
130
- {
131
- bool called = false ;
132
-
133
- Func < Stream , Stream , int > applyCallback = ( reader , writer ) =>
134
- {
135
- called = true ;
136
- return 0 ;
137
- } ;
138
-
139
- string repoPath = InitNewRepository ( ) ;
140
- var filter = new FakeFilter ( FilterName + 7 , attributes , checkPassThrough , applyCallback ) ;
141
-
142
- var filterRegistration = GlobalSettings . RegisterFilter ( filter ) ;
143
- using ( var repo = CreateTestRepository ( repoPath ) )
144
- {
145
- StageNewFile ( repo ) ;
146
- }
147
-
148
- GlobalSettings . DeregisterFilter ( filterRegistration ) ;
149
-
150
- Assert . False ( called ) ;
151
- }
152
-
153
55
[ Fact ]
154
56
public void InitCallbackNotMadeWhenFilterNeverUsed ( )
155
57
{
@@ -161,7 +63,6 @@ public void InitCallbackNotMadeWhenFilterNeverUsed()
161
63
} ;
162
64
163
65
var filter = new FakeFilter ( FilterName + 11 , attributes ,
164
- checkSuccess ,
165
66
successCallback ,
166
67
successCallback ,
167
68
initializeCallback ) ;
@@ -184,7 +85,6 @@ public void InitCallbackMadeWhenUsingTheFilter()
184
85
} ;
185
86
186
87
var filter = new FakeFilter ( FilterName + 12 , attributes ,
187
- checkSuccess ,
188
88
successCallback ,
189
89
successCallback ,
190
90
initializeCallback ) ;
@@ -202,68 +102,6 @@ public void InitCallbackMadeWhenUsingTheFilter()
202
102
GlobalSettings . DeregisterFilter ( filterRegistration ) ;
203
103
}
204
104
205
- [ Fact ]
206
- public void WhenStagingFileCheckIsCalledWithCleanForCorrectPath ( )
207
- {
208
- string repoPath = InitNewRepository ( ) ;
209
-
210
- var calledWithMode = FilterMode . Smudge ;
211
- string actualPath = string . Empty ;
212
- IEnumerable < string > actualAttributes = Enumerable . Empty < string > ( ) ;
213
- Func < FilterSource , IEnumerable < string > , int > callback = ( source , attr ) =>
214
- {
215
- calledWithMode = source . SourceMode ;
216
- actualPath = source . Path ;
217
- actualAttributes = attr ;
218
- return GitPassThrough ;
219
- } ;
220
-
221
- var filter = new FakeFilter ( FilterName + 13 , attributes , callback ) ;
222
-
223
- var filterRegistration = GlobalSettings . RegisterFilter ( filter ) ;
224
-
225
- using ( var repo = CreateTestRepository ( repoPath ) )
226
- {
227
- FileInfo expectedFile = StageNewFile ( repo ) ;
228
-
229
- Assert . Equal ( FilterMode . Clean , calledWithMode ) ;
230
- Assert . Equal ( expectedFile . Name , actualPath ) ;
231
- Assert . Equal ( attributes , actualAttributes ) ;
232
- }
233
-
234
- GlobalSettings . DeregisterFilter ( filterRegistration ) ;
235
- }
236
-
237
-
238
- [ Fact ]
239
- public void WhenCheckingOutAFileFileCheckIsCalledWithSmudgeForCorrectPath ( )
240
- {
241
- const string branchName = "branch" ;
242
- string repoPath = InitNewRepository ( ) ;
243
-
244
- var calledWithMode = FilterMode . Clean ;
245
- string actualPath = string . Empty ;
246
- IEnumerable < string > actualAttributes = Enumerable . Empty < string > ( ) ;
247
- Func < FilterSource , IEnumerable < string > , int > callback = ( source , attr ) =>
248
- {
249
- calledWithMode = source . SourceMode ;
250
- actualPath = source . Path ;
251
- actualAttributes = attr ;
252
- return GitPassThrough ;
253
- } ;
254
-
255
- var filter = new FakeFilter ( FilterName + 14 , attributes , callback ) ;
256
-
257
- var filterRegistration = GlobalSettings . RegisterFilter ( filter ) ;
258
-
259
- FileInfo expectedFile = CheckoutFileForSmudge ( repoPath , branchName , "hello" ) ;
260
- Assert . Equal ( FilterMode . Smudge , calledWithMode ) ;
261
- Assert . Equal ( expectedFile . FullName , actualPath ) ;
262
- Assert . Equal ( attributes , actualAttributes ) ;
263
-
264
- GlobalSettings . DeregisterFilter ( filterRegistration ) ;
265
- }
266
-
267
105
[ Fact ]
268
106
public void WhenStagingFileApplyIsCalledWithCleanForCorrectPath ( )
269
107
{
@@ -275,7 +113,7 @@ public void WhenStagingFileApplyIsCalledWithCleanForCorrectPath()
275
113
called = true ;
276
114
return GitPassThrough ;
277
115
} ;
278
- var filter = new FakeFilter ( FilterName + 15 , attributes , checkSuccess , clean ) ;
116
+ var filter = new FakeFilter ( FilterName + 15 , attributes , clean ) ;
279
117
280
118
var filterRegistration = GlobalSettings . RegisterFilter ( filter ) ;
281
119
@@ -298,7 +136,7 @@ public void CleanFilterWritesOutputToObjectTree()
298
136
299
137
Func < Stream , Stream , int > cleanCallback = SubstitutionCipherFilter . RotateByThirteenPlaces ;
300
138
301
- var filter = new FakeFilter ( FilterName + 16 , attributes , checkSuccess , cleanCallback ) ;
139
+ var filter = new FakeFilter ( FilterName + 16 , attributes , cleanCallback ) ;
302
140
303
141
var filterRegistration = GlobalSettings . RegisterFilter ( filter ) ;
304
142
@@ -328,7 +166,7 @@ public void WhenCheckingOutAFileFileSmudgeWritesCorrectFileToWorkingDirectory()
328
166
329
167
Func < Stream , Stream , int > smudgeCallback = SubstitutionCipherFilter . RotateByThirteenPlaces ;
330
168
331
- var filter = new FakeFilter ( FilterName + 17 , attributes , checkSuccess , null , smudgeCallback ) ;
169
+ var filter = new FakeFilter ( FilterName + 17 , attributes , null , smudgeCallback ) ;
332
170
var filterRegistration = GlobalSettings . RegisterFilter ( filter ) ;
333
171
334
172
FileInfo expectedFile = CheckoutFileForSmudge ( repoPath , branchName , encodedInput ) ;
@@ -361,7 +199,7 @@ public void FilterStreamsAreCoherent()
361
199
return GitPassThrough ;
362
200
} ;
363
201
364
- var filter = new FakeFilter ( FilterName + 18 , attributes , checkSuccess , assertor , assertor ) ;
202
+ var filter = new FakeFilter ( FilterName + 18 , attributes , assertor , assertor ) ;
365
203
366
204
var filterRegistration = GlobalSettings . RegisterFilter ( filter ) ;
367
205
@@ -433,36 +271,28 @@ private Repository CreateTestRepository(string path)
433
271
434
272
class EmptyFilter : Filter
435
273
{
436
- public EmptyFilter ( string name , IEnumerable < string > attributes )
274
+ public EmptyFilter ( string name , IEnumerable < FilterAttribute > attributes )
437
275
: base ( name , attributes )
438
276
{ }
439
277
}
440
278
441
279
class FakeFilter : Filter
442
280
{
443
- private readonly Func < FilterSource , IEnumerable < string > , int > checkCallBack ;
444
281
private readonly Func < Stream , Stream , int > cleanCallback ;
445
282
private readonly Func < Stream , Stream , int > smudgeCallback ;
446
283
private readonly Func < int > initCallback ;
447
284
448
- public FakeFilter ( string name , IEnumerable < string > attributes ,
449
- Func < FilterSource , IEnumerable < string > , int > checkCallBack = null ,
285
+ public FakeFilter ( string name , IEnumerable < FilterAttribute > attributes ,
450
286
Func < Stream , Stream , int > cleanCallback = null ,
451
287
Func < Stream , Stream , int > smudgeCallback = null ,
452
288
Func < int > initCallback = null )
453
289
: base ( name , attributes )
454
290
{
455
- this . checkCallBack = checkCallBack ;
456
291
this . cleanCallback = cleanCallback ;
457
292
this . smudgeCallback = smudgeCallback ;
458
293
this . initCallback = initCallback ;
459
294
}
460
295
461
- protected override int Check ( IEnumerable < string > attributes , FilterSource filterSource )
462
- {
463
- return checkCallBack != null ? checkCallBack ( filterSource , attributes ) : base . Check ( attributes , filterSource ) ;
464
- }
465
-
466
296
protected override int Clean ( string path , Stream input , Stream output )
467
297
{
468
298
return cleanCallback != null ? cleanCallback ( input , output ) : base . Clean ( path , input , output ) ;
0 commit comments