Wednesday, June 06, 2007

ReSharper And Other Trivia

As Jim has recently explained, ReSharper 3.0 is now available in beta and for the first time supports VB.NET. As the majority of the code I work with each day is VB, I have, also for the first time, installed ReSharper. I am enjoying the experience so far and it works well across both VB and C# projects in the same solution.

However, as I've mentioned before, I use C# projects to test VB production code and ReSharper was failing to consider InternalsVisibleTo attributes and incorrectly marking code in my unit tests as erroneous. Thankfully Visual Studio still built and executed the code fine. Also very impressive was how quickly the guys at Jetbrains had solved the bug once I had emailed them. Try the nightly builds here for the latest version.

As a side note, if you're working with the InternalsVisibleTo attribute, you may find fellow Australian developer David Kean's generator very useful for extracting the rather long assembly PublicKey.

Now, if I can just convince ReSharper to give back my F12 key.

 Tuesday, June 05, 2007

SQL Server 2008

It's hard to keep up. Microsoft have recently released the June CTP for SQL Server 2008. You may need to sign in with your Windows Live ID to follow that link and you definitely need to apply for the SQL CTP program if you want to download it. I guess it makes sense for us to start seeing SQL 2008 now as it probably coincides with the Visual Studio 2008 RTM later this year.

Finding Closure

Scott Hanselman recently posted about troubles with external hard drives and large files. However, while file systems and compatibility between multiple OSes is quite a problem on it's own (and one I'll still need to solve for myself soon), I've been wrestling with a different large file issue.

Several months ago I purchased (separately) a Samsung 40GB 2.5" PATA hard drive and a USB external hard drive enclosure to suit for quite a low price from eBay. Most of my data trafficking between home and work consisted of Office documents, source code, and other assorted small files. All was well.

Since then, I have needed to transfer Virtual PC images, MSDN DVD images, and server backups and I have had no success. Without any error messages during the copy process I was finding that files over ~400MB copied to the external drive were corrupt. They had the same length as the original but a command line FC /B or an FCIV revealed that random bytes were different.

Extensive Googling suggested motherboard USB power issues, cable quality problems, hard drive faults, and write-caching settings as potential causes. I methodically checked each possibility by using different machines, PCI USB controllers, new cables, a different 2.5" hard drive, and playing around in Device Manager. Nothing helped.

A few weeks ago, my local computer store had a special on Western Digital Passport Portable Drives. The Western Digital brand has always been good to me and I figured I could try one and have someone to complain to if it didn't work. I bought one and since then I've been moving all sorts of large files around (including 16GB Windows backups) without any problems.

That's just one more time for me, learning the hard way to stop buying cheap components and instead to just fork out for the quality brands up front. It's like washing a spoon under a running tap: occasionally you forget what happened last time and you get wet. So if you're getting corrupt files on an hard drive in an external enclosure, just cough up the cash and buy something better.

 Monday, June 04, 2007

Capture To Team Foundation

Dudu Shmaya has just released a plugin for Cropper to create TFS work items from screen captures. You can also use it to add screen capture attachments to existing work items. We already use both Cropper and TFS, and this new plugin should be very useful for creating bug reports.

Dudu says he plans to submit the source code for his plugin to the CodePlex project for Cropper plugins soon. Looks like there are some other nice plugins already on their too.

 Saturday, June 02, 2007

Sharpen Your Unit Tests, Forget VB

We are entering a new stage of development at work, we've released betas of three modules and are now beginning the initial iterations for two new modules. We are taking this opportunity to push unit testing into our standard development cycle, which is something I've wanted to do for a long time.

With friend and work colleague, Jim Burger, leading the charge to unit test and document our common libraries, some "best practices" that suit our project model are starting to reveal themselves.

For each project under test, we create a corresponding test project with the same name suffixed by "Tests". This keeps the projects paired together in the Solution Explorer and creates default namespaces for the projects that are just different enough to avoid clashes.

Within the test project we then create a folder for each class under test and within those folders, we create a unit test class for each function under test. We've found that each function usually requires at least three tests (null guard test, common case, edge case) and giving each function it's own file keeps our tests manageable.

Most importantly, while all our production code is in VB, we write our unit tests in C#. One of the main reasons is that the C# compiler respects the InternalsVisibleTo attribute and allows us to test code marked as Friend without resorting to reflection in our tests or putting test-only code in our production projects.

