Cory Foy

Friday, March 30, 2007

Unit Testing to move into Visual Studio Professional

Now this is cool news. It was announced a few days ago that Unit Testing and some other features are being moved out of the Developer and Tester Team System versions into the Professional version, meaning pretty much everyone will have access to it.

However, I disagree with Brad Wilson that unit testing should be in the .NET framework. I do think it should be in all versions of the IDE, including the free Express editions. And I also think that there should be a way to run unit tests on build machines without having to install Visual Studio. But moving it into the language - I think that's too low level.

Still, very cool news, and I look forward to seeing what else the team does in "Orcas"

Autogenerating Tests for Web Services using Visual Studio

I had a customer ask me recently for a way to auto-generate Unit Tests for Web Services based only on the WSDL using Visual Studio. Now, those of you who know me know I would call those "Integration Tests" (or perhaps "Deathly Slow Tests"), but a need is a need, and it's actually pretty straightforward.

First, you need Visual Studio Team Suite (or at least VS for Developers or Testers) for the following. If you don't have that, you can always download the 180-day trial.

What we are going to be taking advantage of is two things. First, when you add a reference to a web service (known as a "Web Reference"), a stub file is created that you would normally use to make the calls. Second, when a test project has a reference to another project, it adds an option to use a "Unit Test Wizard" which can autogenerate the test methods.

So, first, let's fire up Visual Studio. I'm going to be using one of the Team Foundation Server web references here, but any web service should work.

Start by creating a new Project, and mark it as a Class Library. I named mine "TFSWebServiceLibrary" like so:

Now, let's add our Web Reference. As I mentioned above, I'm going to be using a TFS Web Service, which can be found at http://yourtfsserver:8080/services/v1.0/ServerStatus.asmx. To add this as a web reference, right-click on the project and choose "Add Web Reference":

Enter the name of your web service and then click "Add Reference":

You'll now see a new Web Reference in your project, called whatever you named it in the above screen:

It doesn't look like much, but if you click the "Show All Files" icon near the top of your Solution Explorer, you'll see there is much more than meets the eye:

Aha! See Reference.cs? That's the stub file. If you take a glance at it, you'll see lots of auto-generated goodness that does the magic of calling the web service. But, more importantly, we now have a code file that accesses the web service that we can generate tests against.

Generating the tests is actually a smidgen easier. Right-Click on your Solution, and add a new Test Project. I called mine TFSWebServiceTester:

Now for the magic. right-click on the project, and add a reference to the project we created above. ("Add Reference" -> Projects Tab -> and then choose the project we created in step 1). Now, right-click on the Project and choose "Add->Unit Test...":

This will start the Unit Test wizard. Expand the nodes until you find the web service name you created when you added the web service:

If you expand that node, you'll see the various methods you can call on that web service. May as well uncheck the properties, since we don't care about testing those:

Now, Click Ok and watch the generation madness begin. When that finishes, you'll now have a unit test capable of calling the web services. You'll know the test because it will be shiny, new, and called WebServiceNameTest (for example, ServerStatusTest in our example). Now it's up to you to modify the tests for the proper input/output variables. For example, I modified the GetSupportedContractVersion test to look like:

If you are going to be doing testing of web services, you definitely want to become familiar with this article which discusses various gotchas and how to test the web services locally instead of having to test on a remote server (which would be closer to a "unit test" - though the spinning up of a local web server would only reduce it to a "somewhat bearable" test).

Tuesday, March 27, 2007

"No exact match found" when using People Picker in MOSS with Forms Authentication

This week I've been working with a customer to implement Forms Authentication for their MOSS site. Actually, it's mixed authentication since they'll have part via AD and part via a database. There are some great tutorials out there, but some people run into the problem I did - after modifying the web.config files, you have to add the user in the database to your SharePoint site. But when you enter the user into the People Picker, you get "No exact match found" and it won't let you continue.

What I found was that if I switched the Central Administration site to use the provider I set up, I got an "Unknown Error", which let me to think something bad was going on. Thinking through it more, I had in the back of my head that SharePoint would be accessing the database in the context of the current user, which is, of course, wrong. It access the database as the user you told SharePoint to use to access the database. So looking at that user, it didn't have access to my authentication database, and once I granted it access, everything worked like a charm!

Monday, March 26, 2007

Microsoft Visual Studio Team System Web Access

Brian Harry just announced that Microsoft has aquired the company that makes the Teamprise web access solution for Team Foundation Server and is immediately making it available for free for all licensed TFS users. This is great news since one of the big challenges with TFS deployments is people not wanting to install Visual Studio / Team Explorer to manage work items. Very cool!

Labels: ,

Friday, March 23, 2007

Team Foundation Branching Guidance now available on CodePlex

I'm catching up from my emails after being gone to an offsite event all week (what other company pays its employees to go to an offsite event and stay at the Bellagio in Vegas for a week?), and noticed that the Team Foundation Branching Guidance is now up and available on CodePlex. I saw a prerelease version, and it is a good document, though I still need to read all the way through it.

