# Tuesday, May 19, 2009

I’ve been attempting to learn NHibernate lately. One of the big draws for me was the ability to write unit tests that did hit a database, but an in-memory one. Ayende recently posted on how to use SQLite to get in-memory unit tests. His example assumed standard hbm mappings and configuration.

I was curious how hard it would be port his example over to Fluent NHibernate. Not surprisingly, it was quite easy actually!

Here’s the Blog entity I used, which is based on the usage I saw from Ayende’s post:

And here is the mapping:

As you can see, it is pretty straight forward so far. The next piece of code is the Fluent NHibernate implementation of Ayende’s InMemoryDatabaseTest.

There aren’t too many differences really. We’re using the same SchemaExport, but we do need to call ExposeConfiguration so that we can store off a reference to the Configuration to be used by the SchemaExport instance.

The final piece, the actual test itself, is identical to Ayende’s example, except that I’m using MbUnit instead of xUnit:

Nice and easy! I like it!

As you can also tell, I’m experimenting with using github’s gist feature. I’ve been using github to store off my dot files and other environment-related settings as well as my presentations, but the gist feature seems pretty nice.

posted on Tuesday, May 19, 2009 12:34:06 PM (Central Daylight Time, UTC-05:00)  #    Comments [0]
# Tuesday, May 12, 2009

I blogged a while back about finding in files with PowerShell and I wanted to share an update on that.

The original post highlighted using a combination of Get-ChildItem and Select-String to quickly find things. It works fine, but the output isn’t the easiest to read, because the found text isn’t highlighted in any way.

Get-ChildItem –include *.cs –recurse | Select-String searchText

image

I really like the color output that grep provides. Check out the results of grep on the same search.

find –name *.cs | xargs grep StringBuilder

image

That is so much easier to read that it isn’t even funny. The match jumps out at you because of the color difference.

I did some searching and found Wes Haggard’s Find-String script. It had the additional benefit that it also displayed the line number, but it didn’t display the relative path.

find-string.ps1 StringBuilder *.cs -recurse

image

Wes’ script still served my purposes, though, so I used it for a long time until I learned about grep’s Context Line Control arguments. They would let grep print out additional lines before or after the display search result so that you could see the context of your search result. Like so:

find –name *.cs | xargs grep StringBuilder –A 3

image

Unfortunately for me, PowerShell’s Select-String didn’t support context… at least until version 2.

With the addition of the Context parameter, I could now build a nice grep replacement in PowerShell. I broke my version out into two separate scripts: one to actually format the MatchInfo object and one to do the finding. As you might imagine, the formatting script is a little more interesting. You can get Out-ColorMatchInfo at http://poshcode.org/1095 and you can get my version of Find-String at http://poshcode.org/1096.

Here’s sample output:

find-string StringBuilder *.cs –context 0,3

image 

I went with only displaying the relative path to the file on one line and then displaying the results on the following lines. It makes reading context easier for me.

Let me know what you think.

posted on Tuesday, May 12, 2009 2:55:25 PM (Central Daylight Time, UTC-05:00)  #    Comments [3]