We also get the nice benefit that C# will automatically put classes in namespaces that match the folder structure in the project. This provides a simple mechanism to categorise our tests for running them and viewing the results. C# also tends to produce slightly more succinct code which just feels better as the number of tests grows.

Although both VB and C# have their pros and cons, the majority of the .NET world is C# and so are the job opportunities. As a VB programmer, by using C# for at least some of your work, you make sure you are learning more aspects of .NET and when you get involved in the .NET community you're more likely to appreciate what they're talking about.


This post brought to you by Windows Live Writer Beta 2.

kick it on DotNetKicks.com
 Thursday, May 31, 2007

Virtual Library

Microsoft now has a collection of Virtual PC/Virtual Server VHD images to trial a decent range of their enterprise products. They currently have Windows Vista, Visual Studio 2005 Team Suite, Windows Server 2003 R2, SQL Server 2005, Exchange 2007, and several others. These should be really useful for testing their new products without requiring a spare machine and also for testing your own software against their various platforms. Hopefully they will continue to keep their images up to date and expand on the packages available.

 Wednesday, May 30, 2007

Dude, Here's Your 4 Gigabytes Of RAM!

I recently purchased a HP dc7700 SFF PC for my home office and installed Windows Vista Business x64. I regularly use Visual Studio 2005 and SQL Server 2005 x64 on this system for bringing work home with me and for doing personal development projects. I have also been testing the Orcas Beta 1 Virtual PC image that Microsoft has made available. Based on my experiences with Windows XP 32-bit, I figured 2GB of memory would be sufficient for my new machine.

I've since discovered though that Vista x64 and SQL x64 are very memory hungry and I usually have to close several applications just to free the 1GB required by the Orcas VPC. Not being happy with the performance hit from paging, I started looking into installing more memory. Jeff Atwood had posted about the 4GB problem only a few weeks earlier and was one of the motivators for choosing a 64-bit OS and the dc7700 has the Intel Q965 Express chipset and four DDR2 slots, both of which support a maximum of 4GB. However I could not find any reliable documentation that suggested whether the BIOS in the dc7700 supported the memory remapping feature that would allow Vista x64 to utilise all the RAM.

Thankfully, I have an awesome contact in the HP reseller channel who was able get my query passed along to the right people and get confirmation on whether it would work or not. I was a little impatient and I had already ordered the new RAM before the answer came back. The new memory modules arrived today and I am pleased to say, as was promised by my HP guy, if you own a HP dc7700 like mine, you can install a full 4GB in the system and Vista x64 will happily see the whole lot. Well, it actually only reports 4031MB but I'm not going to complain about 65MB... yet.

 Sunday, May 27, 2007

DataSet Diagrams

We often use Strongly-Typed DataSets in our applications at work. They can be a useful tool but they have their limitations too. Today, I'm not going to discuss the pros and cons of DataSets versus some other DAL concept. Today I'm just writing about a useful tip for working with growing DataSets.

As changes are made to tables and relationships in the DataSet Designer, eventually all the diagrams become unordered and relationship links begin to wander like vines. Unfortunately, I have never been able to find in Visual Studio an option to re-layout the diagram automatically for optimum table sizes and minimum relationship intersections. You don't have to shuffle them around manually though, there is another way:

  1. Open the project containing the DataSet and Show All Files in the Solution Explorer.
  2. Ensure the DataSet designer windows are closed.
  3. Open the DataSet's .XSS file in a code window (it should be XML with <Shape> elements among others).
  4. Clear the entire contents of the XSS file, leaving it blank.
  5. Save the XSS file and close the window.
  6. Open the DataSet's designer window, you should find all the tables and relationships nicely arranged.

It's been a busy day but I should have another overly long post ready in time for next week.

 Saturday, May 19, 2007

The Diet Coke Of Unit Testing?

I have been wanting to make use of Unit Testing in my personal projects and my projects at work. So far I've read a lot about unit testing concepts and implementations and even written a few tests to get a feel for it. The majority of the material that exists about unit testing in .NET refers to the NUnit testing framework. The is presumably because it was one of the first .NET unit testing frameworks and based on the well established JUnit. However, now that Visual Studio 2005 includes it's own unit testing framework, why wouldn't you want to use that?

Jean-Paul Boodhoo once blogged1 that when a new developer joins your team they should be able to Get Latest from source control, build, and be ready to work. I agree and using tools included in Visual Studio means one less dependency for a new developer to install on their workstation. However, there is the possibility that Visual Studio's Unit Testing, as a version 1.0 product, might be lacking important functionality to be found in established testing tools. A quick Google for "visual studio unit testing vs nunit" leads to a few notable issues.

