xunitcontrib-resharper 0.5–fixes, fixes, fixes

by Matt 28. November 2011 12:49

I’ve just pushed a new version of xunitcontrib up to codeplex. Well, two new versions.

There’s the stable, ReSharper 6.0 and 5.1.3 version, and then the latest build for the 6.1 EAP. Both have had the same bunch of fixes made:

On top of that, the EAP version should now work properly in Visual Studio 2011.

The two interesting ones are the fixed dotCover support and the getting partial classes working. While the last release would show methods as highlighted, it was missing support for Show Covering Tests. This allows you to right click on any method and when select the Show Covering Tests will list all tests that call into that method. More niceness from JetBrains.


Getting partial classes working is important if you want to use Microsoft’s Pexframework. This tool will generate unit tests for you based on the code your write. These generated tests live in partial files, which now work in 6.0 and 6.1.

And finally, a quick word about versions. I intend to support that latest released revision of the last two major versions of ReSharper. In other words, I’ll support 6.x and 5.x by releasing versions for 6.0 and 5.1.3. Once the 6.1 EAP is fully baked, I’ll only support 6.1 and 5.1.3. I’ve added another release to hold these older versions.


xunitcontrib-resharper 0.4.4 - dotCover support

by Matt 23. October 2011 12:39

Finally I get around to releasing dotCover support for the xUnit.net ReSharper unit testing plugin. Meant to do this ages ago, and it slipped off the radar – apologies.

The dotCover guys have made integration very nice and easy. Simply right click on a file, or a class, or click the icon next to a test method and select “Cover with dotCover”. The unit tests are run, dotCover thinks for a couple of seconds, and then you get your code coverage.


If you have the “Highlight code” icon selected, then all code (tests and production code) is highlighted in green or red depending on your coverage. The options even allows you to select a colour scheme that works with a dark background.


And that’s it. There are no other changes in this release.

You can download it from the codeplex site, and installation is the usual unblock, unzip and replace files. But, as a special treat, if you’re playing with my experimental NuGet ReSharper extension manager, you can download the .nupkg file from the same page. If you drop this file into the C:\rsrepo folder (remember, it is experimental), go to ReSharper –> Extension Manager –> Updates, it should appear as an update, ready to install. One small VS restart later, and you’re up and running with the new version.


ReSharper plugins via NuGet

by Matt 18. October 2011 10:04

I have this little ReSharper plugin. It is small and rather useful. And one of the most frequent requests I get is for an installer.

I’ve resisted this, mainly because it’s only 4 files. I could see how useful an installer would be, but I wasn’t going to write one just to copy 4 files around. That would be like using a sledgehammer to crack a nut.

Nope. I’m going to use a nuclear bomb to crack a nut.

Instead, I thought it would be more interesting to write an extension manager for ReSharper, based on NuGet. In other words, package ReSharper plugins as NuGet packages, and deliver and manage them in the same way – so you can browse, install, update and uninstall, just like assembly reference NuGet packages.

Something like this:


Before we go any further, I need to point out that this is not a finished product – it is very much an experimental ALPHA version. It works, but only just.

It can do the basics just fine – it can browse and install, uninstall and update plugin packages. They’re stored in a nuget repository in your local profile, and get automatically loaded at startup.

The big thing that’s missing is server support. The “Online Gallery” does NOT talk to a server, and is HARDCODED to point at C:\rsrepo.

It’s also missing other useful stuff like error handling, displaying license and progress dialogs and so on.

But it’s functional enough to give a tyre-kicking to, and I’d appreciate the feedback. ReSharper 6.0 only for now.

Here’s what you need to do to get up and running (please read carefully – this is alpha quality!):

  1. Download the zip file from the github downloads page
  2. Extract the contents – you’ll find a .vsix file and 3 .nupkg files
  3. Double click the .vsix file. This will install the plugin (in the future it will be on the Visual Studio Gallery, making this much easier)
  4. Create the C:\rsrepo folder and copy the .nupkg files into it
  5. Fire up Visual Studio
  6. Go to ReSharper –> Extension Manager to bring up the manager UI

If you go to the “Online Gallery” section of the extension manager, you should see the test packages listed. I’ve created a package for the current 6.0 release of xunitcontrib, and two versions of a sample plugin that simply adds a menu item to the ReSharper menu (it just displays a message box with the current version).

