I was recently made aware that some unit tests for Kentor.AuthServices were failing on non-English computers. To be able to test a different setup I turned to Azure and set up a machine with VS2013 Pro and installed Swedish language support. Once I found the right way, it was very straight forward.
The problem was that I had set up a number of unit tests to check the actual contents of the exception message. Those are customized when running on a different UI culture (if the language is installed).
Just checking the type of the exception would not be enough as some methods throw ArgumentNullException
for different parameters and I want to make sure that it is the right param that is detected and not a false positive. Following the TDD practices as strictly as possible on this project I had to get failing tests first, before making any changes.
I also wanted to make sure that it’s possible to develop and run all tests on VS Pro (I’m using Premium myself). It’s easy to accidentally use a tool that is not available in Pro and this was a perfect opportunity to check that.
So I headed over to manage.windowsazure.com to get started.
Finding the Visual Studio VMs
There are virtual machines available on Azure with Visual Studio preconfigured if you have an active MSDN subscription. First follow the normal link to create a new VM, but select the gallery instead of quick create.
To access the Visual Studio VMs, select the small MSDN check box down to the left. Choose the Visual Studio version you want and go ahead.
The provisioning (creation) of the machine takes some time, but once it’s created and running it’s available through remote desktop by default. The rdp settings file needed is available for download from the Azure portal. If you want to adjust the settings, such as adding access to the client’s drives you have to download the file and edit if. If you’re fine with accessing it through the default settings it’s easiest to just run the file directly.
Adding a language
At first I had troubles finding the right way to add a language to the VM, but once I found the right way it was dead simple. Open the control panel and select “Add a language”. Find the language you want to add and add it. Now it is available for selection as input locale etc, but the translation files needed to get exception messages in the language are not automatically downloaded. That can be done by selecting the “options” link.
Select “Download and Install Language Pack” to continue. Then a lot of patience is required. The download was quite quick, but the install was painfully slow. I aborted it several times because I saw no progress and thought there was en error. The progress bar only has two steps. Half complete and complete. It took nearly ten minutes for it to get to half complete and even more to finish, but once that was done, the language files were available and I could run my tests using a Swedish locale. I’ll get back to the solution for that in a another post.
Possible spoiler for the next post: the ArgumentNullException has a constructor overload with an argument for the name of the argument that is null. http://msdn.microsoft.com/en-us/library/k8a0dfcy(v=vs.110).aspx
And a matching property to get it out later.
I thought code analysis had a warning if you didn’t use that overload?
I used the http://msdn.microsoft.com/en-us/library/wssa019h(v=vs.110).aspx overload that only takes the name of the parameter.
The problem was that I checked the actual exception message contents, which are localized. You can see the old and new code in the diff of https://github.com/KentorIT/authservices/commit/0f788abc66544a741c4082d780bd28b85ff22b34