In this exercise, you will learn about the new suspend and resume functionality for work items and the new integrated code reviews.
- Another common but unavoidable difficulty faced by developers is context switching between different tasks. In past versions of Team Foundation Server, this was addressed with Shelvesets that would preserve your changes on the server even if you weren’t ready to check those into source control. In Team Foundation Server 2011, this has been taken one step further with the Suspend and Resume feature – in addition to creating a shelveset of changes, some other data like breakpoints and tool window positions are also saved locally.
We begin this exercise in the state that we ended the previous exercise in - we have a set of pending changes to be made as part of the work that we have in progress. Load the My Work window in Team Explorer to view the work that is in progress.
Figure 45
My Work showing tasks in all states
As part of this scenario, imagine that we also have some other debugging tool windows open and a break point set as we debug code that we are writing. Open HomeController.cs from FabrikamFiber.Web | Controllers and add a breakpoint to the first line in the HomeController constructor as shown in Figure 1 below:
Figure 46
Setting a breakpoint
- Open the Immediate window from Debug | Windows | Immediate.
- Now imagine that your boss asks you to stop working on the current task, and work on a high-priority bug instead. We currently have a lot of time invested in getting Visual Studio debugging tools in place, and we would like to be able to return to this current context after the bug fix is complete.
- Press Ctrl+Shift+S to save all open files.
In Team Explorer, navigate to the My Work screen, select the Suspend & Shelve link, and then select the Suspend button. We could modify the description, but since we are currently working on a work item, it is pre-populated for us.
Figure 47
Suspending work
Clear out all breakpoints by pressing Ctrl+Shift+F9, and then select the Yes button to confirm the action.
Figure 48
Deleting all breakpoints
- Close all document windows by selecting Window | Close All Documents from the main menu.
Reset to the default window layout by selecting Window | Reset Window Layout from the main menu.
Figure 49
Restoring default window layout
At this point, you should have a very clean looking workspace and the previous task that you were working on should be listed in the Suspended & Shelved Work section of the My Work window.
Figure 50
Suspended section of My Work
Note the search box for work items at the top of the Team Explorer window. This will perform a search of all work items in the currently selected team project. Type “Canadian” into the search box and press the Enter key to locate the high-priority bug that you have been asked to work on.
Figure 51
Searching for work items
This quick search functionality searches the team project Title, Description, and Repro Steps fields by default for the keyword provided. You can also click the drop-down arrow to show your search history, and to add search parameters for metadata such as work item type, or whom the work item is assigned to.
Double-click on the bug with titled “Customers with Canadian addresses not displaying properly”.
Figure 52
Location of high-priority bug that needs fixed
In the window displaying the form for the bug, select the Tasks link to view the linked work items. Note that there are two child tasks.
Figure 53
Viewing existing child tasks
Imagine that other team members are tackling these child tasks already, but that we know of another problem related to the parent bug that also needs to be fixed. Select the New button in the Tasks section of the form to create a new child task.
Figure 54
Creating a new child task
For the new linked work item, select Link Type of Child, Work Item Type of Task, enter a Title of “Fix RegEx for Zip code property”, and then select the OK button.
Figure 55
Creating a new child task
Assign the new task to Julia and then select the Save Work Item button.
Figure 56
Assigning work item to Julia
Return to the Team Explorer – My Work window. You should now see the new task appear in the Available Work Items section.
Figure 57
Location of the new task in My Work
Right-click on the new task entitled “Fix RegEx for Zip code property”, and then select the Add to In Progress option from the context menu.
Figure 58
Moving new task to In Progress state
In Solution Explorer, open the Address.cs file from the Models folder of the FabrikamFiber.DAL project. The Address.Zip property is currently using an incorrect regular expression data annotation, with the result being that users of the web application can enter invalid postal codes for Canadian addresses.
Figure 59
Source code with bug
Let’s assume that the correct fix is to update the regular expression. Comment out the existing regular expression and then un-comment the other one.
Figure 60
Source code with bug fixed
- Press Ctrl+S to save the changes to the file.
Now that the fix has been made, let’s ask Cameron to perform a code review on the changes to make sure things look correct. In Team Explorer - My Work, select the Request Review link.
Figure 61
Location of Request Review link
Type Cameron Skinner for the name of the reviewer and then press the Enter key, type a desription of “please check my regular expression change”, and then select the Submit Request button.
Figure 62
Entering details for code review request
- Log in as Cameron to perform the code review. Click Start -> Switch User. The password for all users in this virtual machine is P2ssw0rd.
Load Visual Studio 11, open Team Explorer, and navigate to My Work. The new code review request is shown under the Code Reviews & Requests section at the bottom.
Figure 63
Code Reviews & Requests section of My Work
Double-click the code review request to open the Code Review window. This view allows Cameron to see a lot of information regarding the request so that he is able to determine whether he will accept or decline the task. He can view the entire shelveset of changes, see the other reviewers or even add someone to the reviewers list, see the related work items, comments related to the code review request, and finally the ability to show a diff view for all of the changed files with a single click.
Figure 64
Code Review window
In the Code Review window, select the Accept button to start working on the code review.
Figure 65
Location of Accept button
Select the Address.cs file from the comments section to open it with the new inline diff tool.
Figure 66
Location of file with bug fix
By default, we are now viewing the changes using a side-by-side comparison mode. Red background colors represent changes in the old version (left) and green colors represent changes in the new version (right). Note the legend available at the bottom of the comparison view.
Figure 67
Inline diff tool showing difference between old and new version of code
The new diff viewer in Visual Studio 11 has been fully integrated into the editor. It is also used as part of the merging process, which you will see later.
In the Compare Files toolbar, select the compare mode drop down button to view the various display modes that the diff viewer can use. Try out a few of the different modes.
If the Compare Files toolbar is not open, open it from View | Toolbars | Compare Files from the main menu in Visual Studio.
Figure 68
Location of button to choose compare mode
Let’s assume that we agree that the changes are correct, so go ahead and add a review-level comment to that effect. Select the Reply link underneath Julia’s message.
Figure 69
Location of Reply link to reply to comment
For the comment, enter “that looks good” and then select the Save button.
Figure 70
Entering a response to a comment
Note that the new comment has the text “Unsent” next to it. The comment will not be sent until Cameron is done with the review.
Figure 71
Comment is not sent automatically
You can also annotate individual files and blocks of code with comments. In the diff viewer, use the mouse to highlight the Zip property name, right-click, and select Add Comment from the context menu.
Figure 72
Adding a comment to code
In the comment box, enter “Consider renaming PostalCode” and then select the Save link.
Figure 73
Annotating code with a comment
Select the Send Comments hyperlink near the top of the Code Review window to send the comments that we have batched up so far. Having the ability to send comments back right away can be beneficial for a code review that requires more work than this one. If the reviewer finds an issue with a change, the developer can immediately start fixing the issue rather than waiting for the reviewer to finish.
Figure 74
Send Comments link
Select the Send &Finish drop down followed by the Looks Good option to end the code review.
Figure 75
Ending a code review
In the Code Reviews & Requests section of My Work, select the Incoming & Outgoing drop down followed by the Recently Finished option to see the code review that Cameron just finished.
Figure 76
Viewing recently finished code reviews
Figure 77
Recently finished code review is sent back to requestor
- Switch users and log in as Julia once again.
Return to Team Explorer – My Work and double-click on the code review item to open it.
Figure 78
Code review has been completed
In Team Explorer – Code Review, note that Cameron finished his review and had comments.
Figure 79
Code Review window showing updates after code review
For this scenario, let’s say that we are done with the code review process. Select the Close Review link and choose the Complete option.
Figure 80
Closing the review as being completed
Now that we are confident that we have fixed the high priority bug, we can check-in the changes. Select the Check In link to load the Pending Changes window and then finally select the Check In button to complete the task.
Figure 81
Check in changes
Figure 82
Check in changes
Now we can return to the code that we were originally working on before we were interrupted by the bug fix. In the My Work window, right-click on the task listed under the Suspended & Shelved Work section, and then select the Resume option from the context menu.
Figure 83
Resuming suspended work
After the shelveset is opened and the task context is restored, you will notice that the document windows and tools windows, as well as their positions, are restored to the state that we left them in when we suspended this task. Although you won’t notice this in a virtual machine, had you been using multiple monitors with Visual Studio 11 you would have also noticed that all of the tool windows would be opened on their respective monitors as well. This capability allows you to quickly get in and out of tasks to help you deal with the frequent interruptions that many of us face on a daily basis.
Figure 84
Restored development environment