Once you’ve installed a package, you need to restart VS before the plugin will get loaded (you’re not yet prompted like NuGet does). Similarly, uninstalling or updating a plugin requires a restart (this is unavoidable – the dlls are loaded into memory and there is no way to unload them. You’ll find the same behaviour in the Visual Studio extension manager).

While you’re in the Online Gallery, you’ll probably notice that it lists all versions of the sample packages, rather than just the latest. Don’t install both versions at the same time – that will confuse things (I told you it was alpha). The two versions are there to test updating – once the oldest version is installed, going to the Updates section will list the newer as ready for updating.

So, what’s next?

Top priority is server support. I need to get a gallery working, and to be able to configure the extension manager with the server feed.

Then, a proper good tidy up – error handling, progress indicators, showing licenses, searching, sorting etc. I’d like to add support for ReSharper 5.1 and the forthcoming 6.1 EAP.

Oh, and more packages would be nice, too.

Creating a package is dead easy – just put your assembly files in an “rs60\plugins” folder. Open one of the sample packages in the NuGet Package Explorer to take a look. Or check out the samples folder in the source on github.

I’d love to hear some feedback. Let me know what you think. Leave a comment here, github or on twitter.

So, that’s how you install 4 files.


xunitcontrib support for ReSharper 6.0 beta

by Matt 14. June 2011 09:18

So, ReSharper 6.0 has gone beta. And that means we need a new build of the xUnit.net test runner plugin. The latest release on codeplex works nicely with the beta version, and I’ll be aiming to keep it up to date as the nightly builds continue.

There are a couple of minor changes with this release, changes that are in the source for the 5.1 version, but haven’t yet been released (that’s the missing 0.4.2 version for you eagle-eyed folks). You can read more in the release notes.


There is currently a bug/regression in ReSharper that means you can’t just throw all of the files in the plugins folder. Instead, you must copy the xunit.runner.utility.dll and the xunitcontrib.runner.resharper.runner.6.0.dll files into the C:\Program Files\JetBrains\ReSharper\v6.0\bin folder. If you copy all of the files from the zip (including the plugins folder) straight into the bin folder, you’ll be fine. I’m hoping this will be fixed by RTM.

Go download!



Assembly lists for dotPeek!

by Matt 31. May 2011 10:38

So, I guess I’m laying claim to the first dotPeek plugin. (tl;dr - get the source and a zip file at github)

I’m really liking dotPeek, JetBrains’ new decompiler. It’s not perfect – it is still in pre-beta after all - it’s a bit slow, there are things it has trouble decompiling (Silverlight reactive framework for one) but what it does have is a killer feature – ReSharper’s navigation and code analysis – go to type, go to symbol, deriving classes, show usages, etc. Everything you could need for a good bit of code spelunking.

Everything except assembly lists.

Reflector’s got a lovely feature that allows you to switch between lists of different assemblies, so I can be looking through the Silverlight reactive framework, then switch over to wander through the ReSharper API and then jump into the dotPeek assembly list. All very handy, and all very much missing from dotPeek.

Fortunately, the nice folks at JetBrains have included ReSharper’s plugin model into dotPeek. So, check this out:


Looks remarkably familiar, no?

It’s dead easy to install:

  1. Since dotPeek doesn’t have a standard installer, create a folder called plugins wherever it is you’ve installed dotPeek to
  2. Download this file from the downloads section of the github repo
  3. Right click the zip file, display properties and click “unblock”
  4. Extract the files from the zip file and dump them in the “plugins” folder, preferably in their own folder, such as “AssemblyLists”

Now, when you start dotPeek, you’ll get a new entry in the FIle menu, and a new button on the toolbar in the Assembly Explorer that will bring up the list management window. Add, remove or rename your lists here. They should stay up to date with whatever was last selected in the assembly explorer, and will save and load between sessions.

One word of warning – the assembly lists are stored in a shared file, and if you start dotPeek without the plugin, it WILL lose your lists.

Let me know what you think – issues and whatnot on github, or @citizenmatt on twitter. Ta!


xunitcontrib-silverlight 0.2 – Windows Phone 7 support

by Matt 16. March 2011 11:45

Fancy writing xUnit.net tests for Windows Phone 7?


I’ve just pushed the latest release of xunitcontrib-silverlight to codeplex. It’s version 0.2 and builds on the first release by including a Windows Phone 7 compatible provider for the Silverlight Unit Testing Framework.

