@@ -7,38 +7,39 @@ namespace AgDatabaseMove.Unit
77
88 public class BackupFileToolsTest
99 {
10- public static IEnumerable < object [ ] > UrlFileExamples => new List < object [ ] > {
11- new object [ ] { "https://hello/a.bak" } ,
12- new object [ ] { "https://hello/a.full" } ,
13- new object [ ] { "https://storage-account.blob.core.windows.net/container/file.trn" } ,
14- new object [ ] { "https://hello/a.diff" } ,
15- new object [ ] { "https://a.diff" } ,
16- new object [ ] { "https://1/2/3/4/5/a.diff" } ,
17- new object [ ] { "https://storage-account.blob.core.windows.net/container/file.bad" } ,
18- new object [ ]
19- { "https://storage-account.blob.core.windows.net/container/sql/db_name/backup_2020_09_02_170003_697.trn" } ,
20- new object [ ] { "http://hello/a.bak" }
21- } ;
22-
23- public static IEnumerable < object [ ] > NonUrlFileExamples => new List < object [ ] > {
24- new object [ ] { @"c:\hello\a.bak" } ,
25- new object [ ] { @"\\abc\hello/a.bak" } ,
26- new object [ ] { "https://storage-account.blob.core.windows.net/container" } ,
27- new object [ ] { "http://storage-account.blob.core.windows.net/container" }
28- } ;
2910
3011 [ Theory ]
31- [ MemberData ( nameof ( UrlFileExamples ) ) ]
32- public void UrlFilesAreUrl ( string file )
12+ [ InlineData ( @"https://hello/a.bak" ) ]
13+ [ InlineData ( @"https://hello/a.full" ) ]
14+ [ InlineData ( @"https://storage-account.blob.core.windows.net/container/file.trn" ) ]
15+ [ InlineData ( @"https://hello/a.diff" ) ]
16+ [ InlineData ( @"https://1/2/3/4/5/a.diff" ) ]
17+ [ InlineData ( @"https://storage-account.blob.core.windows.net/container/file.bad" ) ]
18+ [ InlineData ( @"https://storage-account.blob.core.windows.net/container/sql/db_name/backup_2020_09_02_170003_697.trn" ) ]
19+ [ InlineData ( @"http://a.bak" ) ]
20+ [ InlineData ( @"\\UNC\syntax\path\file.ext" ) ]
21+ [ InlineData ( @"\\server\file.ext" ) ]
22+ [ InlineData ( @"//Unix/syntax/file.ext" ) ]
23+ public void ValidUrlTests ( string url )
3324 {
34- Assert . True ( BackupFileTools . IsUrl ( file ) ) ;
25+ Assert . True ( BackupFileTools . IsValidFileUrl ( url ) ) ;
3526 }
3627
3728 [ Theory ]
38- [ MemberData ( nameof ( NonUrlFileExamples ) ) ]
39- public void NonUrlFilesAreNotUrl ( string file )
29+ [ InlineData ( @"" ) ]
30+ [ InlineData ( @" " ) ]
31+ [ InlineData ( @"c:\hello\a.bak" ) ]
32+ [ InlineData ( @"\\C:/" ) ]
33+ [ InlineData ( @"\wrongUNC\file.txt" ) ]
34+ [ InlineData ( @"/wrongUNC/file.txt" ) ]
35+ [ InlineData ( @"\\server\dir" ) ]
36+ [ InlineData ( @"\\server\dir\" ) ]
37+ [ InlineData ( @"https://storage-account.blob.core.windows.net/dir" ) ]
38+ [ InlineData ( @"http://storage-account.blob.core.windows.net/dir" ) ]
39+ [ InlineData ( @"http://storage-account.blob.core.windows.net/dir/" ) ]
40+ public void InvalidUrlTests ( string url )
4041 {
41- Assert . False ( BackupFileTools . IsUrl ( file ) ) ;
42+ Assert . False ( BackupFileTools . IsValidFileUrl ( url ) ) ;
4243 }
4344
4445 [ Theory ]
@@ -58,5 +59,32 @@ public void BackupTypeAbbrevToType(string abbrev, BackupFileTools.BackupType typ
5859 {
5960 Assert . Equal ( type , BackupFileTools . BackupTypeAbbrevToType ( abbrev ) ) ;
6061 }
62+
63+ [ Theory ]
64+ [ InlineData ( @"C:\dir\file.ext" ) ]
65+ [ InlineData ( @"/some/file.ext" ) ]
66+
67+ public void ValidPathTests ( string path )
68+ {
69+ Assert . True ( BackupFileTools . IsValidFilePath ( path ) ) ;
70+ }
71+
72+ [ Theory ]
73+ [ InlineData ( @"" ) ]
74+ [ InlineData ( @" " ) ]
75+ [ InlineData ( @"/dir" ) ]
76+ [ InlineData ( @"/" ) ]
77+ [ InlineData ( @"file.ext" ) ]
78+ [ InlineData ( @"dir\file.ext" ) ]
79+ [ InlineData ( @"C dir\file.ext" ) ]
80+ [ InlineData ( @"dir" ) ]
81+ [ InlineData ( @"C:\dir\" ) ]
82+ [ InlineData ( @"C:\dir" ) ]
83+ [ InlineData ( @"C:\" ) ]
84+ [ InlineData ( @"C:\inval|d" ) ]
85+ public void InValidPathTests ( string path )
86+ {
87+ Assert . False ( BackupFileTools . IsValidFilePath ( path ) ) ;
88+ }
6189 }
6290}
0 commit comments