From ac3e66823b5d69f77c01cd8a641137b72e546c0b Mon Sep 17 00:00:00 2001 From: v-maudan Date: Wed, 14 Apr 2021 19:02:54 +0530 Subject: [PATCH] removed additonal try catch block --- .../DetectionTemplateSchemaValidationTests.cs | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/.script/tests/detectionTemplateSchemaValidation/DetectionTemplateSchemaValidationTests.cs b/.script/tests/detectionTemplateSchemaValidation/DetectionTemplateSchemaValidationTests.cs index 73a4fb3751..24826d60e2 100644 --- a/.script/tests/detectionTemplateSchemaValidation/DetectionTemplateSchemaValidationTests.cs +++ b/.script/tests/detectionTemplateSchemaValidation/DetectionTemplateSchemaValidationTests.cs @@ -109,12 +109,12 @@ namespace Kqlvalidations.Tests public void Validate_DetectionTemplates_AllFilesAreYamls() { List detectionPath = DetectionsYamlFilesTestData.GetDetectionPath(); - var yamlFiles = Directory.GetFiles(detectionPath[0], "*.yaml", SearchOption.AllDirectories).ToList(); - yamlFiles.AddRange(Directory.GetFiles(detectionPath[1], "*.yaml", SearchOption.AllDirectories).ToList().Where(s=>s.Contains("Analytic Rules"))); + var yamlFiles = Directory.GetFiles(detectionPath[0], "*.yaml", SearchOption.AllDirectories).ToList(); // Detection folder + yamlFiles.AddRange(Directory.GetFiles(detectionPath[1], "*.yaml", SearchOption.AllDirectories).ToList().Where(s=>s.Contains("Analytic Rules"))); // Extending detection validation to solution folder var AllFiles = Directory.GetFiles(detectionPath[0],"*", SearchOption.AllDirectories).ToList(); AllFiles.AddRange(Directory.GetFiles(detectionPath[1], "*", SearchOption.AllDirectories).ToList().Where(s => s.Contains("Analytic Rules"))); - var numberOfNotYamlFiles = 2; //This is the readme.md file in the directory - Assert.True(AllFiles.Count == yamlFiles.Count + numberOfNotYamlFiles, "All the files in detections folder are supposed to end with .yaml"); + var numberOfNotYamlFiles = 2; //This is the readme.md file in the detection and Cisco Ise soluton directory. + Assert.True(AllFiles.Count == yamlFiles.Count + numberOfNotYamlFiles, "All the files in detections and solution (Analytics rules) folder are supposed to end with .yaml"); } [Fact] @@ -138,21 +138,16 @@ namespace Kqlvalidations.Tests private string GetYamlFileAsString(string detectionsYamlFileName) { var detectionsYamlFile = ""; + // Get file present in detection folder or else check in solution folder try { - detectionsYamlFile = Directory.GetFiles(RootDetectionPath, detectionsYamlFileName, SearchOption.AllDirectories).Single(); + detectionsYamlFile = detectionsYamlFile = Directory.GetFiles(RootDetectionPath, detectionsYamlFileName, SearchOption.AllDirectories).Where(s => s.Contains("Detection")).Single(); } catch { - try - { - detectionsYamlFile = Directory.GetFiles(RootDetectionPath, detectionsYamlFileName, SearchOption.AllDirectories).Where(s => s.Contains("Analytic Rules")).Single(); - } - catch - { - detectionsYamlFile = detectionsYamlFile = Directory.GetFiles(RootDetectionPath, detectionsYamlFileName, SearchOption.AllDirectories).Where(s => s.Contains("Detection")).Single(); - } + detectionsYamlFile = Directory.GetFiles(RootDetectionPath, detectionsYamlFileName, SearchOption.AllDirectories).Where(s => s.Contains("Analytic Rules")).Single(); } + return File.ReadAllText(detectionsYamlFile); }