Using it is dead easy, but not exactly seamless – check out this brilliantly helpful post for full details . In outline:

  1. Create a Windows Phone application project
  2. Add references to:
    • Microsoft.Silverlight.Testing (the Silverlight 3 version – included in the release package)
    • xunit-silverlight-wp7
    • xunit.extensions-silverlight-wp7
    • xunitcontrib.runner.silverlight.toolkit-wp7
    • (Visual Studio may decide to whinge about adding Silverlight 3 assemblies to a WP7 project. Ignore them, it’s all fine)
  3. In the MainPage.xaml.cs file, modify MainPage_Loaded to create the test page and set it as the RootVisual (see the above post for an example)
  4. VERY IMPORTANT: Register the xunit test provider. Simply call XunitContrib.Runner.Silverlight.Toolkit.UnitTestProvider.Register()
    If you fail to do this, NO TESTS WILL RUN
  5. Write some xunit tests and run the application

Everything else is pretty much as for the desktop (Silverlight) runner:

  • The core xUnit.net API is fully supported (Fact, Theory, new test instance per run, IUseFixture, IDisposable, etc)
  • ExclusiveAttribute works as a means of filtering which tests to run
  • Use traits with keys of “category”, “owner” and “description” to pass metadata into the system (not used much, but nice to know)
  • OleDb theories aren’t supported due to lack of Silverlight support. Similarly, capturing output
  • Tests aren’t run in random order (they’re run alphabetically)
  • Theory tests are enumerated in full before the tests are run, so there is a single test for each instance of a theory test combination. If enumerating tests is expensive, project startup will be expensive
  • Silverlight does not support private reflection. This means you might need to use InternalsVisibleTo for xunit-silverlight-wp7

GOTCHAS. There are a couple:

  1. The namespace displayed for a failing test is incorrect. It’s always displayed as “XunitContrib.Runner.Silverlight.Toolkit”. There is a change currently sitting in source control for the silverlight unit testing framework that will sort this out. Once the bits have been released, this will be fixed properly
  2. Don’t forget to call UnitTestProvider.Register!
  3. There is a bug in the xaml for the test page which makes the “Run everything” button invisible. This means that it looks like there’s only the “Use tag” button – and using this button causes the ExclusiveAttribute to be ignored (because you’ve specified what to run with a tag expression). The workaround is to just click it anyway (the yellow rectangle in the image below) – it still works, you just can’t see it. Similarly, this bug is fixed in source control, and will be rolled into a release once the official bits are released.


This release has a couple of other changes to the 0.1 release that are worth mentioning:

  1. Assemblies are now versioned appropriately. For the xunit files, the file version is the xunitcontrib version (e.g. 0.2) which is the value displayed in Windows Explorer. However, the internal version of the assembly (the number you link against), is set to the version of the xunit assembly
  2. The xunit assemblies have been renamed to follow a known pattern, namely *-silverlight3, *-silverlight4 or *-silverlight-wp7
  3. The xunit assemblies now come with xml intellisense docs

So what’s next?

  • Well, it’s getting painfully difficult to build from source. I think I’m going to have to bite the bullet and put the xunit port into its own fork
  • nuget support
  • Ensure support for the Silverlight Unit Test Framework’s base classes, which means ensuring asynchronous tests and the UI test panel work

And of course, anything else that get’s reported. Please list issues at codeplex, or ping me on twitter @citizenmatt.


Running xunit tests in Silverlight–xunitcontrib-silverlight

by Matt 14. December 2010 12:14

If you want to write unit tests in Silverlight,  it’s a pretty solid bet that you’ll be using using Jeff Wilcox’s unit testing framework that ships with the Silverlight Toolkit. It’s essentially a port of mstest, combined with a Silverlight based test runner. Handily, the test runner allows for unit test providers, allowing us to plug in a different test framework.

And that’s exactly what the latest release of xunitcontrib is – a port of xUnit.net, and a provider for the unit testing framework.


It’s a pretty faithful port of xunit (i.e. with as few changes to the source as possible), and includes the majority of the features that you’ll require day-to-day for testing, but it’s also running on a different platform and in a different execution environment to the desktop CLR version of xunit, so THERE ARE DIFFERENCES.

