Tag Archives: C#

Comparing Design Patterns in Ruby and C#: The Command Pattern (with Robots!)

The command pattern is another one of those patterns that we all (whether we realize it or not) see almost every day. It’s commonly used in UI development but it’s a pattern that can be applied in many situations. In rails, ActiveRecord migrations are a perfect example of a command implementation, including “up” and “down” [...]

Read Post

Comparing Design Patterns in Ruby and C#: The Iterator Pattern

Continuing our exploration of design patterns in Ruby and C#, we’re going to dive into the Iterator pattern. Like most design patterns, if you google (or bing) for an example you will run into several different implementations because there are many ways to iterate a collection of objects. In it’s classic (well, classing in the [...]

Read Post

Comparing Design Patterns in Ruby and C#: The Composite Pattern

In the last post of the series, we took a look at the Observer pattern. This time we’re going to explore the Composite pattern. The Composite pattern gives us the ability to take a complex procedure that may involve many steps and turn it into something that is simple for consumers to use. The classic [...]

Read Post

Comparing Design Patterns in Ruby and C#: The Observer Pattern

Continuing our comparison of design patterns in Ruby and C#, we’re taking a look at the Observer pattern. With this pattern, we have a subject and a list of observers that are interested in knowing when changes occur on the subject. This happens in a push model, the subject maintains the list observers and notifies [...]

Read Post

Comparing Design Patterns in Ruby and C#: The Strategy Pattern

In the previous post of this series, we looked at how the Template pattern is implemented in both Ruby and C#. In this post, we’ll take a look at the Strategy pattern…one of my favorites. In it’s classic form, the Strategy pattern consists of a context class and various “strategies” which share a common interface. [...]

Read Post

Comparing Design Patterns in Ruby and C#: The Template Pattern

Most of my career has been in .Net development and I’m pretty comfortable applying design patterns in C#, but as I’m learning Ruby, I was finding it difficult to figure out how to implement them without creating awkward, hard-to-read code. Recently a local Ruby guru, Nate Klaiber, recommended that I pick up the book Design [...]

Read Post

Using Reflection to Find the Connection String Being Used By NHibernate

In my last post, we discussed how to run a Sql script from C# to insert lookup data when we regenerate our database for integration tests. But we want to make sure that the connection string that’s being used by NHibernate is the same connection string being used by our InsertTestData() method. To do that, [...]

Read Post

Running a Sql Script to Insert Lookup Data For Tests From C#

Earlier this week I needed a way to insert test data into my database that was being regenerated at the start of each test fixture. For most scripts, you can use a simple command with CommandText to get the job done. But this doesn’t work with certain Sql statements, such as GO. Luckily, I stumbled [...]

Read Post

Testing for Expected Exceptions Without Compromising BDD Conventions

Today I decided to relearn some of the BDD concepts I picked up at the end of last year and ran into a scenario where I needed to test that a specific type of exception was being thrown by a method. The simple way to do this is to decorate your test method with an [...]

Read Post

Sorting generic lists using IComparer<T>, IComparable<T>, and the Comparison<T> delegate

Within .Net 3.5, we were given Linq which makes working with generic lists a piece of cake. But if you’re like me, you probably still find yourself supporting a lot of code bases that have been written in the 2.0 framework for clients that aren’t ready to move to 3.5. However, .Net 2.0 did bring [...]

Read Post