Wednesday, February 18, 2009

Windows Explorer --- Grrr

Okay, I try not to say anything bad about software that a lot of work has gone into, because, well, I know how hard it is to get it right.

But yesterday I needed to fix a problem on out Team Foundation Server. I needed to get my hands on an executable called TF.EXE. It wasn't (for whatever reason) on my TFS server. Fine, it was supposed to be on my machine (since I have just about every freaking product known to man on my machine it seems). I tried to save myself time by doing a search from my Vista File Explorer (or whatever it is officially called these days). Nothing came back. I hunted around a little bit, searched the web a little bit, and finally just gave up and worked around my problem.

This morning, while fighting another MS-Test - tests not executed issue (if I get one more of these freaking things, I'm going back to NUnit), I stumbled across my C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE directory, and lo and behold, there's TF.exe.

So can someone tell me why the hell File Explorer couldn't find it for me yesterday and save me a hour of my time? Why even bother putting the freaking search tool there if it doesn't work? Anyone? Is there a trick to making it search the whole drive? Arrrgggh.

What a great way to start the day!

Monday, February 16, 2009

MSTest - Grrrrrr

I spent two hours plus this mornign trying to find out why my test harnesses all started returning 'Not Executed' when I ran in 'Run Tests in Current Context", but worked fine in "Debug Tests in Current Context". The tests worked on everyone else's computers.

The solution...

I deleted my entire solution folder, and did a get latest from TFS. What a pain in the ass. I was this close to converting back to NUnit.

Design for Reuse?

I've been reading "Microsoft .NET: Architecting Applications for the Enterprise" by Dino Esposito and Andrea Salterello the last few days, and really enjoying it. It's not a detailed coding book, but discusses patterns and approaches, and is bringing me up to speed on some of the areas of development I haven't yet explored, or have explored but need a refresher on. I actually found myself sitting on the couch on Saturday afternoon while the kids were asleep, reading it because it applies directly to what I am doing this week.

One of the points it made (I should have highlighted it, because I can't find the page now), is that you put interfaces on classes not for reusability, but for replacability. That's a whole paradigm change from what I use to do, but have now adopted with TDD and Dependency Injection.

I used to spend hours trying to factor out what I thought would be common code, and got stuck just trying to figure out how loggers would work (in days before log4net) or data access for a certain class. To me, back then, the money was in designing for future needs.

Now I realize that most of those common modules have already been written, and it saves me a lot more time and money to design each class I write with an interface and to be able to swap it out using dependency injection. I can try and guess for years what my next implementation of a business process might look like, and I will fail 99% of the time. Build what you know now, put it behind an interface, and swap out the old for the new.

It seems pretty elementary now, but even a year and a half ago, I didn't get it. It's like a huge weight has been lifted off my shoulders, and I am no longer stuck in future requirements purgatory!

Friday, February 13, 2009

Good Tests Gone Very Bad

I've been writing dozens of tests lately as I have completely bought in to the TDD methodology. I've even turned on code coverage in Team Suite to see just how I'm doing. This may not be a great thing to do if you suffer from OCD, but it sure has helped me to better understand my code. It helps even more when I am walking through other people's code trying to debug something, as I run their tests first, check to see if any lines of code haven't executed as expected, and then write a test to try to execute that code as I would expect. If I still don't get there, I know one of the core assumptions elsewhere is wrong. Its a lot faster than stepping through hundreds of lines of code. It focuses my attention to the problem area much more quickly.

Yesterday morning, I was flying along, writing code, and writing tests, and one of the other developers here came by to ask how to properly test his ViewModel that depended on checking various items on the file system (i.e. does a directory exist, if not, create it).

We're using Rhino Mocks, not TypeMock isolator, so the fact that these System.IO classes are static means that we can't mock them. A little searching revealed that our best option was to create an IFileManager interface with a FileManager class under it, and mock the interface. Not my favorite thing to do, but it works.

I wrote the tests for the new class, and they ran fine.

Then we added that class to my co-worker's class and exposed a property on his interface / class for the IFileManager so that we could pass in a mock.

I ran his tests for his class in debug mode. It worked. Cool.

We wrote some new tests to pass in the mock, and ran those in debug mode. They worked as expected. Awesome!

But here's where things got hairy.

We went to my test list editor, and added them to our global test list, and reran the tests. The failed with a 'Could not load type error'. Hmmm. Must be something wrong with my set up / tear down. So I reran just one of the tests from the test list editor. Still failed. Okay, back to the code. Rerun the test in debug mode. It works. Run the test in 'Run' mode. It fails. WTF?

Check my tests on the FileManager class. They work fine.

Strip the new code out of the ViewModel class. Run the original tests. Pass.

Run the new tests. Fail. Same error. Wait... the class it says it can't load is the class we have completely commented out. Except we left in the using statement. Comment that out. Build. Still failed, same message.

At this point I'm getting pretty PO'd. I force a clean on my whole solution, and rebuild. Tests pass. WTF?

Start adding code back in. Add the using statement. Pass.

Add the reference to the interface. Failed.

Pull the mocking code out of the tests, pass in a real object (not generated by the AutoMockingUnityContainer). Pass. Okay, it's somewhere in the Unity Code. We're now 2 hours into this. I went through this a dozen times, various combinations, until it finally hit me.

The problem wasn't that it couldn't load my FileManager class. By this time, that class had nothing left in it beside a couple of boolean functions that always returned true. What had happened was that immediately before I had been asked to look at this issue, I had installed the October 2008 release of the Enterprise Application Library (Version 4.1) to make use of the Validation Application Block. I had previously just installed the Unity Framework separately. I now had two versions of the Unity Framework installed on my machine, with the same version numbers, but from different locations on my machine.

I uninstalled the Enterprise Library, restarted my IDE, and ran my tests successfully. I readded all the code I had commented out, and the tests ran as expected. I think we spent three hours on this one yesterday (x2 since two of us were trying to figure it out)

Now I have to decide when to have the team install the app blocks on thier machines, and to remind them to unistall Unity and any old versions first.

Random VS2008 Crashes

For the past few weeks, I've been having a lot of problems with VS2008 crashing randomly on my PC. I've been installing a lot of tools and components lately, so I have little doubt that something I've installed recently was causing it to BSOD (Black Screen of Death in this case).

This morning, I was trying to add the Microsoft.IdentityModel.dll to my tool box, and it kept crashing. I finally had enough, and decided to Google for a solution. The link below fixed the problem on the first try. Yes!

http://www.tech-archive.net/Archive/VisualStudio/microsoft.public.vsnet.ide/2008-03/msg00083.html

Sometimes it pays to spend 2 minutes fixing the problem instead of just ignoring it and hoping it will go away.