@@ -21,7 +21,7 @@ public class GetItemsAsyncTests : DataLakeTestBase
21
21
public GetItemsAsyncTests ( )
22
22
{
23
23
// Use the factory to inject the mock logger to get the mock client...
24
- var factory = new DataLakeServiceFactory ( MockLogger . Object ) ;
24
+ var factory = new DataLakeServiceFactory ( Logger ) ;
25
25
Sut = factory . CreateDataLakeService ( MockFileSystemClient . Object ) ;
26
26
}
27
27
@@ -35,7 +35,7 @@ public void Setup()
35
35
}
36
36
37
37
[ Test ]
38
- public void Given_ValidDirectoryPath_Should_ReturnContents ( )
38
+ public void Given_ValidDirectoryPath_Should_ReturnContentsAsJson ( )
39
39
{
40
40
var itemsConfig = new DataLakeGetItemsConfig
41
41
{
@@ -60,7 +60,7 @@ public void Given_DirectoryPathWithIncorrectCase_Should_ReturnContentsForCorrect
60
60
61
61
Assert . That ( result . FileCount , Is . EqualTo ( 1 ) ) ;
62
62
Assert . That ( result . Files . Count , Is . EqualTo ( 1 ) ) ;
63
- Assert . That ( result . Files . Count ( x => x . FullPath == "raw/api/feb/delta_extract_3.json" ) , Is . EqualTo ( 1 ) ) ;
63
+ Assert . That ( result . Files , Has . All . Property ( nameof ( DataLakeItem . FullPath ) ) . EqualTo ( "raw/api/feb/delta_extract_3.json" ) ) ;
64
64
}
65
65
66
66
@@ -101,6 +101,7 @@ public void Given_LimitNRecords_Should_ReturnNRecords(DataLakeGetItemsConfig ite
101
101
var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
102
102
103
103
Assert . That ( result . FileCount , Is . EqualTo ( expectedResultCount ) ) ;
104
+ Assert . That ( result . Files , Has . Count . EqualTo ( expectedResultCount ) ) ;
104
105
}
105
106
106
107
@@ -113,11 +114,13 @@ public void Given_LimitNRecords_Should_ReturnNRecords(DataLakeGetItemsConfig ite
113
114
[ TestCaseSource ( nameof ( OrderByColumn ) ) ]
114
115
public void Given_OrderBy_Should_ReturnRecordsOrderedBySpecifiedColumnWithDirectionSpecifiedByOrderByDescendingFlag ( DataLakeGetItemsConfig itemsConfig , int [ ] expectedContentLengths )
115
116
{
117
+ var expectedFileCount = expectedContentLengths . Length ;
118
+
116
119
var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
117
120
118
- Assert . That ( result . FileCount , Is . EqualTo ( expectedContentLengths . Length ) ) ;
119
- for ( int i = 0 ; i < 5 ; i ++ )
120
- Assert . That ( result . Files [ i ] . ContentLength , Is . EqualTo ( expectedContentLengths [ i ] ) ) ;
121
+ Assert . That ( result . FileCount , Is . EqualTo ( expectedFileCount ) ) ;
122
+ Assert . That ( result . Files , Has . Count . EqualTo ( expectedFileCount ) ) ;
123
+ Assert . That ( result . Files . Select ( item => item . ContentLength ) , Is . EquivalentTo ( expectedContentLengths ) ) ;
121
124
}
122
125
123
126
@@ -130,24 +133,24 @@ public void Given_OrderBy_Should_ReturnRecordsOrderedBySpecifiedColumnWithDirect
130
133
[ TestCaseSource ( nameof ( LimitNRecordsAndOrderByColumn ) ) ]
131
134
public void Given_LimitNRecordAndOrderBy_Should_ReturnTopNRecordsOrderedBySpecifiedColumnWithDirectionSpecifiedByOrderByDescendingFlag ( DataLakeGetItemsConfig itemsConfig , int [ ] expectedContentLengths )
132
135
{
133
- itemsConfig . Limit = expectedContentLengths . Length ;
136
+ var expectedFileCount = expectedContentLengths . Length ;
137
+ itemsConfig . Limit = expectedFileCount ;
134
138
135
139
var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
136
140
137
- Assert . That ( result . FileCount , Is . EqualTo ( expectedContentLengths . Length ) ) ;
138
- for ( int i = 0 ; i < expectedContentLengths . Length ; i ++ )
139
- Assert . That ( result . Files [ i ] . ContentLength , Is . EqualTo ( expectedContentLengths [ i ] ) ) ;
141
+ Assert . That ( result . FileCount , Is . EqualTo ( expectedFileCount ) ) ;
142
+ Assert . That ( result . Files , Has . Count . EqualTo ( expectedFileCount ) ) ;
143
+ Assert . That ( result . Files . Select ( item => item . ContentLength ) , Is . EquivalentTo ( expectedContentLengths ) ) ;
140
144
}
141
145
142
-
143
-
144
146
[ Test ]
145
147
public void Given_RecursiveFlagIsTrue_Should_ReturnContentRecursively ( )
146
148
{
147
149
var itemsConfig = new DataLakeGetItemsConfig { Directory = "raw/database" , Recursive = true } ;
148
150
var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
149
151
150
152
Assert . That ( result . FileCount , Is . EqualTo ( 5 ) ) ;
153
+ Assert . That ( result . Files , Has . Count . EqualTo ( 5 ) ) ;
151
154
}
152
155
153
156
[ Test ]
@@ -157,22 +160,154 @@ public void Given_RecursiveFlagIsFalse_Should_ReturnDirectoryContentsOnly()
157
160
var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
158
161
159
162
Assert . That ( result . FileCount , Is . EqualTo ( 2 ) ) ;
160
- Assert . That ( result . Files . All ( x => x . Directory == itemsConfig . Directory ) , Is . True ) ;
163
+ Assert . That ( result . Files , Has . Count . EqualTo ( 2 ) ) ;
164
+ Assert . That ( result . Files , Has . All . Property ( nameof ( DataLakeItem . Directory ) ) . EqualTo ( itemsConfig . Directory ) ) ;
165
+ }
166
+
167
+ [ Test ]
168
+ public void Given_DirectoryPathWithIncorrectCaseAndIgnoreDirectoryCaseIsFalse_Should_Throw ( )
169
+ {
170
+ var itemsConfig = new DataLakeGetItemsConfig { Directory = "raw/DATABASE" , IgnoreDirectoryCase = false } ;
171
+ Assert . CatchAsync ( ( ) => Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) ) ;
172
+ }
173
+
174
+ [ Test ]
175
+ public void Given_DirectoryPathWithIncorrectCaseAndIgnoreDirectoryCaseTrue_Should_ReturnContents ( )
176
+ {
177
+ var itemsConfig = new DataLakeGetItemsConfig { Directory = "raw/DATABASE" , IgnoreDirectoryCase = true } ;
178
+ var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
179
+
180
+ Assert . That ( result . FileCount , Is . GreaterThan ( 0 ) ) ;
181
+ Assert . That ( result . Files , Has . Count . GreaterThan ( 0 ) ) ;
182
+ }
183
+
184
+ [ Test ]
185
+ public void Given_DirectoryPathWithIncorrectCaseAndIgnoreDirectoryCaseIsTrue_WhenMatchesOneDirectoryPath_Should_ReturnCorrectedPath ( )
186
+ {
187
+ var itemsConfig = new DataLakeGetItemsConfig { Directory = "raw/DATABASE" , IgnoreDirectoryCase = true } ;
188
+ var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
189
+
190
+ Assert . That ( result . CorrectedFilePath , Is . EqualTo ( "raw/database" ) ) ;
161
191
}
162
192
193
+ [ Test ]
194
+ public void Given_DirectoryPathWithIncorrectCaseAndIgnoreDirectoryCaseIsTrue_WhenMatcheMultipleDirectoryPaths_Should_Throw ( )
195
+ {
196
+ var itemsConfig = new DataLakeGetItemsConfig { Directory = "raw/ApI" , IgnoreDirectoryCase = true } ;
197
+ Assert . CatchAsync ( ( ) => Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) ) ;
198
+ }
163
199
200
+
201
+
202
+ private static object [ ] [ ] Filters =
203
+ {
204
+ new object [ ] { "raw/api/jan" , nameof ( DataLakeItem . Name ) , "eq:delta_extract_4.json" , 1 } ,
205
+ new object [ ] { "raw/api/jan" , nameof ( DataLakeItem . Name ) , "ne:delta_extract_4.json" , 4 } ,
206
+ new object [ ] { "raw/api/jan" , nameof ( DataLakeItem . ContentLength ) , "gt:40" , 1 } ,
207
+ new object [ ] { "raw/api/jan" , nameof ( DataLakeItem . ContentLength ) , "ge:40" , 2 } ,
208
+ new object [ ] { "raw/api/jan" , nameof ( DataLakeItem . ContentLength ) , "lt:20" , 1 } ,
209
+ new object [ ] { "raw/api/jan" , nameof ( DataLakeItem . ContentLength ) , "le:20" , 2 } ,
210
+ new object [ ] { "raw/api" , nameof ( DataLakeItem . Directory ) , "like:*feb*" , 1 } ,
211
+ new object [ ] { "raw/api" , nameof ( DataLakeItem . FullPath ) , "like:delta_extract_[3-5].json" , 4 } ,
212
+ new object [ ] { "raw/api" , nameof ( DataLakeItem . Url ) , "like:.+raw\\ /api.+" , 8 } , // 6 files + 2 directories
213
+ new object [ ] { "raw/api" , nameof ( DataLakeItem . IsDirectory ) , "eq:true" , 2 } ,
214
+ new object [ ] { "raw/api" , nameof ( DataLakeItem . IsDirectory ) , "eq:false" , 6 } ,
215
+ new object [ ] { "raw/api" , nameof ( DataLakeItem . LastModified ) , "ge:2021-01-04T14:00:00" , 2 } ,
216
+ } ;
217
+ [ TestCaseSource ( nameof ( Filters ) ) ]
218
+ public void Given_Filter_Should_ReturnRecordsMatchingFilter ( string directory , string filterProperty , string filterExpression , int expectedFileCount )
219
+ {
220
+ // Have to build the filter here rather than pass it in using TestCaseSource as the logger is not static
221
+ var filter = FilterFactory < DataLakeItem > . Create ( filterProperty , filterExpression , Logger ) ;
222
+ var itemsConfig = new DataLakeGetItemsConfig { Directory = directory , Filters = new [ ] { filter } } ;
223
+
224
+ var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
225
+
226
+ Assert . That ( result . FileCount , Is . EqualTo ( expectedFileCount ) ) ;
227
+ Assert . That ( result . Files , Has . Count . EqualTo ( expectedFileCount ) ) ;
228
+ }
229
+
230
+ private static object [ ] [ ] InvalidFilters =
231
+ {
232
+ new object [ ] { "raw/api/jan" , nameof ( DataLakeItem . Name ) , "neq:delta_extract_4.json" } , // Invalid operator
233
+ new object [ ] { "raw/api/jan" , nameof ( DataLakeItem . ContentLength ) , "eq:delta_extract_4.json" } , // Invalid value type
234
+ new object [ ] { "raw/api/jan" , "Some invalid property" , "ne:delta_extract_4.json" } ,
235
+ new object [ ] { "raw/api/jan" , string . Empty , "ne:delta_extract_4.json" } ,
236
+ new object [ ] { "raw/api/jan" , null , "ne:delta_extract_4.json" } ,
237
+
238
+ new object [ ] { "raw/api/jan" , nameof ( DataLakeItem . Name ) , string . Empty } ,
239
+ new object [ ] { "raw/api/jan" , nameof ( DataLakeItem . Name ) , null } ,
240
+
241
+ } ;
242
+ [ TestCaseSource ( nameof ( InvalidFilters ) ) ]
243
+ public void Given_InvalidFilter_Should_Throw ( string directory , string filterProperty , string filterExpression )
244
+ {
245
+ // Have to build the filter here rather than pass it in using TestCaseSource as the logger is not static
246
+ var filter = FilterFactory < DataLakeItem > . Create ( filterProperty , filterExpression , Logger ) ;
247
+ var itemsConfig = new DataLakeGetItemsConfig { Directory = directory , Filters = new [ ] { filter } } ;
248
+
249
+ Assert . CatchAsync ( ( ) => Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) ) ;
250
+ }
251
+
252
+ [ TestCaseSource ( nameof ( InvalidFilters ) ) ]
253
+ public void Given_MultipleFilters_WhenSomeAreInvalid_Should_Throw ( string directory , string filterProperty , string filterExpression )
254
+ {
255
+ var filters = new [ ]
256
+ {
257
+ FilterFactory < DataLakeItem > . Create ( nameof ( DataLakeItem . FullPath ) , "like:*jan*" , Logger ) ,
258
+ FilterFactory < DataLakeItem > . Create ( nameof ( DataLakeItem . IsDirectory ) , "eq:5" , Logger ) ,
259
+ } ;
260
+ var itemsConfig = new DataLakeGetItemsConfig { Directory = "raw" , Filters = filters } ;
261
+
262
+ Assert . CatchAsync ( ( ) => Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) ) ;
263
+ }
264
+
265
+ [ Test ]
266
+ public void Given_MultipleValidFiltersOfDifferentTypes_Should_ReturnFilteredResults ( )
267
+ {
268
+ var filters = new [ ]
269
+ {
270
+ FilterFactory < DataLakeItem > . Create ( nameof ( DataLakeItem . FullPath ) , "like:*jan*" , Logger ) ,
271
+ FilterFactory < DataLakeItem > . Create ( nameof ( DataLakeItem . IsDirectory ) , "eq:true" , Logger ) ,
272
+ } ;
273
+ var itemsConfig = new DataLakeGetItemsConfig { Directory = "raw" , Filters = filters } ;
274
+ var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
275
+
276
+ Assert . That ( result . FileCount , Is . EqualTo ( 3 ) ) ;
277
+ Assert . That ( result . Files , Has . Count . EqualTo ( 3 ) ) ;
278
+
279
+ Assert . That ( result . Files , Has . All . Property ( nameof ( DataLakeItem . IsDirectory ) ) . True ) ;
280
+ }
281
+
282
+
283
+ [ Test ]
284
+ public void Given_MultipleValidFiltersOfSameType_Should_ReturnFilteredResults ( )
285
+ {
286
+ var filters = new [ ]
287
+ {
288
+ FilterFactory < DataLakeItem > . Create ( nameof ( DataLakeItem . FullPath ) , "like:*jan*" , Logger ) ,
289
+ FilterFactory < DataLakeItem > . Create ( nameof ( DataLakeItem . FullPath ) , "like:*delta" , Logger ) ,
290
+ } ;
291
+ var itemsConfig = new DataLakeGetItemsConfig { Directory = "raw" , Filters = filters } ;
292
+ var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
293
+
294
+ Assert . That ( result . FileCount , Is . EqualTo ( 6 ) ) ;
295
+ Assert . That ( result . Files , Has . Count . EqualTo ( 6 ) ) ;
296
+
297
+ Assert . That ( result . Files , Has . All . Property ( nameof ( DataLakeItem . FullPath ) ) . Contains ( "jan" ) ) ;
298
+ Assert . That ( result . Files , Has . All . Property ( nameof ( DataLakeItem . FullPath ) ) . Contains ( "delta" ) ) ;
299
+ }
164
300
165
301
166
- //Filters = new[] {FilterFactory<DataLakeItem>.Create("Name", "like:*1*", MockLogger.Object)}
167
302
//[Test]
168
- //public void Given_ValidDirectoryPath_Should_ReturnDirectoryPath ()
303
+ //public void Given__Should_Return ()
169
304
//{
170
- // var testPath = "raw/database";
171
- // var resultPath = Sut.CheckPathAsync(testPath, true ).Result;
305
+ // var itemsConfig = new DataLakeGetItemsConfig { Directory = "raw/database", Recursive = false } ;
306
+ // var result = Sut.GetItemsAsync(DatalakeConfig, itemsConfig ).Result.ToObject<GetItemsResponse>() ;
172
307
173
- // Assert.That(resultPath, Is.EqualTo(testPath));
308
+ // Assert.That(result.FileCount, Is.EqualTo(2));
309
+ // Assert.That(result.Files.All(x => x.Directory == itemsConfig.Directory), Is.True);
174
310
//}
175
-
176
311
}
177
312
178
313
public class GetItemsResponse
0 commit comments