Identity Interface


April 25, 2007

Mock Objects in C#

Category: code – jonshern – 10:35 pm

From what I have seen there are 3 solutions

NMock, RhinoMock and TypeMock.

NMock and RhinoMock are opensource and free. TypeMock is free*, which means they have a community edition that is free and an enterprise edition that you have to pay for.

TypeMock is much more robust than the previous two solutions.  I would go with NMock or RhinoMock if you are just starting a TDD solution and you want a mock framework.  If you are adding Mock objects to an existing solution I would go with TypeMock.

With RhinoMock and NMock you need interfaces to facilitate the creation of your Mocks.  TypeMock you just need code.  You can create mock objects from methods, concrete classes, and even sealed classes.

Mocking works good for telling a test what methods we know will be executed and then verifying those calls are performed.

A great example would be

You have a data layer that returns datasets. You want to test code that touches the datalayer but you do not want to actually access the database.

You would create a mock object like

DataTable expected = null;
DataTable actual;
MockManager.Init();
Mock dataLayerMock = MockManager.Mock(typeof(DataLayer.Widgets));
 
DataTable dt = new DataTable();  
//here you could mimic the structure of what the datalayer will return
dataLayerMock.ExpectAndReturn("GetWidgetsThatNeedToBeShipped",dt);
actual = BusinessLayey.Widgets.GetWidgetsThatNeedToBeShipped();
Assert.AreEqual(actual, dt);     
//in this case the business layer just passes the datatable from
//the datalayer to the presentation layer,
//so they would be equal, and the test would pass.
 
MockManager.Verify();

April 5, 2007

Tracking Renewable Energy

Category: energy, environment – jonshern – 9:22 pm

The great plains institute just released news of a new software called M-RETS(Midwest Renewable Energy Tracking System).

Basically it is a app that allows Minnesota, Wisconson, Iowa, and Manitoba to trade renewable energy in a market type scenario.  This will function to keep the cost down, and encourage the use and development of more renewables.

I think this initiative will go along way in providing the necessary push we need to move in the direction of renewable energy.

Parking at “The Mall”

Category: business, wastefullness – jonshern – 9:12 pm

After many years of talking about phase two of the Mall of America it is finally starting to move.

I heard through the grapevine that each parking spot costs $25000.

Wow that is a lot of money, and there will be about 7000 spots.

So just giving people room to park will cost 175 million dollars, and they say mass transit is expensive:)