I have been writing unit tests for my classes that use code contracts (Contract.Requires<T>) just like I did with the old style guard clauses basically since code contracts were released. My reasoning for testing them has always been that the unit test code should not make any assumptions about the implementation of the SUT and ideally should have no understanding about how it is implemented. Instead it should just test the behaviour. If a method that takes a reference type as a paramete...
[More]
Tags:
4f367181-6357-45e0-96e4-4ae19fface43|0|.0
I’m after some feedback from the community regarding the UX of UI navigation when dealing with a list of items where there is only one item in the list. I have a scenario in a UI where there is a list of subscriptions for a user account. Most of the time (~>90%) there will only be one subscription. There are two options for handling this. Always display the list when the user navigates to the list UI and force the user to manually select the only item available Automatically redirect...
[More]
Tags:
e935f526-8f58-4573-bfe2-93d14b05771c|0|.0
Quite simply, a lot. The yield statement seems to be such a simple part of C# yet it can provide such amazing power (being delayed enumeration). Outside of that power however, it can provide beautiful simplicity. Take the following abstract class for example: namespace MyApplication.Diagnostics
{
using System;
using System.Collections.Generic;
public abstract class DiagnosticTask
{
public abstract IEnumerable<DiagnosticTaskResult> ExecuteAll();
...
[More]
Tags:
699e9456-256f-43a9-ae7b-d8348dbd9c3b|0|.0
I have a pet peeve with how Action and TryAction style members are often implemented. Too often I see the following style of implementation. using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
public class SomeClass
{
public Stream GetSomething(String referenceData)
{
if (String.IsNullOrWhiteSpace(referenceData))
{
throw new InvalidOperationException();
}
return new MemoryStre...
[More]
Tags:
6994bd1f-b23f-4613-b222-4f1cb8c2cb04|1|5.0
I’ve been writing a custom Unity extension for disposing build trees when a container is asked to tear down an instance. This has brought up some interesting ideas about the conditions in which an instance should be destroyed. This has lead to me come up with the Law of Instance Ownership. Law of Instance Ownership An instance is owned by the highest stack frame that holds a direct reference to an instance, or the application domain for globally held instances. A common misconception is...
[More]
Tags: Unity
cff3c980-81b9-4dbb-9008-e6efba46cd6c|0|.0
I was reminded this morning of an email that I sent to the junior developers on my team when they joined us. It is an overview of some of the development practices, patterns and products that they would get exposed to on our project. I have included it here as a reference collection for others. Principles and Patterns These are things that I often use and are still learning to use. SOLID – Originally put together by Bob Martin (http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod). A g...
[More]
Tags: Useful Links, Performance, StyleCop, ReSharper, Unit Testing, PostSharp, AOP, Dependency Injection, Unity
50f5bc36-68e0-4a26-aa37-04e9cdbc8136|0|.0
I've been on ADSL2+ for a few years now. Having a possible maximum speed of 24Gb is nice, but the actual floats between 5-7Gb being 3.5km from the exchange. That's not great, but is fast enough for general net usage. Tonight however, surfing the net has been slow. Really really slow. So slow in fact, that www.speedtest.net tells me this.
In the test before this one, the upload speed was actually a tad faster than the download speed. Did someone say broadband???
Yep, I&...
[More]
Tags:
60ce2ac0-87be-4b45-9541-0039ca54980f|0|.0
There is a lot of information around that discusses the differences between classes and structs. Unfortunately there isn't a lot of information available about when to use one over the other.
MSDN has a good resource which provides guidance on how to choose between classes and structs. It starts by describing the differences between the two and then provides the following advice.
Consider defining a structure instead of a class if instances of the type are small and common...
[More]
Tags: Useful Links
d206439b-a0f8-4b29-9464-b540067df645|1|5.0
I had a conversation yesterday regarding
WCF service contract design with my tech lead at work. Funnily enough, I then got a comment on an old post that afternoon from Ciaran O'Neill which is really about the same topic. I thought that I should write up my thoughts on the subject. See here for the article.
Tags: WCF
243552ba-2c12-493d-a83a-47184c49e418|0|.0
I was asked recently about caching expiration policies in response to my rant in my Caching should not be the source of truth post and a comment I made in a post by Chris Blankenship. I have written an article about cache expiration policies which you can find here. It discusses the high level concepts in expiration polices and some suggestions about which options to pick. It makes references to HttpRuntime.Cache and the Caching Application Block in
Enterprise Library.
Tags:
3404e4b1-21b4-49d2-83b3-70e022940b20|0|.0