5
5
using Newtonsoft . Json ;
6
6
using Newtonsoft . Json . Linq ;
7
7
using NUnit . Framework ;
8
+ using SqlCollaborative . Azure . DataPipelineTools . Common ;
8
9
using SqlCollaborative . Azure . DataPipelineTools . DataLake ;
9
10
using SqlCollaborative . Azure . DataPipelineTools . DataLake . Model ;
10
11
@@ -46,21 +47,123 @@ public void Given_ValidDirectoryPath_Should_ReturnContents()
46
47
Assert . That ( result . Count , Is . EqualTo ( 2 ) ) ;
47
48
}
48
49
50
+ private static DataLakeGetItemsConfig [ ] DirectoryPathWithIncorrectCase =
51
+ {
52
+ new DataLakeGetItemsConfig { Directory = "RAW/api/feb" } ,
53
+ new DataLakeGetItemsConfig { Directory = "raw/API/feb" } ,
54
+ new DataLakeGetItemsConfig { Directory = "raw/api/FEB" }
55
+ } ;
56
+ [ TestCaseSource ( nameof ( DirectoryPathWithIncorrectCase ) ) ]
57
+ public void Given_DirectoryPathWithIncorrectCase_Should_ReturnContentsForCorrectedPath ( DataLakeGetItemsConfig itemsConfig )
58
+ {
59
+ var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
60
+
61
+ Assert . That ( result . FileCount , Is . EqualTo ( 1 ) ) ;
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 ) ) ;
64
+ }
65
+
66
+
49
67
[ Test ]
50
- public void Given_DirectoryPathWithIncorrectCase_Should_ReturnContentsForCorrectedPath ( )
68
+ public void Given_InvalidDirectoryPath_Should_ThrowException ( )
51
69
{
52
70
var itemsConfig = new DataLakeGetItemsConfig
53
71
{
54
- Directory = "raw/aPi/feb "
72
+ Directory = "some/invalid/path "
55
73
} ;
56
74
75
+ Assert . CatchAsync ( ( ) => Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) ) ;
76
+ }
77
+
78
+ [ Test ]
79
+ public void Given_DirectoryPathWithIncorrectCase_When_MatchesMultipleDirectories_Should_ThrowException ( )
80
+ {
81
+ var itemsConfig = new DataLakeGetItemsConfig
82
+ {
83
+ Directory = "RAW/api/JAN"
84
+ } ;
85
+
86
+ Assert . CatchAsync ( ( ) => Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) ) ;
87
+ }
88
+
89
+
90
+
91
+ private static object [ ] LimitNRecords =
92
+ {
93
+ new object [ ] { new DataLakeGetItemsConfig { Directory = "raw/api/jan" , Limit = 1 } , 1 } ,
94
+ new object [ ] { new DataLakeGetItemsConfig { Directory = "raw/api/jan" , Limit = 3 } , 3 } ,
95
+ new object [ ] { new DataLakeGetItemsConfig { Directory = "raw/api/jan" , Limit = 5 } , 5 } ,
96
+ new object [ ] { new DataLakeGetItemsConfig { Directory = "raw/api/jan" , Limit = 10 } , 5 } // There's 5 files for that folder in the test csv
97
+ } ;
98
+ [ TestCaseSource ( nameof ( LimitNRecords ) ) ]
99
+ public void Given_LimitNRecords_Should_ReturnNRecords ( DataLakeGetItemsConfig itemsConfig , int expectedResultCount )
100
+ {
57
101
var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
58
102
59
- Assert . That ( result . fileCount , Is . EqualTo ( 1 ) ) ;
60
- Assert . That ( result . files . Count , Is . EqualTo ( 1 ) ) ;
61
- Assert . That ( result . files . Count ( x => x . FullPath == "raw/api/feb/delta_extract_3.json" ) , Is . EqualTo ( 1 ) ) ;
103
+ Assert . That ( result . FileCount , Is . EqualTo ( expectedResultCount ) ) ;
62
104
}
63
105
106
+
107
+ private static object [ ] OrderByColumn =
108
+ {
109
+ new object [ ] { new DataLakeGetItemsConfig { Directory = "raw/api/jan" , OrderByColumn = "ContentLength" } , new [ ] { 10 , 20 , 30 , 40 , 50 } } , // Default is ascending order
110
+ new object [ ] { new DataLakeGetItemsConfig { Directory = "raw/api/jan" , OrderByColumn = "ContentLength" , OrderByDescending = false } , new [ ] { 10 , 20 , 30 , 40 , 50 } } ,
111
+ new object [ ] { new DataLakeGetItemsConfig { Directory = "raw/api/jan" , OrderByColumn = "ContentLength" , OrderByDescending = true } , new [ ] { 50 , 40 , 30 , 20 , 10 } }
112
+ } ;
113
+ [ TestCaseSource ( nameof ( OrderByColumn ) ) ]
114
+ public void Given_OrderBy_Should_ReturnRecordsOrderedBySpecifiedColumnWithDirectionSpecifiedByOrderByDescendingFlag ( DataLakeGetItemsConfig itemsConfig , int [ ] expectedContentLengths )
115
+ {
116
+ var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
117
+
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
+ }
122
+
123
+
124
+ private static object [ ] LimitNRecordsAndOrderByColumn =
125
+ {
126
+ new object [ ] { new DataLakeGetItemsConfig { Directory = "raw/api/jan" , OrderByColumn = "ContentLength" } , new [ ] { 10 , 20 , 30 } } , // Default is ascending order
127
+ new object [ ] { new DataLakeGetItemsConfig { Directory = "raw/api/jan" , OrderByColumn = "ContentLength" , OrderByDescending = false } , new [ ] { 10 , 20 , 30 , 40 } } ,
128
+ new object [ ] { new DataLakeGetItemsConfig { Directory = "raw/api/jan" , OrderByColumn = "ContentLength" , OrderByDescending = true } , new [ ] { 50 , 40 } }
129
+ } ;
130
+ [ TestCaseSource ( nameof ( LimitNRecordsAndOrderByColumn ) ) ]
131
+ public void Given_LimitNRecordAndOrderBy_Should_ReturnTopNRecordsOrderedBySpecifiedColumnWithDirectionSpecifiedByOrderByDescendingFlag ( DataLakeGetItemsConfig itemsConfig , int [ ] expectedContentLengths )
132
+ {
133
+ itemsConfig . Limit = expectedContentLengths . Length ;
134
+
135
+ var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
136
+
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 ] ) ) ;
140
+ }
141
+
142
+
143
+
144
+ [ Test ]
145
+ public void Given_RecursiveFlagIsTrue_Should_ReturnContentRecursively ( )
146
+ {
147
+ var itemsConfig = new DataLakeGetItemsConfig { Directory = "raw/database" , Recursive = true } ;
148
+ var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
149
+
150
+ Assert . That ( result . FileCount , Is . EqualTo ( 5 ) ) ;
151
+ }
152
+
153
+ [ Test ]
154
+ public void Given_RecursiveFlagIsFalse_Should_ReturnDirectoryContentsOnly ( )
155
+ {
156
+ var itemsConfig = new DataLakeGetItemsConfig { Directory = "raw/database" , Recursive = false } ;
157
+ var result = Sut . GetItemsAsync ( DatalakeConfig , itemsConfig ) . Result . ToObject < GetItemsResponse > ( ) ;
158
+
159
+ Assert . That ( result . FileCount , Is . EqualTo ( 2 ) ) ;
160
+ Assert . That ( result . Files . All ( x => x . Directory == itemsConfig . Directory ) , Is . True ) ;
161
+ }
162
+
163
+
164
+
165
+
166
+ //Filters = new[] {FilterFactory<DataLakeItem>.Create("Name", "like:*1*", MockLogger.Object)}
64
167
//[Test]
65
168
//public void Given_ValidDirectoryPath_Should_ReturnDirectoryPath()
66
169
//{
@@ -74,8 +177,8 @@ public void Given_DirectoryPathWithIncorrectCase_Should_ReturnContentsForCorrect
74
177
75
178
public class GetItemsResponse
76
179
{
77
- public int fileCount { get ; set ; }
78
- public string correctedFilePath { get ; set ; }
79
- public List < DataLakeItem > files { get ; set ; }
180
+ public int FileCount { get ; set ; }
181
+ public string CorrectedFilePath { get ; set ; }
182
+ public List < DataLakeItem > Files { get ; set ; }
80
183
}
81
184
}
0 commit comments