Getting up and running with Database testing quickly in .NET

When I first started learning about how to do database code in .NET and in particular how to test your database code I came across a really useful post on the Code Project.

It basically goes through a tutorial on how to get a base class set up that sets up a brand new SQL Server CE database every test run and populates it from an NHibernate configuration.

This was great, but there were a number of issues that caused it to not work for me (including the fact I decided to use Fluent NHibernate rather than writing a heap of obscure XML). As well as this, there were a couple of fundamental flaws in the way the test worked and it didn’t work with the latest versions of SQL Server CE and NHibernate at the time.

Consequently, I fixed up the code so it worked and I wanted to outline those changes and the final result here in case anyone finds it useful.

Continue reading “Getting up and running with Database testing quickly in .NET”

Terse controller testing with ASP.NET MVC (part 1)

As I alluded to in a previous post, I think that achieving high code coverage in controller tests is often a waste of time in terms of return on investment – most of the stuff in there will be trivial things that either work or don’t and will be hard to regressively break (e.g. returning the view with the model if model validation failed). In saying that, if there is a way to get really terse tests then they become easier to write and maintain and then it’s worth aiming for high code coverage (since the reward outweighs the cost).
Continue reading “Terse controller testing with ASP.NET MVC (part 1)”

Coding Naming Conventions: Australian (or British) vs. American English

I really dislike American spelling of words. Nothing personal, but I guess growing up with knowledge about how words are spelt and then seeing words spelt “wrong” is frustrating (particularly when you can’t turn off a US spell-checker and it keeps “auto-correcting” your words to incorrect spelling).

Something my team has a discussion on this week was what our naming convention should be for words that have different spelling in US English vs Australian English (the most common one that has come up lately is finalise vs finalize).
Continue reading “Coding Naming Conventions: Australian (or British) vs. American English”

Source Code Indentation

I hate using spaces for indentation. I’m just putting it out there. My work mates think it’s a bit silly to have such a strong opinion on such a minor (mostly invisible) thing, however the pedantic perfectionist in me feels strongly about this.

Why do I hate using spaces for indentation? I’ll let the comparative advantages (and disadvantages) speak for themselves.

Continue reading “Source Code Indentation”

Simulating Tag Syntax with Razor Templating

When using a templating language to output HTML it’s often quite useful and natural to have the concept of a “tag” syntax e.g. (using some random custom ColdFusion tags as an example):

  • Self-closing: <cf_form_field label="Some Label" value="The value" />
  • Nested: <cf_form_section heading="Some heading"> ... </cf_form_section>

The tags would implicitly output to the page and can be side-by-side with HTML code without needing start and end code delimiters (such as <% … %> or <? … ?>, etc.).
Continue reading “Simulating Tag Syntax with Razor Templating”