@@ -6,6 +6,7 @@ namespace Microsoft.WingetCreateTests
66 using System ;
77 using System . Collections . Generic ;
88 using System . IO ;
9+ using System . IO . Compression ;
910 using System . Linq ;
1011 using System . Net ;
1112 using System . Net . Http ;
@@ -138,5 +139,79 @@ public static string MockDownloadFile(string filename)
138139 string downloadedPath = PackageParser . DownloadFileAsync ( url ) . Result ;
139140 return downloadedPath ;
140141 }
142+
143+ /// <summary>
144+ /// Creates copies of the specified resource file. If multiple copies are requested, the new files will be named with a numeric suffix.
145+ /// </summary>
146+ /// <param name="resource">Name of the resource file to copy.</param>
147+ /// <param name="numberOfCopies">Number of copies to create.</param>
148+ /// <param name="newResourceName">Optional new name for the copied resource file.</param>
149+ /// <returns>List of paths to the newly created files.</returns>
150+ public static List < string > CreateResourceCopy ( string resource , int numberOfCopies = 1 , string newResourceName = null )
151+ {
152+ string originalResourcePath = GetTestFile ( resource ) ;
153+ string newResourcePath = originalResourcePath ;
154+ if ( ! string . IsNullOrEmpty ( newResourceName ) )
155+ {
156+ newResourcePath = Path . Combine ( Path . GetDirectoryName ( originalResourcePath ) , newResourceName ) ;
157+ }
158+
159+ List < string > copyPaths = new ( ) ;
160+ for ( int i = 0 ; i < numberOfCopies ; i ++ )
161+ {
162+ string copyPath = PackageParser . GetNumericFilename ( newResourcePath ) ;
163+ File . Copy ( originalResourcePath , copyPath ) ;
164+ copyPaths . Add ( copyPath ) ;
165+ }
166+
167+ return copyPaths ;
168+ }
169+
170+ /// <summary>
171+ /// Adds files to an existing test zip archive.
172+ /// </summary>
173+ /// <param name="zipResourceName">Name of the zip resource file.</param>
174+ /// <param name="filePaths">List of paths for files to be included in the zip archive.</param>
175+ public static void AddFilesToZip ( string zipResourceName , List < string > filePaths )
176+ {
177+ string zipPath = GetTestFile ( zipResourceName ) ;
178+ using ( ZipArchive zipArchive = ZipFile . Open ( zipPath , ZipArchiveMode . Update ) )
179+ {
180+ foreach ( string file in filePaths )
181+ {
182+ var fileInfo = new FileInfo ( file ) ;
183+ zipArchive . CreateEntryFromFile ( fileInfo . FullName , fileInfo . Name ) ;
184+ }
185+ } // The zipArchive is automatically closed and disposed here
186+ }
187+
188+ /// <summary>
189+ /// Removes files from an existing test zip archive.
190+ /// </summary>
191+ /// <param name="zipResourceName">Name of the zip resource file.</param>
192+ /// <param name="fileNames">List of file names to be removed from the zip archive.</param>
193+ public static void RemoveFilesFromZip ( string zipResourceName , List < string > fileNames )
194+ {
195+ string zipPath = GetTestFile ( zipResourceName ) ;
196+ using ( ZipArchive zipArchive = ZipFile . Open ( zipPath , ZipArchiveMode . Update ) )
197+ {
198+ foreach ( string fileName in fileNames )
199+ {
200+ zipArchive . GetEntry ( fileName ) ? . Delete ( ) ;
201+ }
202+ } // ZipArchive is automatically closed and disposed here
203+ }
204+
205+ /// <summary>
206+ /// Delete test resources from cache directory.
207+ /// </summary>
208+ /// <param name="testFileNames">Name of the test files to delete.</param>
209+ public static void DeleteCachedFiles ( List < string > testFileNames )
210+ {
211+ foreach ( string fileName in testFileNames )
212+ {
213+ File . Delete ( Path . Combine ( PackageParser . InstallerDownloadPath , fileName ) ) ;
214+ }
215+ }
141216 }
142217}
0 commit comments