@@ -24,11 +24,8 @@ public class DataLakeServiceTests: TestBase
24
24
private const string ContainerName = "mycontainer" ;
25
25
26
26
private readonly IEnumerable < PathItem > TestData ;
27
- private readonly Mock < DataLakeFileSystemClient > mockFileSystemClient ;
28
-
29
- //private readonly Mock<DataLakeDirectoryClient> mockDirectoryClient;
30
- //private readonly Mock<DataLakeFileClient> mockFileClient;
31
27
28
+ private readonly Mock < DataLakeFileSystemClient > mockFileSystemClient ;
32
29
private readonly Mock < ILogger < DataLakeServiceFactory > > mockLogger ;
33
30
34
31
private readonly DataLakeService Sut ;
@@ -64,14 +61,14 @@ private Mock<DataLakeFileSystemClient> BuildMockDataLakeFileSystemClient()
64
61
65
62
mockFileSystemClient
66
63
. Setup ( x => x . GetPaths ( It . IsAny < string > ( ) , It . IsAny < bool > ( ) , It . IsAny < bool > ( ) , It . IsAny < CancellationToken > ( ) ) )
67
- . Returns ( ( string p , bool r ) =>
64
+ . Returns ( ( string path , bool recursive , bool userPrinciaplName , CancellationToken token ) =>
68
65
{
69
66
var items = TestData
70
67
// Include all files starting with the test path
71
- . Where ( x => x . Name . StartsWith ( p ) )
68
+ . Where ( x => x . Name . StartsWith ( path ?? string . Empty ) && path != null )
72
69
// Still include them if the recursive flag is set, otherwise check if the relative path after the search path contains
73
70
// directory separator to exclude sub dirs
74
- . Where ( x => r || ! x . Name . Substring ( p . Length ) . Contains ( '/' ) )
71
+ . Where ( x => recursive || ! x . Name . Substring ( path . Length ) . Contains ( '/' ) )
75
72
. ToList ( )
76
73
. AsReadOnly ( ) ;
77
74
@@ -117,21 +114,7 @@ private IEnumerable<PathItem> GetTestData()
117
114
) ;
118
115
} ) . ToArray ( ) ;
119
116
}
120
-
121
- //private IEnumerable<DataLakeItem> GetTestData()
122
- // {
123
- // return GetTestData(",", properties =>
124
- // {
125
- // return new DataLakeItem()
126
- // {
127
- // Directory = properties[nameof(DataLakeItem.Directory)],
128
- // Name = properties[nameof(DataLakeItem.Name)],
129
- // IsDirectory = Convert.ToBoolean(properties[nameof(DataLakeItem.IsDirectory)]),
130
- // ContentLength = Convert.ToInt32(properties[nameof(DataLakeItem.ContentLength)]),
131
- // LastModified = Convert.ToDateTime(properties[nameof(DataLakeItem.LastModified)])
132
- // };
133
- // }).ToArray();
134
- // }
117
+
135
118
136
119
[ SetUp ]
137
120
public void Setup ( )
@@ -140,11 +123,50 @@ public void Setup()
140
123
}
141
124
142
125
[ Test ]
143
- public void CheckPathAsync_ShouldReturn_ ( )
126
+ public void CheckPathAsync_ShouldReturnThePath_WhenTheDirectoryPathExists ( )
144
127
{
128
+ var testPath = "raw/database" ;
129
+ var correctPath = Sut . CheckPathAsync ( testPath , true ) . Result ;
145
130
131
+ Assert . That ( testPath , Is . EqualTo ( correctPath ) ) ;
146
132
}
147
-
148
133
134
+ [ Test ]
135
+ public void CheckPathAsync_ShouldReturnThePath_WhenTheFilePathExists ( )
136
+ {
137
+ var testPath = "raw/database/jan/extract_1.csv" ;
138
+ var correctPath = Sut . CheckPathAsync ( testPath , false ) . Result ;
139
+
140
+ Assert . That ( testPath , Is . EqualTo ( correctPath ) ) ;
141
+ }
142
+
143
+ [ Test ]
144
+ public void CheckPathAsync_ShouldReturnNull_WhenTheIsDirectoryIsIncorrectlyFalse ( )
145
+ {
146
+ var testPath = "raw/database" ;
147
+ var correctPath = Sut . CheckPathAsync ( testPath , false ) . Result ;
148
+
149
+ Assert . That ( testPath , Is . EqualTo ( correctPath ) ) ;
150
+ }
151
+
152
+ [ Test ]
153
+ public void CheckPathAsync_ShouldReturnNull_WhenTheIsDirectoryIsIncorrectlyTrue ( )
154
+ {
155
+ var testPath = "raw/database/jan/extract_1.csv" ;
156
+ var correctPath = Sut . CheckPathAsync ( testPath , true ) . Result ;
157
+
158
+ Assert . That ( testPath , Is . EqualTo ( correctPath ) ) ;
159
+ }
160
+
161
+ [ Test ]
162
+ public void CheckPathAsync_ShouldReturnNull_WhenPathDoesNotExist ( )
163
+ {
164
+ var testPath = "some/invalid/path" ;
165
+ var correctPath = Sut . CheckPathAsync ( testPath , true ) . Result ;
166
+
167
+ Assert . That ( null , Is . EqualTo ( correctPath ) ) ;
168
+ }
169
+
170
+
149
171
}
150
172
}
0 commit comments