I strongly suggest checking out what’s different or not included in the xunit port, as well as the details of the unit testing framework integration.

In the mean time, you can download the release from codeplex. It supports Silverlight 4 using the April 2010 toolkit and Silverlight 3 using the semi-official build based on the April 2010 toolkit (Windows Phone 7 support is coming in the next release). Here’s the quick run down on how to use it:

  1. Create a Silverlight application
  2. Add references to Microsoft.Silverlight.Testing.dll and the Silverlight-appropriate versions of xunit-silverlight.dll, xunit.extensions-silverlight.dll and xunitcontrib.runner.silverlight.toolkit.dll
  3. In App.xaml.cs, replace Application_Startup with:
          UnitTestSystem.RegisterUnitTestProvider(new XunitContrib.Runner.Silverlight.Toolkit.UnitTestProvider());
          RootVisual = UnitTestSystem.CreateTestPage();
  4. Then just add tests, and run the application

Alternatively, if you’ve installed the latest Silverlight Toolkit, you’ll get a unit testing project template in the File->New dialog that makes this a little easier, although you’ll still need to add the xunit/xunitcontrib references and register the xunitcontrib provider (if you don’t register it, you’ll get no tests!)

As ever, let me know, either via codeplex or on twitter (@citizenmatt) if there are problems or questions.


xunitcontrib | Silverlight

My colour settings for Visual Studio

by Matt 16. August 2010 10:03

So, just in case I should happen to find myself in a situation where I need to update a vanilla Visual Studio to the nice, soothing colours I know and love, somewhere, say, that doesn’t allow USB drives, I thought I’d post them here (why, yes, I do have a new job, starting tomorrow. How did you guess?)

I can’t quite remember where these colours came from, but having a mooch about the cavernous depths of my downloads folder, I rather think it was from this post on gurustop.net, although tweaked to use Consolas and later versions of ReSharper and goodness knows what else. And it’s also up to date with VS2010, too, using some of the newer colours  you can see when you check the “Advanced highlighting” checkbox on this page (I really like studiostyles.info – nifty bit of html/css, but it doesn’t include ReSharper colours, which is a showstopper for me).

Anyway, it’s very nice, even if I do say so myself – all very calming blue (which makes red errors a bit awkward, probably still need to tweak those a little). It looks kinda like this for normal code (screen grab from the aforementioned awesome studiostyles.info):


and this for the VS2010 “advanced highlighting”:


Except of course, with added ReSharper-y goodness (version 5.1, highlight current line, etc). It doesn’t really differentiate between all the different user defined types and stuff, ‘cos there’s just no need.

So, finally, links: citizenmatt-VS2010-2010-08-16.vssettings and (for all you old timers out there) citizenmatt-VS2008-2010-08-16.vssettings.


SQL Server aliases

by Matt 14. May 2010 11:30

Everyone knows the trick of using the hosts file to redirect one hostname to another. It’s a bit of a sledgehammer, but sometimes it’s amazingly useful.

Take, for example, a system that consists of multiple websites, web services and scheduled tasks. I don’t need to run the entire system locally; I don’t need the resource overhead, nor the overhead of keeping it up to date. So I have a remote development environment (maintained by continuous integration) that the website I’m developing locally can consume.

And the hosts file trick allows me to occasionally work disconnected from this environment, hosting everything locally, and without changing the shared config (and accidentally checking it in and spoiling things for everyone).

I like this, but it leaves me without a database.

My connection strings refer to a named server. Perhaps the host file trick could still work here, but I’ve only got SQL Server Express installed under a named instance. Which, as far as I can tell, means I have to change my connection strings from “Server=dbhost;…” to “Server=.\SQLEXPRESS;…”. And whoops, I’ve just checked that in and broken the whole dev environment.

SQL Server aliases to the rescue!

Fire up SQL Server Configuration Manager and expand the “SQL Native Client 10.0 Configuration” node. Right click on Aliases and select “New Alias…”. Set the alias name to the server name value used in the connection string (for “Server=dbhost;…” use “dbhost”). Set the protocol to “Named Pipes” and enter “.\SQLEXPRESS” in the server field (the pipe name gets automatically populated).


And that’s it. You can now connect to your SQLEXPRESS named instance without changing your connection strings.

