1+ using System . Collections . Generic ;
2+ using System . Net ;
3+ using System . Threading . Tasks ;
14using DataPipelineTools . Tests . Common ;
25using NUnit . Framework ;
6+ using SqlCollaborative . Azure . DataPipelineTools . DataLake ;
7+ using SqlCollaborative . Azure . DataPipelineTools . Functions . DataLake ;
38
49namespace DataPipelineTools . Functions . Tests . Integration . DataLake
510{
@@ -8,8 +13,172 @@ namespace DataPipelineTools.Functions.Tests.Integration.DataLake
813 [ Parallelizable ( ParallelScope . Children ) ]
914 public class DataLakeCheckPathCaseIntegrationTests : DataLakeIntegrationTestBase
1015 {
11- protected override string FunctionUri => $ " { FunctionsAppUrl } /api/ DataLake/CheckPathCase";
16+ protected override string FunctionRelativeUri => " DataLake/CheckPathCase";
1217
1318
19+ [ Test ]
20+ // Test all combos of leading slashes
21+ [ TestCase ( "TestData/TestFolder1/TestDoc1.txt" ) ]
22+ [ TestCase ( "/TestData/TestFolder1/TestDoc1.txt" ) ]
23+ public async Task Given_ValidFilePath_Should_ReturnSamePath ( string testPath )
24+ {
25+ var parameters = new Dictionary < string , string >
26+ {
27+ { DataLakeConfigFactory . AccountParam , StorageAccountName } ,
28+ { DataLakeConfigFactory . ContainerParam , StorageContainerName } ,
29+ { DataLakeConfigFactory . PathParam , testPath }
30+ } ;
31+ var response = await RunQueryFromParameters ( parameters ) ;
32+ LogContent ( response ) ;
33+ Assert . AreEqual ( HttpStatusCode . OK , response . StatusCode ) ;
34+
35+ // Check response details. Its important to cast the actual or we test against JToken from the dynamic results
36+ dynamic results = GetResultsObject ( response ) ;
37+
38+
39+ Assert . IsNull ( results . error ) ;
40+ Assert . AreEqual ( testPath . Trim ( '/' ) , results . validatedPath ? . ToString ( ) ) ;
41+ }
42+
43+ [ Test ]
44+ // Test all combos of leading/trailing slashes
45+ [ TestCase ( "TestData/TestFolder1/" ) ]
46+ [ TestCase ( "TestData/TestFolder1" ) ]
47+ [ TestCase ( "/TestData/TestFolder1/" ) ]
48+ [ TestCase ( "/TestData/TestFolder1" ) ]
49+ public async Task Given_ValidFolderPath_Should_ReturnSamePath ( string testPath )
50+ {
51+ var parameters = new Dictionary < string , string >
52+ {
53+ { DataLakeConfigFactory . AccountParam , StorageAccountName } ,
54+ { DataLakeConfigFactory . ContainerParam , StorageContainerName } ,
55+ { DataLakeConfigFactory . PathParam , testPath }
56+ } ;
57+ var response = await RunQueryFromParameters ( parameters ) ;
58+ LogContent ( response ) ;
59+ Assert . AreEqual ( HttpStatusCode . OK , response . StatusCode ) ;
60+
61+ // Check response details. Its important to cast the actual or we test against JToken from the dynamic results
62+ dynamic results = GetResultsObject ( response ) ;
63+
64+
65+ Assert . IsNull ( results . error ) ;
66+ Assert . AreEqual ( testPath . Trim ( '/' ) , results . validatedPath ? . ToString ( ) ) ;
67+ }
68+
69+ [ Test ]
70+ public async Task Given_NonExistentPath_Should_ReturnBadRequest ( )
71+ {
72+ var parameters = new Dictionary < string , string >
73+ {
74+ { DataLakeConfigFactory . AccountParam , StorageAccountName } ,
75+ { DataLakeConfigFactory . ContainerParam , StorageContainerName } ,
76+ { DataLakeConfigFactory . PathParam , "/SomeMadeUpPath" }
77+ } ;
78+ var response = await RunQueryFromParameters ( parameters ) ;
79+ LogContent ( response ) ;
80+ Assert . AreEqual ( HttpStatusCode . BadRequest , response . StatusCode ) ;
81+
82+ // Check response details. Its important to cast the actual or we test against JToken from the dynamic results
83+ dynamic results = GetResultsObject ( response ) ;
84+
85+
86+ Assert . AreEqual ( DataLakeFunctions . PathNotFoundErrorMessage , results . error ? . ToString ( ) ) ;
87+ Assert . IsNull ( results . validatedPath ? . ToString ( ) ) ;
88+ }
89+
90+ [ Test ]
91+ [ TestCase ( "TESTDATA/TestFolder1/" ) ]
92+ [ TestCase ( "TestData/TESTFOLDER1" ) ]
93+ [ TestCase ( "/TESTDATA/TestFolder1/" ) ]
94+ [ TestCase ( "/TestData/TESTFOLDER1" ) ]
95+ public async Task Given_FolderPath_With_WrongCaseAndSingleMatch_Should_ReturnValidPath ( string testPath )
96+ {
97+ var parameters = new Dictionary < string , string >
98+ {
99+ { DataLakeConfigFactory . AccountParam , StorageAccountName } ,
100+ { DataLakeConfigFactory . ContainerParam , StorageContainerName } ,
101+ { DataLakeConfigFactory . PathParam , testPath }
102+ } ;
103+ var response = await RunQueryFromParameters ( parameters ) ;
104+ LogContent ( response ) ;
105+ Assert . AreEqual ( HttpStatusCode . OK , response . StatusCode ) ;
106+
107+ // Check response details. Its important to cast the actual or we test against JToken from the dynamic results
108+ dynamic results = GetResultsObject ( response ) ;
109+
110+ Assert . AreEqual ( "TestData/TestFolder1" , results . validatedPath ? . ToString ( ) ) ;
111+ }
112+
113+ [ Test ]
114+ [ TestCase ( "TESTDATA/TestFolder1/TestDoc1.txt" ) ]
115+ [ TestCase ( "TestData/TESTFOLDER1/TestDoc1.txt" ) ]
116+ [ TestCase ( "TestData/TestFolder1/TESTDOC1.txt" ) ]
117+ [ TestCase ( "/TESTDATA/TestFolder1/TestDoc1.txt" ) ]
118+ [ TestCase ( "/TestData/TESTFOLDER1/TestDoc1.txt" ) ]
119+ [ TestCase ( "/TestData/TestFolder1/TESTDOC1.txt" ) ]
120+ public async Task Given_FilePath_With_WrongCaseAndSingleMatch_Should_ReturnValidPath ( string testPath )
121+ {
122+ var parameters = new Dictionary < string , string >
123+ {
124+ { DataLakeConfigFactory . AccountParam , StorageAccountName } ,
125+ { DataLakeConfigFactory . ContainerParam , StorageContainerName } ,
126+ { DataLakeConfigFactory . PathParam , testPath }
127+ } ;
128+ var response = await RunQueryFromParameters ( parameters ) ;
129+ LogContent ( response ) ;
130+ Assert . AreEqual ( HttpStatusCode . OK , response . StatusCode ) ;
131+
132+ // Check response details. Its important to cast the actual or we test against JToken from the dynamic results
133+ dynamic results = GetResultsObject ( response ) ;
134+
135+ Assert . AreEqual ( "TestData/TestFolder1/TestDoc1.txt" , results . validatedPath ? . ToString ( ) ) ;
136+ }
137+
138+ [ Test ]
139+ [ TestCase ( "TestData/TESTFOLDERCASEDUPES/TestDoc3.txt" ) ]
140+ [ TestCase ( "TestData/TESTFOLDERCASEDUPES/TestDoc4.txt" ) ]
141+ public async Task Given_FilePath_With_WrongCaseAndMultipleMatches_Should_ReturnError ( string testPath )
142+ {
143+ var parameters = new Dictionary < string , string >
144+ {
145+ { DataLakeConfigFactory . AccountParam , StorageAccountName } ,
146+ { DataLakeConfigFactory . ContainerParam , StorageContainerName } ,
147+ { DataLakeConfigFactory . PathParam , testPath }
148+ } ;
149+ var response = await RunQueryFromParameters ( parameters ) ;
150+ LogContent ( response ) ;
151+ Assert . AreEqual ( HttpStatusCode . BadRequest , response . StatusCode ) ;
152+
153+ // Check response details. Its important to cast the actual or we test against JToken from the dynamic results
154+ dynamic results = GetResultsObject ( response ) ;
155+
156+ Assert . AreEqual ( DataLakeService . ErrorMessage . MultipleFileMatchesWithCaseInsensitiveCompare , results . error ? . ToString ( ) ) ;
157+ }
158+
159+ [ Test ]
160+ [ TestCase ( "TestData/TESTFOLDERCASEDUPES" ) ]
161+ [ TestCase ( "TestData/TESTFOLDERCASEDUPES/" ) ]
162+ [ TestCase ( "/TestData/TESTFOLDERCASEDUPES" ) ]
163+ [ TestCase ( "testdata/TestFolderCaseDupes" ) ]
164+ [ TestCase ( "testdata/TestFolderCaseDupes/" ) ]
165+ [ TestCase ( "/testdata/TestFolderCaseDupes" ) ]
166+ public async Task Given_FolderPath_With_WrongCaseAndMultipleMatches_Should_ReturnError ( string testPath )
167+ {
168+ var parameters = new Dictionary < string , string >
169+ {
170+ { DataLakeConfigFactory . AccountParam , StorageAccountName } ,
171+ { DataLakeConfigFactory . ContainerParam , StorageContainerName } ,
172+ { DataLakeConfigFactory . PathParam , testPath }
173+ } ;
174+ var response = await RunQueryFromParameters ( parameters ) ;
175+ LogContent ( response ) ;
176+ Assert . AreEqual ( HttpStatusCode . BadRequest , response . StatusCode ) ;
177+
178+ // Check response details. Its important to cast the actual or we test against JToken from the dynamic results
179+ dynamic results = GetResultsObject ( response ) ;
180+
181+ Assert . AreEqual ( DataLakeService . ErrorMessage . MultipleDirectoryMatchesWithCaseInsensitiveCompare , results . error ? . ToString ( ) ) ;
182+ }
14183 }
15184}
0 commit comments