The blog has moved to ... Many google searches point here so I am leaving it operational, but there will be no new posts.

Monday, February 18, 2008

First-annual Amgen Tour of California Women's CRITERIUM

First-annual Amgen Tour of California Women's CRITERIUM

First-annual Amgen Tour of California Women's CRITERIUM

Saturday, February 16, 2008

Rails like migrations in the .NET world

I have done a few very small projects with rails; one of the really nice features with rails is database migrations

There are a few ports of rails migrations to the .NET world (that's where I spend alot of my time). I have not used any of these for 'real' but I have 'sampled' them. They all look promising but it seems like there is not very much activity on these projects.



SubSonic Migrations
I don't know if they ever did incorporate this into the official release of sub sonic? maybe it will come in a future release

I recently stumbled across vincent-vega and have begun using it on a small project and am planning to incorporate it into some of our larger applications. It is an Nant task that handles database versioning. It is not a migration in the same way as the other solutions as it uses actual sql scripts for all schema changes instead of c# code, which makes sense to me!

[update 2008/10/14]
vincent-vega is now part of the tarantino project.
Thanks for the heads up Dan!


Rhino.Mocks basics

Rhino.Mocks basics - I just threw this together real quick; personal reference material

The official Rhino Mocks Documentation is very good and available here

Rhino.Mocks - the basics

Started using Rhino.Mocks recently (Awesome!!!) - just wanted to list a few of the basics; the official Rhino Mocks Documentation is very good and available here. These examples are a bit rough, they have not been compiled; there may be typos.

using Rhino.Mocks;

The mock repository
// use the mock repository to create the mocked objects
MockRepository mocks = new Rhino.Mocks.MockRepository();
// example
System.Object someObject = mocks.CreateMock();
// set up the behaviour you want from calls to your mocked object 
// then don't forget
// now do stuff that calls your mocked object Equals method

Mock a call to the db
// create our mocked repository object - IProductRepository, the real one calls the db
IProductRepository repository = mocks.CreateMock();
// tell rhino.mocks when we call the method GetProduct with the argument 33 to return null
// get the mocking ready
// pass our mock to our product service layer
ProductService service = new ProductService(repository);
// service.GetProduct makes a call to the mocked repository.GetProduct which will return null
IProduct product = service.GetProduct(33);
// should be null

Ignore any arguments
// any call to GetProduct will return null no matter the value of the arg

mock a method that returns void
IProduct product = new Product("003092", "Sierra Nevada", 6.49);
// this void call will handle our product 003092
Rhino.Mocks.Expect.Call(delegate { repository.Save(product); });
// this void call will handle any argument
Rhino.Mocks.Expect.Call(delegate { repository.Save(null); }).IgnoreArguments();

Handle multiple calls to the same method
IProduct product = new Product("003092", "Sierra Nevada", 6.49);
// note the .Repeat.Any()
// send the mock to our product service object
ProductService service = new ProductService(repository);
// find by sku calls GetProduct on the mocked Product repository
IProduct beer = service.FindBySku("003092");
// find decent beer calls GetProduct on the mocked Product repository also
IProduct decentBeer = service.FindDecentBeer();

Partial Mock
// create a partial mock with constructor args (our product repository again)
IProductService service = mocks.PartialMock(repository);
// our test case data
IUser loggedOnUser = new User("John", "Doe", CustomerType.Gold);
// mock product service calls to GetLoggedOnUser
// get the mocking ready
// now GetDiscount is not a mocked method but it does call the mocked GetLoggedOnUser method
decimal discount = service.GetDiscount();
// assert the result
Assert.AreSame(44.4M, discount, "Gold customer discount not correct?");
// NOTE: this will not work (compile) unless the mocked method GetLoggedOnUser is public

SyntaxHighlighter and Google Blogger

Just started using the SyntaxHighlighter on my code samples blog - here is some quick notes on what I had to do

One issue I ran into was that the google blogger automatically adds br tags where newlines appear in any content - makes the code pretty much unreadable, but the fix is well documented and easy to implement -