One thing to be aware of – if you’re on a 64 bit machine, the steps above have just set up an alias for 64 bit programmes only, which (probably) includes your IIS based website. You need to set up another alias for 32 bit applications by doing exactly the same thing under the “SQL Native Client 10.0 Configuration (32-bit)” node. Once you do this, you can connect to the server “dbhost” from SQL Server Management Studio.

In fact, there’s just one last thing to be aware of – I don’t really know what I’m doing. I’m not a SQL Server guy, so I don’t know if this is old news, or the normal, well known way of doing things, and I definitely don’t know what this is doing under the covers. But it’s working, and it’s helpful, and I’m going to use it.

Now to figure out how to mock Windows authentication…

Tags: ,

LINQ and loops

by Matt 28. April 2010 09:52

Well, gosh. What a busy few months. What started as a bit of spit and polish to a website has turned into a huge rewrite and a great opportunity to learn and play with MVC(2), the Spark view engine, Lucene.net and NHibernate. But more on those some other time. Today, I’m interested in a performance problem that wasn’t what I was expecting it to be.

One core scenario of this website is that users can watch video files. We don’t want to allow them to view just anything, so we grant them access to a subset of the videos. Which means we have the following requirement: what programmes does the user have access to watch?

This is calculated like so: get the video access tokens for the user. Map each token to an episode. Strip out episodes which don’t have videos available. Retrieve the programmes for all viewable episodes.

For better or worse, this touches 5 tables across 3 separate databases.

We wrote a cache.

And you know what? It works great. The site is fast, the data is readily available, everybody is happy.

Except for one user.

We have a demo user that is granted access to a large number of episodes in a large number of programmes, ready to be used at conferences and other events.

This user killed the site.

Once the data was in the cache, everything was great. But it took 5 minutes to get into the cache. And killed the site while it was doing so.

I was expecting some trouble with this user – they didn’t work well on the existing site, and it’s obvious that we’re doing too much database activity. So I fired up the wonderful NHProf to see exactly what was going wrong and immediately proved myself wrong. All the data was being retrieved with a minimum amount of fuss and sql statements and round trips to the database. It took 5 seconds.

Now, we are definitely doing too much with the database here. We really could do with denormalising some of the data, using less databases and pulling back ids instead of unused entities. But it still only took 5 seconds. As an edge case populating a cache for a user only used by staff at conferences, 5 seconds is pretty much ok.

So what was happening for the remaining 4 minutes and 55 seconds?

The title of the post might help. The heart of this little process was a LINQ to objects query that joined up the lists from the various databases to create the final list of programmes, episodes and tokens that we could cache and present to the user. It went something like this:

var tokens = GetTokens();
var episodes = GetEpisodes(tokens);
var availableEpisodes = GetAvailableEpisodes(episodes);
from p in GetProgrammes(availableEpisodes)
select new ProgrammesWithTokens(p.Id, p.Title, GetTokensForProgramme(p, episodes, tokens))

where GetTokensForProgramme was defined like:

from t in tokens.OrderByDescending(x => x.GrantedDate)
from e in episodes
where e.OpaqueStringId == t.OpaqueStringId 
   && e.EpisodeNumber == t.EpisodeNumber 
   && p.Episodes.Contains(e)
select t

Now, there are two glaring issues going on here: We’re always ordering the tokens list – we could do that once before anything else. Similarly, we could do something about the p.Episodes.Contains(e) which isn’t going to be very quick.

But that’s small fry. Where’s the real problem?

It took me a little while to realise that what looks deceptively like nice, declarative, friendly LINQ, is in fact (of course) nested loops. Three deep. This simple bit of data collation is O(n * m * p).

I didn’t mention data size before. Turns out it’s not really that large. The demo user has about 1600 tokens, for 1500 available episodes for about 300 programmes.

Not much, actually.

But when you count the looping, this gives us 300 * 1600 * 1500 = 720,000,000 iterations.

Seven hundred and twenty MILLION iterations. That’s 720 MILLION string comparisons, and 720 MILLION list traversals for the Contains calls. It’s also 299 unnecessary ordering of the tokens list.

That’s where my 5 minutes was going.

Rewriting this as a bunch of lookups has reduced this bottleneck to essentially the time it takes to read from the database – about 5 seconds.

So the moral of the story is simple. LINQ is nice. It’s lovely. But when you’re doing multiple from statements, don’t forget it’s now doing nested loops.

That can really hurt.



Month List


Comment RSS