• Post Calendar

    May 2017
    S M T W T F S
    « Apr    

Posts Tagged ‘Unit Testing’

How can I unit test unsubscribing from an event? (C#)

I’ve seen some strange bugs that occur when you don’t properly unsubscribe from events. But it seems I’m always stuck when it comes to unit testing that. Well, I use Moq for most of my mocking and there are some techniques you can use for testing that your subscribed, namely by Raise(ing) the event in […]

How to Write Bad C# Code

In case you’re afraid Microsoft might help you write some good C# code, here’s a list of the top tips to make sure you still write bad C# code. Now I’m sure that’s not the objective, but when you read this post you’ll frankly wonder why it is that we still see so much bad […]

Visual Studio 2012 testmc Code Snippet

Headline: This contains the code for the first code snippet I install when I have a new installation of Visual Studio along with the steps to get it into the right location. The Result The first time I saw this format for unit tests was in some work the Microsoft ASP.NET MVC (Model View Controller) […]

Where is TestContext.BeginTimer()?

This post outlines my (with help of others) solution to keeping my unit tests working in the absence of TestContext.BeginTimer() and TestContext.EndTimer(). These seem to be missing in Visual Studio 2012 and I can’t find any posts… so I assume no one else uses this pattern. What’s Broken? Here is a sample unit test that […]

TDD Saves Time When You Need It Most

In the life of a project when is time most precious? The first day? Or the last day? Writing unit tests makes sense, but are you disciplined enough to write them? I understood the value of writing unit tests and had used them on numerous projects. I knew you should write them but I had […]

A Strategic Case for Unit Testing

There is a certain level of velocity and quality that you will never reach without effective unit testing. I’ve had an unusual number of queries about unit testing during the past few days. As a result I thought I would put a more complete description together. Definition I’m not going to spend a great deal […]

Did I Ever Mention I Like TDD?

I’m working to change an older application to one that uses the MVVM (Model-View-ViewModel) pattern. I’m trying to change it one piece at a time, and what a hassle it’s become. I’ve come to the conclusion that a complete re-write is in order. And when I re-write I’ll be using TDD (Test Driven Development). Singe […]

MVC 3 Breaks Error Tracking in CodeSmith Insight

I finally have the Crash Reports working again with CodeSmith’s Insight. The release of MVC 3 provided a new way to deal with errors using the HandleErrorAttribute. The changes to the Global.asax.cs file look something like this: Application_Start     protected void Application_Start()     {         AreaRegistration.RegisterAllAreas();           // Added this when converting to MVC 3         RegisterGlobalFilters(GlobalFilters.Filters);           RegisterRoutes(RouteTable.Routes); […]

Unit Testing HandleErrorAttribute

Code Analysis doesn’t like the former MVC pattern of using a catch for all errors when updating a model. I wanted to use the HandleError attribute to deal with errors, but how should I unit test it? There are several keys to having the HandleError attribute work: Must decorate the Action with [HandleError] Must have […]

SmtpClient.Dispose() Bummer

Headline: You will need to put in some try/catch logic when you call dispose on the SmtpClient. I was working on getting rid of some of my code analysis warnings – “Warning    10    CA2000 : Microsoft.Reliability : In method ‘AccountMembershipService.SendActivationEmail(HttpContextBase, string, Guid, string, string)’, object ‘client’ is not disposed along all exception paths. Call System.IDisposable.Dispose […]