@@ -16,22 +16,20 @@ public async Task ShouldCopyOnlyChangedFilesAndGenerateManifest()
1616 Directory . CreateDirectory ( source ) ;
1717 Directory . CreateDirectory ( target ) ;
1818
19- // Create one changed file and one unchanged file
2019 File . WriteAllText ( Path . Combine ( source , "Test.dll" ) , "hello" ) ;
2120 File . WriteAllText ( Path . Combine ( target , "Test.dll" ) , "stale" ) ;
2221
2322 File . WriteAllText ( Path . Combine ( source , "Unchanged.dll" ) , "same" ) ;
2423 File . WriteAllText ( Path . Combine ( target , "Unchanged.dll" ) , "same" ) ;
2524
26- var updater = new RedistUpdater ( source , target , [ ] ) ;
25+ var updater = new RedistUpdater ( source , target , [ ] , [ "Test.dll" ] ) ;
2726 var ( updated , manifests ) = await updater . UpdateAsync ( ) ;
2827
2928 updated . ShouldContainKey ( Path . Combine ( source , "Test.dll" ) ) ;
3029 updated . ShouldNotContainKey ( Path . Combine ( source , "Unchanged.dll" ) ) ;
3130
3231 File . ReadAllText ( Path . Combine ( target , "Test.dll" ) ) . ShouldBe ( "hello" ) ;
3332
34- // Manifest checks
3533 manifests . ShouldContainKey ( "Test.dll" ) ;
3634 manifests . Count . ShouldBe ( 1 ) ;
3735
@@ -41,4 +39,70 @@ public async Task ShouldCopyOnlyChangedFilesAndGenerateManifest()
4139 var manifestContent = File . ReadAllText ( manifestPath ) ;
4240 manifestContent . ShouldContain ( "Test.dll" ) ;
4341 }
42+
43+ [ Fact ]
44+ public async Task ShouldOnlyUpdateSpecifiedFilesWhenUpdateFilesListProvided ( )
45+ {
46+ using var tempDir = new TempDir ( ) ;
47+ var sourceDir = tempDir . Path ;
48+ var source = Path . Combine ( sourceDir , "source" ) ;
49+ var target = Path . Combine ( sourceDir , "target" ) ;
50+ Directory . CreateDirectory ( source ) ;
51+ Directory . CreateDirectory ( target ) ;
52+
53+ File . WriteAllText ( Path . Combine ( source , "Test1.dll" ) , "hello1" ) ;
54+ File . WriteAllText ( Path . Combine ( target , "Test1.dll" ) , "stale1" ) ;
55+
56+ File . WriteAllText ( Path . Combine ( source , "Test2.dll" ) , "hello2" ) ;
57+ File . WriteAllText ( Path . Combine ( target , "Test2.dll" ) , "stale2" ) ;
58+
59+ File . WriteAllText ( Path . Combine ( source , "Test3.dll" ) , "hello3" ) ;
60+ File . WriteAllText ( Path . Combine ( target , "Test3.dll" ) , "stale3" ) ;
61+
62+ List < string > updateFiles = [ "Test1.dll" , "Test3.dll" ] ;
63+ var updater = new RedistUpdater ( source , target , [ ] , updateFiles ) ;
64+ var ( updated , manifests ) = await updater . UpdateAsync ( ) ;
65+
66+ updated . ShouldContainKey ( Path . Combine ( source , "Test1.dll" ) ) ;
67+ updated . ShouldContainKey ( Path . Combine ( source , "Test3.dll" ) ) ;
68+ updated . ShouldNotContainKey ( Path . Combine ( source , "Test2.dll" ) ) ;
69+
70+ File . ReadAllText ( Path . Combine ( target , "Test1.dll" ) ) . ShouldBe ( "hello1" ) ;
71+ File . ReadAllText ( Path . Combine ( target , "Test3.dll" ) ) . ShouldBe ( "hello3" ) ;
72+ File . ReadAllText ( Path . Combine ( target , "Test2.dll" ) ) . ShouldBe ( "stale2" ) ;
73+
74+ manifests . ShouldContainKey ( "Test1.dll" ) ;
75+ manifests . ShouldContainKey ( "Test3.dll" ) ;
76+ manifests . ShouldNotContainKey ( "Test2.dll" ) ;
77+ manifests . Count . ShouldBe ( 2 ) ;
78+
79+ var manifestPath = Path . Combine ( target , "manifest.sha256.json" ) ;
80+ File . Exists ( manifestPath ) . ShouldBeTrue ( ) ;
81+
82+ var manifestContent = File . ReadAllText ( manifestPath ) ;
83+ manifestContent . ShouldContain ( "Test1.dll" ) ;
84+ manifestContent . ShouldContain ( "Test3.dll" ) ;
85+ manifestContent . ShouldNotContain ( "Test2.dll" ) ;
86+ }
87+
88+ [ Fact ]
89+ public async Task ShouldThrowExceptionWhenSpecifiedFileDoesNotExist ( )
90+ {
91+ using var tempDir = new TempDir ( ) ;
92+ var sourceDir = tempDir . Path ;
93+ var source = Path . Combine ( sourceDir , "source" ) ;
94+ var target = Path . Combine ( sourceDir , "target" ) ;
95+ Directory . CreateDirectory ( source ) ;
96+ Directory . CreateDirectory ( target ) ;
97+
98+ File . WriteAllText ( Path . Combine ( source , "Test1.dll" ) , "hello1" ) ;
99+ File . WriteAllText ( Path . Combine ( target , "Test1.dll" ) , "stale1" ) ;
100+
101+ List < string > updateFiles = [ "Test1.dll" , "NonExistent.dll" ] ;
102+ var updater = new RedistUpdater ( source , target , [ ] , updateFiles ) ;
103+
104+ var exception = await Assert . ThrowsAsync < FileNotFoundException > ( ( ) => updater . UpdateAsync ( ) ) ;
105+ exception . Message . ShouldContain ( "NonExistent.dll" ) ;
106+ exception . Message . ShouldContain ( "-update-files" ) ;
107+ }
44108}
0 commit comments