Jason Anderson explains that only Visual Studio Team Suite includes the Unit Testing tools and that Visual Studio Professional misses out. We all use Team Suite at work so this isn't a problem but I can understand that unit testing should be available developers in all team sizes. Thankfully, Naysawn Naderi says that we can expect Unit Testing in Visual Studio Pro when Orcas is released.

Roy Osherove also has two posts about choosing between Visual Studio Unit Testing and the alternatives. Roy's comments makes VS Unit Testing seem completely useless and claims some parts are broken and even says "how this one went by into the release is a mystery to me". However, I recently had the pleasure of working with VS Unit Testing briefly when contributing to the BlogML project and some of Roy's claims just felt wrong. Surely it can't be that bad. Considering we will want to decide on a testing framework for projects at work soon, I decided to verify these problems.

Roy's first complaint is that there is a bug with the ExpectedException Attribute checking the type of the Exception only and not checking the Message. This is in fact a misinterpretation of the VS Unit Testing ExpectedException Attribute and assuming it was designed the same as NUnit's counterpart. NUnit takes an Exception type and message and verifies that the right Exception is thrown and that is has the matching message. VS treats the message parameter that same as an Assert statement and uses it as the display message to the user when the test fails, admittedly the MSDN documentation is very poorly worded. However, achieving the same behaviour as NUnit is often desired and there is a quick solution:

[TestMethod()]
[ExpectedException(typeof(InvalidOperationException))]
public void ExceptionWithMessage()
{
    try
    {
        MethodToTest();
    }
    catch (InvalidOperationException ex)
    {
        Assert.AreEqual("Expected message.", ex.Message);
        throw;
    }
}

Roy is also disappointed that ExpectedException doesn't work with the base Exception type. Sure it's something the unit testing framework doesn't support but you shouldn't be throwing Exception objects and you shouldn't be catching them either. You can also use the Test Results window to group by Result (ie Passed/Failed), Class Name, and Full Class Name (ie Namespace too), this makes locating the tests your interested in much easier and also negates Roy's corresponding observations with regard to Test Driven Development.

VS Unit Testing isn't perfect though and that's to be expected for a first release. As Roy points out, you can't easily get to the failing production code from a failed test result, it doesn't have quite as many included Asserts as NUnit does and you do need to have Visual Studio installed to use the MSTest command line test runner. For the time being, our requirements don't push VS beyond it's capabilities, Orcas should improve on the weaker points when it's released later this year (?) and it is really easy to convert between NUnit and VS Unit Testing if we need to.

So, if you're looking to choose a unit testing framework, don't be put off by some of the articles flying around about VS. Give NUnit and VS Unit Testing a go and maybe MbUnit and some of the others too. Ultimately you'll find something that you and the rest of your team are comfortable with and fits your process. I can't say that any of them are perfect, nor are any flawed beyond useful. And, if you've managed to read this entire post, thanks for putting up with my ramblings ;).


1. Update: Added link to Jean-Paul Boodhoo's article.

kick it on DotNetKicks.com

 Tuesday, May 15, 2007

Speed Limits

Just a quick update today. I read in my ISP's newsletter about a new group promoting quality broadband in Australia, T4. It's good to see some big names behind the movement.

In Australia, I'm among the lucky minority with access to an ADSL2 Internet connection. While ADSL2 can potentially provide 24000Kbps downstream and 1000Kbps upstream, due to my line quality and the distance from the exchange I'm currently only getting 5568/864. However, I am paying $69.95 per month for the privilege and if I download more than 40gb my connection is slowed to 64Kbps for the remainder of the month. Compared to Scott Hanselman's guaranteed 15000Kbps/2000Kbps Internet connection for only US$50.00 per month my broadband is rather poor and from what I can gather Hanselman doesn't have a download limit.

Unfortunately, as I mentioned before, I'm among the lucky minority. Many users only have access to ADSL1 1500/256 connections and pay more than I do. Even more users, including some of my company's clients, can't get any better than dial-up or 64Kbps ISDN connections. These connections are unbearable to use VPNs or Remote Desktop to perform upgrades or maintenance.

Admittedly the sparse nature of the Australian population introduces some technical barriers and additional costs that Japan, the United States, and other better connected countries don't have to deal with, but groups like T4 and G9 have shown they are not insurmountable and will not cost as much as Telstra will have us believe.