Insights and outlooks on software development

S'true

NUnit and lambdas

Saturday, November 29, 2008 by Thomas L

So as you may have noticed, I really love lambdas. Having the possibility to write code like the row below makes my code more readable.

List<Person> people = peopleRepository.FindAllByName("Thomas");
int totalAge = people.Sum(person => person.Age);

So I would like to use lambdas and list iterations to assert things in NUnit, e.g. like this:

Assert.Contains(people,
  person => person.FirstName == "Thomas" && person.LastName == "Lundström",
  "The list should contain Thomas Lundström");

That way it's way much more readable than how I have to do to get the same functionality today:

Assert.AreEqual(1,
  people.FindAll(person => person.FirstName == "Thomas" &&
    person.LastName == "Lundström").Count,
  "The list should contain Thomas Lundström");

I think it would be a fun project to implement it.

Technorati Tags: ,,,,

Filed under , , having  

0 kommentarer: