Richard's Blog
-
Mocking your Entity Framework data context and testing it in .NET MVC
I explained in my previous post Do we need the repository pattern? why you might want to mock your Entity Framework context rather than using the repository pattern. In this post I’ll show you how to do that and how to test your .NET MVC controllers with a fake data context.
The way you do this varies slightly depending on whether you're using code first or database first. I’ll cover both in this post.
Using Code First in Entity Framework 4
My implementation of code first is based heavily on the blog post by Rowan Miller.
A mockable data context (EF Code First)
When you create your code …
-
Do we need the repository pattern?
As we learn new technologies, we discover new mistakes. The Entity Framework makes data access very quick to develop, but also introduces a new set of mistakes that can be made. On my last project I used the Entity Framework Profiler and found my code blighted with a scourge of N+1 problems. I discussed this in my blog post Reviewing my data access layer using the Entity Framework Profiler.
I was also worried that my code wasn’t testable. From what I’d read, the repository pattern seemed to be the agreed best practice for making your data access testable.
However my N+1 problems led me to …
-
Bridge statistics, manga and SQL
I didn't enjoy stats at school very much. It seemed a very dry subject that involved a lot of tedious calculations and I didn't really see the point. Perhaps if we'd been encouraged to use computers to do the tedious stuff and been given data sets that were more interesting I'd have realised that actually stats can be a very interesting subject.
After reviewing and enjoying The Manga Guide to Relativity, I was excited to be sent a copy of The Manga Guide to Statistics to review. It inspired me to look at statistics again. Perhaps they do have a point, perhaps with some interesting data and a …
-
Moving from Subversion to Mercurial and Bitbucket
I've been using Mercurial for source control on my own small projects for a while and have really liked it. I've also wanted to stop supporting my own Subversion server, but previously I've found hosted solutions too expensive. That's why I like Bitbucket's pricing structure. I have lots of projects that need source control, but I either work alone or as part of a small team. Bitbucket charges by the team size, not the number of projects (which seems like a much better way to judge the budget of a project) and it's free for teams of 5 or under.
I've wanted to move my existing subversion …
-
Movember at Old Broadcasting House
November has been Movember for some of us at Old Broadcasting House.
Movember is all about growing a moustache to raise awareness and money for prostate and testicular cancer. There's only one day left and I will be shaving my moustache off as soon as possible. However Chris and Leo like theirs so much they're planning on keeping them for a bit longer into Mocember.
This year's Movember team was (in order of photo appearance):
Leo (fantastic tache) Fowler
Chris (killer whiskers) Kenworthy
Richard (gringo) Garside
Cactus photo by: Alan Levine
-
A .NET MVC Helper to create HTML wrapping elements
In HTML when you want to create a box around some content with rounded corners or some other nice feature it would be nice if you could just wrap that content in a <div> or a <section> tag and CSS would do the rest. However this rarely seems to be the case, particularly if you want the HTML to render well in older browsers. The views in my latest .NET MVC 3 project were full of repeated opening and closing sections of HTML for something that we called a chunk, which is just our word for a box with rounded corners that groups together related elements on the page. Sometimes a chunk …
-
MailChimp Orchard Module and the Integration Fund
Back in November 2010 MailChimp announced their 'One Million Integration Fund'. They were offering pots of money to people using their API to integrate with their product. It was early days for me and my new client working on Pianola, but we both loved MailChimp and thought it could be something that would help us out.
I was also working a lot with Orchard CMS and wanted to use it on this project. As part of building up interest in Pianola while it was being developed we created a sales site using Orchard and we wanted to be able to collect interested people’s email addresses so we could let …
-
Pianola in Toronto
Since December last year I’ve been the lead developer in a start-up making a product called Pianola. Pianola is a web based product to help bridge clubs manage their club and to bring their members a personal way to review their results and interact with the club. This week I’m in Toronto at the North American Bridge Championships demoing Pianola to club managers and members from across the pond.
This has been my first business trip abroad and Toronto is an amazing city. The first thing I’ve learnt is that when travelling for business and when carrying a lot of extra baggage with things like …
-
The Manga Guide to Relativity
I knew I had a sort of idea what relativity was, but I also knew I didn't actually understand it. I thought it was probably one of the things that I would never get round to understanding. Then I was presented with The Manga Guide to Relativity, and I knew that if anything could explain it, then this book would be that thing.
The guide starts in manga form and tells the story of Student Body President Ruka Minagi who is challenged by Headmaster Iyagi to write a report on relativity over the summer vacation. The beautiful physics teacher Alisa Uraga steps in to teach Minagi all he needs to …
-
Stickers are the new business cards
When I first went freelance and needed to meet people, I found that business cards were a staple of the networking world. I knew that I needed some, but as a new face on the networking scene I wanted mine to stand out. I came up with the idea of origami business cards. These have served me well over the last four years and definitely made me stand out, although they didn't always fit in people's wallets.
I fancied a change and also wanted a business card that would fit with the new design of my blog. One problem I've discovered with traditional business cards is that there's nothing obvious …