public static async Task GetDownloadedEncFilesAsync(string fssBaseUrl, string folderPath, string productName, int?editionNumber, int?updateNumber, string accessToken) { int totalFileCount = 0; //Get Countrycode string countryCode = productName.Substring(0, 2); //Get folder path string downloadedEncFolderPath = Path.Combine(folderPath, countryCode, productName, editionNumber.ToString(), updateNumber.ToString()); var searchQueryString = CreateFssSearchQuery(productName, editionNumber.ToString(), updateNumber.ToString()); var apiResponse = await FssApiClient.SearchBatchesAsync(fssBaseUrl, searchQueryString, 100, 0, accessToken); Assert.AreEqual(200, (int)apiResponse.StatusCode, $"Incorrect status code is returned {apiResponse.StatusCode}, instead of the expected status 200."); var responseSearchDetails = await apiResponse.ReadAsTypeAsync <ResponseBatchSearchModel>(); if (Directory.Exists(downloadedEncFolderPath) && responseSearchDetails.Entries.Count > 0) { totalFileCount = FileCountInDirectories(downloadedEncFolderPath); string[] fileNames = Directory.GetFiles(downloadedEncFolderPath).Select(file => Path.GetFileName(file)).ToArray(); int fssFileCount = 0; ResponseBatchDetailsModel responseBatchDetailsModel = new ResponseBatchDetailsModel(); ExtractEncFileCount(productName, editionNumber, updateNumber, responseSearchDetails, ref fssFileCount, ref responseBatchDetailsModel); Assert.AreEqual(totalFileCount, fssFileCount, $"Downloaded Enc files count {totalFileCount}, Instead of expected count {fssFileCount}"); foreach (var fileName in fileNames) { Assert.IsTrue(responseBatchDetailsModel.Files.Any(fn => fn.Filename.Contains(fileName)), $"The expected file name {fileName} does not exist."); } } else { Assert.AreEqual(totalFileCount, responseSearchDetails.Count, $"Downloaded Enc files count {responseSearchDetails.Count}, Instead of expected count {totalFileCount}"); } }
public static bool CheckProductDoesExistInSearchResponse(ResponseBatchDetailsModel batchDetail, string productName, string editionNumber, string updateNumber) { return(batchDetail.Attributes.Any(a => a.Key == "CellName" && a.Value == productName) && batchDetail.Attributes.Any(a => a.Key == "EditionNumber" && a.Value == editionNumber) && batchDetail.Attributes.Any(a => a.Key == "UpdateNumber" && a.Value == updateNumber)); }
private static void ExtractEncFileCount(string productName, int?editionNumber, int?updateNumber, ResponseBatchSearchModel responseSearchDetails, ref int fssFileCount, ref ResponseBatchDetailsModel responseBatchDetailsModel) { foreach (var item in responseSearchDetails.Entries) { if (fssFileCount == 0 && CheckProductDoesExistInSearchResponse(item, productName, editionNumber.ToString(), updateNumber.ToString())) { fssFileCount = item.Files.Count; responseBatchDetailsModel = item; break; } } }