It's also nice to see stuff like this getting pushed out to CodePlex instead of to some MSDN site. It just gives it more of a community-owned feel.

Teamprise makes its TFS Eclipse plugin available for free!

When I was helping the NUnit team with Linux integration, Charlie tested moving the project to CodePlex. Which was all fine and dandy, except I couldn't access the source code repository from my Linux box to pull down or push up code.

Well, Linux developers needing to access CodePlex rejoice! Teamprise, who makes a handy-dandy plugin for Eclipse to access TFS, announced they are making the plugin available to open source developers.

To get it, you need to go to the Teamprise CodePlex site for the details. They also have a press release up about it.

I'm excited because I just emailed out a couple of days ago to the GM of Platform Strategy saying that I was glad the work Microsoft is doing to bring open source concepts in house, but that it was disappointing not being able to access CodePlex from anything but Windows machines without buying a license.

I still want to play around with getting the native Team Explorer client running in Mono, but that's for another day.

Monday, March 19, 2007

.NET Opening with Microsoft in Charlotte

Know .NET? Want to work for a company with incredible benefits and have an instant boost to your resume? We're looking for a .NET developer for a position based out of Charlotte, NC. If you are interested, please shoot me an email (foyc at cornet design dot com) and let's chat!

Sunday, March 18, 2007

Sweet Revenge against US Airways

Several months ago, US Airways had made a bid for Delta, whom I fly a lot. Now, everyone has their favorite airlines, but something about US Airways from flying them out of Charlotte and St Louis had never sat right with me. Their attitude might have been captured by their company spokesman a few days ago. In the midst of a major winter storm threatning the east coast, and most of the major airlines cancelling scores of flights ahead of the storm (including Jet Blue who seems to have learned their lesson), US Airways spokesman Andrew Christie declared:

The weather is fine for flying


Of course, not just a few hours later had the company cancelling flights due to a lack of deicing equipment. And then the headline on CNN this morning showed the absurity of that statement - 100,000 stuck travellers trying to fly:

Thousands of weary travelers faced a third day waiting to reach their destinations Sunday as US Airways struggled to recover from the ice and snow storm that paralyzed airports in the Northeast.

The airline was still trying to find seats for 100,000 passengers systemwide whose flights were grounded by Friday's storm, spokesman Andrew Christie said.


Fine for flying indeed. I'm so happy that the takeove..ahem...merger of US Airways and Delta didn't go through.

Thursday, March 15, 2007

C# Design Patterns

Do you know C#? Do you know Design Patterns? Do you know Design Patterns in C#? Well, heck, you just know everything, don't ya!

For quite a while, there has been a C# Design Patterns Group headed up by Damon Carr. It took a hiatus for a while, but is back in fashion. If you think you know your stuff, now is a great time to head over, because we are in the midst of a Decorator Pattern contest judged by Damon and yours truly.

Here's the scoop from my post to the list:

We are looking for the best implementation of the Decorator pattern. What is the decorator pattern? According to the Gang of Four:

"Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality".

To provide some framework to work in, this round is looking for decorator patterns that increment or decrement the price of a given object. For example, the base price of a car might be $5000 USD, and you can add on various aftermarket items like wheels, spoilers or really annoying tailpipes that increment the price. In addition, you might have incentives like a coupon, a discount plan or some other thing that decrements the price of the car.

Note that your implementation does not have to use the above example. You could use houses, boats, or green beans. The main rule is that none of the decorators can be mutually exclusive to cut down on the complexity.

Your application should:

- Allow for selection of a main item (at least one)
- Allow for selection of decorators (to either increase or decrease
the price) (at least 2)
- Calculate the total cost

We don't care if the app is a web app, Winforms, or Console. I care if you used Test-Driven Development, but pay no attention to that, because I'm just a judge, and it's not like I'll knock you points for not using TDD. Maybe.

Again, the deadline is March 31st. Prices and Participation may very. 2 week lease at 4% APR with automatic upgrade to Gold-infused Platinum edition at the end of term. Void where prohibited. Must take dealer stock by 3/31/07. Have a nice day if applicable in your jurisdiction.

Labels: , ,

Wednesday, March 14, 2007

It's times like these that make me love my job

I'm on the road a /lot/ - about every week or so, working onsite with our customers to either help them get new technologies implemented, or help them recover from some pretty interesting situations.

This past week I was onsite with a customer who has decided on Team Foundation Server as the corporate standard for Source Control. So I was onsite to help them setup policies, branching and merging strategies, etc.

While I was there, one of the leads came over with an interesting challenge. They are doing Ruby on Rails development on Linux, but they have to use TFS as the Source Control. Now, Microsoft has partnered with a company called Teamprise to provide a Java client for accessing TFS from non-MS platforms, but they were having a problem where the code generated by rails wasn't showing up in the Teamprise client as a pending checkin.

