public void KqlFunctionsAddRemoveDirect() { KqlNode node = new KqlNode(); // deserialize JSON to the runtime type, and iterate. var path = Assembly.GetExecutingAssembly().Location; var directory = Path.Combine(Path.GetDirectoryName(path), "KqlFunctionTestFiles"); // Get the FILTER files string supportedFileMaskCsl = "FILTER*.csl"; var directoryInfo = new DirectoryInfo(directory); var orderedFileList = directoryInfo.EnumerateFiles(supportedFileMaskCsl, SearchOption.TopDirectoryOnly) .Select(d => d.FullName) .ToList(); var sourceFileList = orderedFileList as IList <string> ?? orderedFileList.ToList(); foreach (string file in sourceFileList) { string lines = File.ReadAllText(file); node.AddKqlFunction(lines); } // Assert all functions are added correctly Assert.AreEqual(GlobalFunctions.KqlFunctions.Count, sourceFileList.Count); // Make sure retrieval of a non-existant function doesn't throw an exception if (GlobalFunctions.KqlFunctions.Any()) { CslFunction negativeTest = node.GetKqlFunction("NonExistentFunction"); Assert.IsNull(negativeTest); } // Assert all functions are removed correctly int functionCounter = GlobalFunctions.KqlFunctions.Count; foreach (KeyValuePair <string, CslFunction> keyValuePair in GlobalFunctions.KqlFunctions) { node.RemoveKqlFunction(keyValuePair.Key); functionCounter--; Assert.AreEqual(GlobalFunctions.KqlFunctions.Count, functionCounter); } }