While doing automation testing, we may get a scenario where we need to download a zip file and to validate the contents inside it.
One way to do this validation is by using extracting the contents to a folder and loop through each file names.
Given below is another way where we don't need to extract the zip file but can directly verify the files inside it.
For this we just need to provide the path of zip file and the file names that we need to check inside it.
First, we need to add below package to our solution.
using System.IO.Compression;
You can find it inside NuGet package manager in following names.
This will allow us to unlock different capabilities to work on a zip file using C# code.
A method to check the file names inside zip file is given below.
public bool verifyZipFileContent(string zipFilePath, string fileNameToCheck) { bool foundFlag = false; using (ZipArchive archive = ZipFile.OpenRead(zipFilePath)) { foreach (ZipArchiveEntry entry in archive.Entries) { if(entry.FullName== fileNameToCheck) { foundFlag = true; } } } return foundFlag; }
No comments:
Post a Comment