Clearing Chrome Internal DNS cache

Nov 24 16

Visiting a url, but getting the (old dns) version of a page?
I was too.

Turns out that Chrome keeps an internal DNS cache.

You can view it by visiting the following ‘url’ (enter this in your address bar in Chrome)

chrome://net-internals/#dns

Out Of Memory exception when deserializing with JSON.net – Use Streams instead

Nov 1 16

Calling an api and deserializing the returned json into a type is something I have to do quite often.

I used to use the following:


If the JSON returned is large, we’ll often get an Out Of Memory Exception

From the docs

To minimize memory usage and the number of objects allocated, Json.NET supports serializing and deserializing directly to a stream.

To rectify this, we can instead use Streams

 

In my example, where the JSON has a nested ‘result’ element, you’ll also need a class to represent this (see TypeContainingMyResult above)

Search for a branch with git

Aug 18 16

Got a load of branches?
Need to find a specific one?

Try this


for example

Will return all branches (remote or local) that contain “notifications” in the name of the branch

PleaseDoNotNameYourTestCasesLikeThis

Jun 16 16

I’ve delivered this as a lightening talk a couple of times at companies I’ve consulted at, but thought I’d knock out a suitably short blog post.

A lot of test cases I come across are named like this

WhenSomethingHappensThenSomethingShouldOccur

While the writing of a test in the first place should be applauded, naming them like this is a tad irksome.

By their nature, test case names will generally be longer than the method names their covering.
This in itself makes it harder to read – like a sentence without any spaces.

The pattern I prefer to follow is the one prescribed by Roy Osherove which looks like

UnitOfWork_StateUnderTest_ExpectedBehavior

The underscore separation is very important.
It acts like the space in a sentence; it makes it far easier to read these intentionally longer method names.

Also, this is not (I’d hope) how we’d ever name a real life method.

Thirdly, it makes it easy to distinguish while navigating through code using Resharper. Other go-to-anything tools are available.


I won’t paraphrase the other benefits, which are in the above linked blog post, but I encourage you to check it out.

Oh, and for those that are interested, my 6-deck long slides are available here:
https://docs.google.com/presentation/d/1upUeEnDPCsNzJQ_rh-Rhp65aHkIRTqeAJEwxUm-lZrw

Mocking calls to ApplicationContext.Current.Services

May 31 16

My current contract involves working on a project based on Umbraco.

Unit testing Umbraco, can be a bit tricky, especially given the existence of the static ApplicationContext.Current.Services class, which contains handy references to the Umbraco services – provided by a static type! We can’t mock this.

So, I created a little wrapper around this that would allow us to mock the returned service, via an interface

In the implementation, I use reflection to return the underlying service from ApplicationContext.Current: