-
The Lounge
-
Hosted By
Links
-
Recent Posts
What I'm Doing...
- I'm hoping to make it to ALT.NET Seattle. I may have a 3 month old with me though. Which may raise the level of discourse. 2 hrs ago
- Day 2 of moving 50GB worth of files in Vista. The bar is at about 30%. WTFF?! 2 hrs ago
- Cool, Flickr and Facebook support is built into iPhoto '09. 2 hrs ago
- More updates...
Powered by Twitter Tools.
links for 2008-12-18
18-Dec-08In the last post, the code was pretty clean. Our resident Rhino.Mocks guru at work, Sean, left a comment saying that the new code was much better than the Do-Func stuff I had before. Sean was the one that pointed me to the Repeat.Times methods in Rhino.Mocks. I thought I'd post the old code that I had cobbled together from a StackOverflow answer.
CODE:
-
IDataReader reader = MockRepository.GenerateStub<IDataReader>();
-
-
reader.Stub(x => x.Read()).Do((Func<bool>) delegate()
-
-
{
-
-
m_NumberOfTimesIDataReaderHasBeenCalled++;
-
-
return
-
-
(m_NumberOfTimesIDataReaderHasBeenCalled%2 != 0);
-
-
});
-
-
reader.Stub(x => x["ID"]).Return(Guid.Empty);
-
-
reader.Stub(x => x["FullName"]).Return("Test User");
-
-
-
-
List<UserDTO> list = SearchProvider.ParseUserData(reader);
-
-
Assert.IsNotNull(list);
The re-factored code using the Repeat.Times methods.
CODE:
-
IDataReader reader = MockRepository.GenerateStub<IDataReader>();
-
-
reader.Stub(x => x.Read()).Return(true).Repeat.Times(1);
-
-
reader.Stub(x => x.Read()).Return(false);
-
-
reader.Stub(x => x["ID"]).Return(Guid.Empty);
-
-
reader.Stub(x => x["FullName"]).Return("Test User");
-
-
-
-
List<UserDTO> list = SearchProvider.ParseUserData(reader);
-
-
Assert.IsNotNull(list);
You can see how the second code sample is much cleaner than the first. A lot of the messiness of the first code sample comes from talking to the compiler instead of talking to objects. What do I mean by that? Well, in the first example we have to tell the compiler what the delegate should return
CODE:
-
Func<bool>
You'll also notice some ugliness inside of the delegate body.
CODE:
-
m_NumberOfTimesIDataReaderHasBeenCalled++;
-
return (m_NumberOfTimesIDataReaderHasBeenCalled%2 != 0);
Here, I was incrementing a class member and checking to see if it was odd or even. If it was even, I'd return true, otherwise I'd return false. This allowed me to control the number of times the IDataReader.Read() method would return true. In this case, it would return true once, then the variable would be incremented to an odd number and the Read method would return false.
That's all part of me telling the compiler what to expect, when what I really want to do is just tell my objects what to do. This episode of the Alt.net podcast also talks a little bit about class-based programming versus object-oriented programming.
links for 2008-12-17
17-Dec-08Wubi - Ubuntu Installer for Windows
16-Dec-08Wubi - Ubuntu Installer for Windows
I've been running Linux on various boxes for years. For the most part, Iv'e either dedicated a machine completely to Linux, run Linux in a VM, or dual-booted. The dual-boot always required setting up a separate partition and messing with the boot.ini, or whatever, file after installing Linux into the new partition. Then I discovered the Wubi project.
Wubi lets you install Ubuntu into a virtual partition, represented by a file, and modifies your boot loader, adding a new entry. It will automatically detect your CPU type and download the appropriate version of Ubuntu (e.g. If you are running an AMD x64 chip, it will download the AMD x64 version of Ubuntu). You can select from four different desktop environments, KDE, GNome, XFCE, or the Mythbuntu media server.
After you install and reboot your machine, your new Ubuntu installation will appear in your list of boot options. All without the need to shrink and create new partitions.
If you are thinking about trying Unbuntu, but don't have the resources to run a VM or re-partition your machine, I'd encourage you to try Wubi.
