Search Page with xPath

There’s a neat trick in the Chrome Developer Tools which not too many people are aware of. Firstly, I’m just going to run through something you should already know. You can obtain the xPath value for an element in the page by:

  1. selecting the element in the Elements tab of the chrome developer tools; and
  2. right clicking on that Element and selecting copy XPath

That will copy the XPath value for that element into the clipboard. Really handy for things like the XPath selector in Selenium.

Sometimes, that XPath is not exactly the way you want to write it. For example, some XPath values will be more bullet-proof in terms of selecting an element because they may handle dynamically loaded elements better than the one which we extracted using the method above. (That’s perfect for the page in the state that it is in at that moment). But we may want to re-jig that XPath so that it will still find that element every day.

Here’s the neat trick. You can open the console and run XPath expressions against the page. The syntax is to simply using a lower case ‘x’ between the ‘$’ sign and the brackets: $x('xpath here')

For example:

Test Method Snippet

I created a useful code snippet that I thought I would share. The shortcut is tm and the snippet outputs the following text, giving you the skeleton for a unit test:

public void TestMethod()
	//  Arrange
	//  Act
	//  Assert                        

You can download that snippet by clicking the following button:

Also, I got sick of typing mvcaction4 every time I wanted to scaffold out an Action Method. So I cracked open the snippet file for that snippet using the a text editor and changed the contents of the shortcut element to mac4. Much easier to type and very easy to remember as well!

MembershipReboot Presentation for ADNUG

On Wednesday night I delivered a presentation about MembershipReboot, a claims-aware authentication library for ASP.NET. Here are some links relevant to the content, in addition to the PowerPoint presentation which I used:

Powerpoint presentation:

Hitting Host Machine’s SQL Server from within a VM

I had a situation at home where I was running some code in Visual Studio on a virtual machine. The virtual machine was running using VMWare Player on my desktop machine.

I needed to access the database which was running on my host machine (the desktop machine) from within the VM. So I had to come up with a Connection String which was able to target the host machine. The following Connection String achieves that:

<add name="DefaultConnection" connectionString="Data Source=,2310;Network Library=DBMSSOCN;Initial Catalog=AdventureWorld;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

Note, I had to open port 2310 on the host machine’s firewall.

Now, I don’t need to install Sql Server on my virtual machines (which always seems to be a pain in the proverbial).


I’ve wanted to take a look at NDepend for quite a while now. So today I am going to write about my initial impression of this excellent static-analysis tool. To get an immediate feel for what NDepend is and what it does, there is a short video that can be viewed here.

Managed code comes with many advantages. And one of the most significant (possibly the most significant) is the mountain of meta-data that .NET assemblies carry about themselves, and those that they interact with. This plethora of information can be tapped, analysed and presented in a meaningful way which gives coders/architects a great, bird’s eye view of the state of a given code base.

This post will not be a tutorial. But it will contain screenshots and some explanations. It will fall short of being a tutorial, because I am not setting out steps from end-to-end. Think of it as a summary of one developer’s experience analysing a real .NET solution with NDepend. The solution that I will analyse is my Home Library sample application (which is nowhere near finished and currently in a state of rampant architectural experimentation).

The first thing I wanted to check out once I had run the analysis on my solution (including all of its projects) was the metrics stuff. That looks interesting to me and I immediately decided to hone in on the Most Complex... - Types metric. When you select that from the NDepend menu (NDepend > Metric > Most Complex… > Types), it loads 2 separate panes:

  1. Search Results pane
  2. Metrics pane (which shows a treemap of the results)

Once I got my head around what I was looking at, it occurred to me that it was showing me the same information, but through different prisms:


Figure 1 – Metrics and Results Panes

Looking carefully at Figure 1, we can see that the way in which that information was retrieved was by way of the query that can be seen in the Search Results pane. Now that is pretty awesome, because NDepend has its own version of LINQ called CQLinq, which is used to pull out data from the static analysis (I am not sure if it is a fully-fledged LINQ provider, as I haven’t seen the word “provider” in any of their doco – but still über cool to have your own flavour of LINQ). Their documentation about syntax etc is a very good reference for writing CQLinq.

If you hover over the various methods in the tree-view (at the foot of the Search Results pane), you will see the corresponding rectangle in the treemap light up. You can see in Figure 2 that
I have honed in on the ExpressionBuilder type, as I do recall that carrying quite a bit of complexity. By the size of the rectangle in contrast to the rest of the treemap, that complexity is represented well. Obviously, the UI-related types in this WinForms app have the most complexity, each with quite a large Initialize method for all the controls on the forms.

Hover Cause and Effect

Figure 2 – Hover Cause and Effect

Another excellent feature in the Metrics pane is a drop down list which filters the top n items which match the query. In fact, if you look over to the right in the query window, you can see Take(10) has been added to the CQLinq query in Figure 3:

Top n

Figure 3 – Top n

I was correct in my feeling about the ExpressionBuilder class, as it is featuring in that top 10. If you click on the Edit Query button in the Search Results pane (visible in Figures 1 and 2 above), it launches a pane with a text-box for query manipulation. You can then add a new query, which is a pretty cool extension point. But that’s just the tip of the iceberg when it comes to customising NDepend to your needs.

The other feature that I wanted to highlight, as something that I found really cool, is the ability to see Dependency Graphs of your code. Figure 4 shows a graph I created from the NDepend menu NDepend > Graph> View ApplicationAssemblies Only:

Dependency Graph Assemblies

Figure 4 – Dependency Graph Assemblies

That’s a really nice representation of my architecture (just as I envisioned it). You can see the UI stuff towards the left, and then as you move through the middle (the domain), you eventually hit the data stuff on the right.

You can also create one for namespaces. Check out Figure 5 below:


Figure 5 – Mutually Dependent Namespaces

I’ve highlighted a problem there, which the tool found, regarding mutually dependant namespaces. The tooltips (the light-yellow boxes) provide some information to assist me in hunting down the reason for this unseemly coupling issue. This is a very valuable view of the relationship between your objects. You can also drill down further by right-clicking on the connector “edges” between the nodes in the graph to look at member dependencies etc.

The really cool thing about those tooltips is that they are dynamic. When you change a query or selected-item in a drop-box, the data displayed in those tooltips changes before your very eyes.

There are a heap of other things NDepend offers, some of which will have to be the subject for a future post.

But I’ll leave the reader with this – the developers of NDepend use NDepend to develop it. To use their words, they eat their own dog-food. And a very high quality kibble it is.