Rory Primrose

Learn from my mistakes, you don't have time to make them yourself

View project on GitHub

Moved to GitHub Pages

I’ve been running this blog on the Microsoft stack since way back in August 2001 with almost 900 posts. I think that might have even been before blogging was called blogging. My viewpoint on blog engines has changed substantially over the years to the point where the bells and whistles of the ‘modern’ blog engines are not as attractive as they once were.

I’ve now converted the blog over to Jekyll using GitHub pages to make my blogging life a lot easier. As part of this process, I have removed a whole lot of old posts and files that are no longer relevant to the current state of technology. This blog now has half the posts it once was and is much more technology focused.

Read More

ReSharper Jasmine and RequireJS

I’ve been converting my code over to RequireJS and have been battling how to get this to work with the ReSharper test running which uses Jasmine. The main issue is that Jasmine runs the page on load of the browser document (the spec runner) before RequireJS has loaded dependencies. The reason for this is that RequireJS loads dependencies asynchronously. By the time they have loaded, the test run has already completed.

Read More

Not all browsers are made equal - The JavaScript console

While this is stating the obvious, my JavaScript skills sometimes fail to appreciate that what works in one browser does not work in another. Classic example here is logging information to the console. I recently noticed that IE doesn’t play very nice with a script that does something like console.log. While it might seem strange that console output across browsers might be different, that is just how it is.

The primary issue here however is that scripts will still use the console but the script might not execute in a browser the supports it. This script might be something that you control, but could also be a third party script you import. In either case, there are two things that should happen here. Firstly and most importantly, the script shouldn’t fail because the browser doesn’t support console logging. Secondly, the console functionality should do its best attempt at getting console logging to work when at all possible.

Read More

Bridging between NSubstitute and FluentAssertions

The two go-to packages I use for unit testing are NSubstitute and FluentAssertions. NSubstitute is a wonderful package that solves all the pain points I had testing with RhinoMocks. Similarly, FluentAssertions is an awesome package for running assertions on data with very powerful evaluations. A great feature of both these packages is the really good feedback about failures. There is one scenario however that falls in the cracks of between the functionality of these two packages.

NSubstitute is really good at setting up stub behaviour using predicate or value argument matching and asserting received calls with the same argument matching. FluentAssertions is really good at asserting whether values satisfy specified criteria. The difference between these packages is that NSubstitute works with predicate expressions whereas FluentAssertions evaluates assertions and throws an exception if the assertions fail.

The gap in functionality here is where I want to use NSubstitute to evaluate received calls but the power of FluentAssertions evaluation in the argument matching. This doesn’t work because NSubstitute uses Arg.Is<T> (Expression<predicate<T>>) whereas FluentAssertions will throw an exception. We need the ability to bridge these two packages so that we can have the power of FluentAssertions executing within an NSubstitute argument matcher and allowing the test code to remain readable.

Read More

Generic Func IEqualityComparer

Developers generally like the LINQ syntax with all its lambda goodness. It is fluent and easy to write. Then you do something like dataSet.Intersect(otherData, OHNO!).

Signatures like the LINQ Intersect function seems to just get in the way of productive development. With so many things in a lambda syntax, we are now forced back into the world of IEqualityComparer. The easy fix is to drop in something like a generic equality comparer that will support a Func.

Read More

Azure Table Storage Adapter - Fixes and Features

I have posted over the last couple of months about an adapter class that I have been using for using Azure table storage. The adapter has been really useful to bridge between Azure table entities and application domain models. There have been some interesting scenarios that have been discovered while using this technique. Here has been the history so far:

Read More

Azure Table Storage Adapter Using Reserved Properties

I posted earlier this year about an adapter class to be the bridge between ITableEntity and a domain model class when using Azure table storage. I hit a problem with this today when I was dealing with a model class that had a Timestamp property.

While the adapter class is intended to encapsulate ITableEntity to prevent it leaking from the data layer, this particular model actually wanted to expose the Timestamp value from ITableEntity. This didn’t go down too well.

Read More

Azure Table Services Unexpected response code for operation

I’ve just hit a StorageException with Azure Table Services that does not occur in the local emulator.

Unexpected response code for operation : 5

The only hit on the net for this error is here. That post indicates that invalid characters are in either the PartitionKey or RowKey values. I know that this is not the case for my data set. It turns out this failure also occurs for invalid data in the fields. In my scenario I had a null value pushed into a DateTime property. The result of this is a DateTime value that will not be accepted by ATS.

Read More

Azure EntityAdapter with unsupported table types

I recently posted about an EntityAdapter class that can be the bridge between an ITableEntity that Azure table services requires and a domain model class that you actually want to use. I found an issue with this implementation where TableEntity.ReadUserObject and TableEntity.WriteUserObject that the EntityAdapter rely on will only support mapping properties for types that are intrinsically supported by ATS. This means your domain model will end up with default values for properties that are not String, Binary, Boolean, DateTime, DateTimeOffset, Double, Guid, Int32 or Int64.

I hit this issue because I started working with a model class that exposes an enum property. The integration tests failed because the read of the entity using the adapter returned the default enum value for the property rather than the one I attempted to write to the table. I have updated the EntityAdapter class to cater for this by using reflection and type converters to fill in the gaps.

Read More