This time I wanted to determine how many library items there were in two separate TeamMentor libraries : OWASP and Top Vulnerabilities.
I wanted to find an easy way to determine how many libraries were loaded in the jsTree control and after that be able to determine how many items were loaded (how many leafs were loaded).
Firstly, I created a single collection of Libraries using LINQ capabilities to merge subsets of data :
This is the way I used to be able to create a list of libraries :
Look for example that our assert verifies that 2 libraries were loaded. Considering that I do have a list of libraries, I can use the power of LINQ to determine how many library items (a.k.a nodes or leafs) were loaded. Since all the libraries are in the list, I can use SelectMany LINQ method which allow me to find all the elements within a collection, therefore applied to our case , this would be the way achieve that:
As you can see in this code section, there is not need to do an iteration over the List elements because SelectMany returns all the elements from the libaries and returns that in a single value.