I collected some information, setup a repro here at the house, and got involved in a discussion with Martin Woodward. We ended up figuring out that they merely need to refresh the Eclipse project before they could see the checkins in the pending checkin window.

But this means that I got to help a team figure out how to workaround a problem preventing them from doing Ruby on Rails on Linux. Now, that was fun (even though I'm sure some sales people will panic if they ever read this).

MSBuild task to recursively delete all of a folder's contents

Following the Perl mantra of TMTOWTDI - we had a question come up about how to recursively delete a folder's contents - without deleting the folder itself - using MSBuild.

There are several solutions, but if you have a lot of crud to delete, one of the faster ways is to create a target which has the following calls:

<Exec Command="dir /ad /b c:\Temp > files.txt"/>
<Exec Command='for /f "Tokens=*" %%i in (files.txt) do rd /s/q "C:\Temp\%%i"'/>
<Delete Files="files.txt"/>

This spits out all of the subfolders to a temporary text file, then deletes them by looping over them and calling rd. The reason you have to do it this way is that if you just use the for loop without the Tokens=* line, it won't find directories with spaces in the name, as it, by default, only reads in the first space delimited token.

The reason it has to be to calls is that the "dir /ad /b c:\Temp" call has to be in single-quotes in the for command, but the Tokens=* has to be in double quotes. Since one of those is already taken because we are in an XML attribute, you need to break it into two seperate calls.

Another way would be to break the commands into two seperate properties, and then exec that:

<PropertyGroup>
  <dir_list>dir /ad /b c:\Temp</dir_list>
  <del_command>for /f "Tokens=*" %%i in ('$(dir_list)') do rd /s/q "C:\Temp\%%i"</del_command>
</PropertyGroup>

<Target Name="DeleteTemp">
     <Exec Command="$(del_command)"/>
</Target>

Friday, March 02, 2007

C# and Beginning Programmers / Ruby and Netbeans

Combination of two interesting articles this evening. The first is that there is a new Ruby IDE on the block - NetBeans! Offering Code Completion and Rails support, it should be pretty cool. Here's the full article.

Speaking of programming, Microsoft released a new dev center for - beginning developers! The Beginner Developer Learning Center on MSDN has links, articles and tutorials for that special script kiddie just getting started in the fundamentals of programming. Speaking of kiddies - they even have a special kid's section!

Cool stuff. Now go get your apps patched for Daylight Savings Time! ;)

Thursday, March 01, 2007

Very disheartening XP post

I was catching up on some of my mailing lists this evening when I came across the following post by the Agile Coach at my former employer:

 

One of our development groups, 4 XP teams, just ended a 3 month period of management imposed overtime. The result was lower velocity, more defects delivered to production, more time spent fixing production problems, more sick days.

MoreTime != MoreValue

While I couldn't agree with him more, it was disheartening because I know the people on those teams and is an amazing admission that when faced with a crisis the real belief in XP by management will come out.

First, anytime I see the words "mandatory mangement" anything is a big red flag that something is amiss. In an XP team you have to communicate with your teams to understand how to get past the problems and achieve the solution.

For example, there were times when something needed to get done, and we were on a deadline we wanted to meet, so we would work extra to get it done. Which is fine for two reasons:

  1. We, as a team, decided it
  2. It was for a short term, after which we went back to our normal schedules

But three months? There is nothing sustainable in that pace and either means that the teams have stopped communicating, management has stopped listening, or everyone has just given up.

What's disheartening is that, when I was there, I saw teams and individuals who really believed in XP. They saw the value, craved the communication and the openness, and were doing their best to make it work in spite of the limitations imposed on them from a top-down deployment of XP.

It's also disheartening because I fear developers are going to leave there thinking that's the way XP is, and have a bad taste in their mouth.

That coach must be a better man than I, because I certainly can't imagine staying on as a coach trying to help people through everything he has been through, including this. I only hope that things begin to turn around, that the devs understand they have the power to change things, and that management understands that now is the time to really listen to what the dev teams are saying and act on them.

Yes, you should care about Daylight Savings Time this year

Every year, we get treated to an extra (or lost) hour of sleep or work when Daylight Savings Time changes. This year, there may be many lost hours of sleep if you aren't watching your computer systems.

That's because this year DST starts three weeks earlier. Yep, Congress changed when it starts. The problem is that a lot of computer systems "understand" DST, but they understand it happening at a certain time, so they are going to be mighty confused when it happens on a different day.

For anyone running Microsoft software at home or at work, we have a web-based tool for figuring out what needs to be changed. This also applies if you are running any time of mobile phone which understands DST (definately Windows Mobile, and probably Blackberries too). Our tool is here and walks you through what you need.

If you are running Team Foundation Server, don't forget that it creates a SharePoint portal whenever you create a new Team Project, so be sure to patch it as well.