2009-09-24

Great Lean/Kanban Post

... with a big extra plus for letting me know about "Pirate Metrics" for the first time:
http://raibledesigns.com/rd/entry/lean_teams_doing_more_with

Trying out Sharp Tests Ex with NUnit 2.5

/*before*/ Assert.That(logHandlersCount, Is.EqualTo(1));



/*after*/ logHandlersCount.Should().Be.EqualTo(1);




Even better readability :-)

More on Sharp Tests Ex here: http://sharptestex.codeplex.com/Wiki/View.aspx?title=SyntaxMainPage

2009-09-18

A NUnit Custom Constraint together with a String Extension Method

[Test]

public void WhenMyStringPropertyIsEmptyThenMyEntityMustBeInvalid()

{

var myEntity = new Entity { MyStringProperty = string.Empty };


Assert.That(myEntity, "MyStringProperty".IsIncludedInBrokenRules());

}


IsIncludedInBrokenRules() is an extension method that returns an instance of a class that inherits Constraint.

2009-09-08

SQLite - works on my machine ;-)

I have this new and shiny HP Z600 (x64) at work.

Recently I started using SQLite in-memory for unit testing NHibernate persistence logic.

When committing, my dear colleague with an older x86 machine got problems...

I reproduced the problem on my machine by setting the build target to x86 in VS08.

Just change to the 32-bit version of SQLite did the trick.

2009-09-02

Linq Group By

 

        [Test]

        public void CanAggregateIdAndValue()

        {

            var idValuePairs = new List<IdValuePair>

                                   {

                                       new IdValuePair(1, 1),

                                       new IdValuePair(1, 2),

                                       new IdValuePair(1, 3),

                                       new IdValuePair(2, 1),

                                       new IdValuePair(2, 2),

                                       new IdValuePair(3, 1),

                                       new IdValuePair(4, 1),

                                       new IdValuePair(4, 2)

                                   };

 

            var expectedAggregatedIdValuePairs = new List<IdValuePair>

                                   {

                                       new IdValuePair(1, 6),

                                       new IdValuePair(2, 3),

                                       new IdValuePair(3, 1),

                                       new IdValuePair(4, 3)

                                   };

 

            var aggregatedIdValuePairs = Aggregate(idValuePairs);

 

            Assert.IsTrue(expectedAggregatedIdValuePairs.SequenceEqual(aggregatedIdValuePairs));

        }

 

        private static IEnumerable<IdValuePair> Aggregate(IEnumerable<IdValuePair> idValuePairs)

        {

            // imperative OO

            /*var map = new Dictionary<int, int>();

 

            foreach (var idValuePair in idValuePairs)

            {

                if (map.Keys.Contains(idValuePair.Key))

                {

                    map[idValuePair.Key] += idValuePair.Value;

                }

                else

                {

                    map[idValuePair.Key] = idValuePair.Value;

                }

            }

 

            foreach (var aggregatedIdValuePair in map)

            {

                yield return aggregatedIdValuePair;

            }*/

 

            // declarative linq

            return (from ivp in idValuePairs

                   group ivp by ivp.Key into aggregateGroup

                   select new IdValuePair(aggregateGroup.Key, aggregateGroup.Sum(x => x.Value)));

        }