Monday, August 29, 2011

SpecFlow Tests and Lists

Some days I just can't see the forest for the trees...

Sometimes you just want to pass a list to check against:

Scenario: some files match
	Given I have the following files
		| FileName           |
		| test.txt           |
		| sample.txt         |
		| sample.file.txt |
		| sample.file2.txt |
		And  I have the following processes
			| Regex        | Process         |
			| sample.*.txt | TestProcess.bat |
	When I run the application
	Then The files should be processed
		| FileName           |
		| sample.file.txt |
		| sample.file2.txt |

If you're using SpecFlow and need to pass in a list to one of your bindings, here's a simple one-liner to convert a table to a list of strings:

[Given(@"I have the following files")]
public void GivenIHaveTheFollowingFiles(Table table)
    var files = table.Rows.Select(o => o["FileName"]);

'files' will be a list of the strings in the table. I'm sure there's a better way, but this one works.

Monday, August 15, 2011

Useful Things

Edit: Updated Feb 2012 to reflect new stuff I'm using...

A loooong time ago, an associate asked me to come up with a list of useful things. This post is the start of that. It's a dump of some of the things I use on a daily basis along with my comments:

Development Tools
  • Visual Studio - Goes without saying.
  • NuGet - Package manager (with VS integration). Must have.
  • ReSharper - Excellent helper tool. Enhances Visual Studio's UI. Well worth the money.
  • VS10x Code Map - Adds a new view of the code file you're working in. Really useful when your mates like to have 10 classes and 2500 lines of code in one file.
  • dotPeek - Also by JetBrains. An excellent source code explorer.
  • NCrunch - Runs your unit tests while you code. Immediate feedback. Or, ZMOG! Why aren't you using this now!!
  • FluentAssertions - Make your test assertions read more like English. This really is something you should use in all your tests.
  • NSubstitute - A very good mocking framework. I use this one over Moq, because I like NSubstitute's interface better.
  • Moq - Another very good mocking framework.
  • NHibernate - Flexible, powerful, and has tons of support. What more could you ask for? why aren't you using this?
  • FluentNHibernate - I used this as much for almost all my data access, until the loquacious (in-code) stuff was added to NHibernate.
UI Stuff
  • jQuery & jQueryUI - Must have when it comes to doing JavaScript stuffs.
IoC Containers
  • Castle Windsor - This has become my main IoC Container. The interceptors work well enough for AoP, and I really like the facilities.
  • Unity - IoC container from Microsoft. I've switched to this, simply because I like the intercepts for AOP better than Ninject.
  • Ninject - Open source IoC Container. I used this one a lot, still occasionally do.
Source Control
  • TFS - The main MS one.
  • Git - Open source SCM, with free project hosting options. I like this better than TFS, but I have to use TFS at work.
  • VisualHg or TortoiseHg - Mercurial for Windows types.
Misc Tools