Projects On Track

Document Sample
Projects On Track Powered By Docstoc
					Project on Track
Demo Script

The following demos are included in this script:

 Demo                                              Description

     1.   Architecture Explorer                    In this demo, we will see how complex solution
                                                   architectures can be easily understood using new visual

     2.   Architectural Validation                 In this demonstration, we see how to create layer
                                                   diagrams and use them to validate architectural

     3.   Code Analysis                            This demo focuses on learning how to run code analysis
                                                   tools for rules compliance and complexity.

     4.   Test Impact Analysis                     Here we will learn how code to determine which, if any,
                                                   tests are applicable to a given piece of code.

     5.   Branch Visualization                     In this demo, we will learn how to visualize branches in
                                                   Team Foundation Server 2010.
Setup and Configuration
In addition to running Windows 7, the following software packages must be installed in order to use these demo materials:

 Software                                                  Version and Location

     1.   Visual Studio 2010 Ultimate                      Download Release Candidate

The starter code and completed examples are in a folder named Code. The demos assume the directory to be the user's Visual Studio 2010 default project
location, typically %Documents%\Visual Studio 2010\Projects. The demos also all assume that TFS is installed on the system (or VM) and that you've
downloaded and unzipped the ExpenseSample application (found here). The sample should be located on your local hard drive and uploaded into TFS both as a
primary repository and a branch. Note you will have to "upgrade" the solution from Visual Studio 2008 SP1 to Visual Studio 2010, create and configure the
workflow persistence store database (per the readme file with the application solution), and create the application database (the script for which is included
with the application). Some guidance is provided here.

Demo 1 – Architecture Explorer
Estimated time to complete demo [15 minutes]
Intro: In this demonstration, see how the powerful new architectural features makes things easier to visualize complex projects.

 Action                                             Script                                               Screenshot
     1.   Open Internet Explorer and type in this
                                                       Let's begin our study of the Architecture
                                                        Explorer by loading an application with

                                                        many interesting architectural features.
                                                       This sample application was designed
                                                        specifically with architectural exploration
                                                        and layering in mind, and you can
                                                        download it from CodePlex. Note I'm using
                                                        this application as an example to
                                                        demonstrate architectural tools included
                                                        with Visual Studio 2010 Ultimate. Your own
                                                        applications may not exhibit this same
                                                        architecture, and that's okay. This is just an
                                                       So let's load this solution and see what it
                                                        looks like. As we progress through this
                                                        demonstration, imagine yourself a new
                                                        team member on the development team
                                                        assigned to this application. How would
                                                        you dig into the solution to begin
                                                        understanding how it's architected? Where
                                                        would you start if you were given a specific
                                                        area to modify. Would you know that the
                                                        code you've just added fits into the
                                                        architectural model as laid out by the
                                                        team's application architect?

2.   With Visual Studio started, open the         As you can see, I've stored the application's
     Expense Sample solution from TFS.             source code in Visual Studio Team
                                                                                                    ("project view" in Arch. Exp.)
                                                   Foundation Server 2010, so I'll open the
                                                   solution from there.
                                                  The application is broken into several
3.   Expand and contract various nodes in
                                                   namespaces. In fact, it produces several
     Solution Explorer to show the depth of
                                                   executable files and assemblies. So there is
     the solution (measure of complexity).
                                                   some complexity here, and if you're new to
                                                   the team, it would take some time to get
                                                   comfortable with the solution and how
                                                   things are laid out.
4.   Click View, then Architecture Explorer       However, instead of digging into the             ("create graph")
     from the main Visual Studio menu.             solution using Solution Explorer, which is
                                                   how we'd dive into this application before
                                                   Visual Studio 2010 Ultimate, let's try a
                                                   different, more graphical approach. With
                                                   Visual Studio 2010 Ultimate you have a
                                                   new tool, the Architecture Explorer. I'll
                                                   open that up now so we can see it.
5.   When Architecture Explorer appears,
     click Solution View.                         With Architecture Explorer, we have a            ("left to right")
6.   In the Solution View, select all of the       number of different ways we can view our
     sub-items in the window.                      solution. Let's start with the solution items.
7.   Click the Create Graph button. The            I'll select the projects in the solution and
     graph appears.                                click the "create graph" button. This
                                                   creates a nice graphical depiction of our
                                                   solution. Here you can see the constituent
                                                   projects in the solution in a nice, easy to
                                                   understand graphical format.
8.   Click the Left to Right toolbar button.      Here, the graph is laid out horizontally,
                                                   from top to bottom. If I prefer, I can
                                                   rearrange the graph to read left to right.

9.   Click "Business" in the solution item        If I select an individual project, I can also

    view and then Create Graph. A second           graph that. Here I'll select "business" and      ("contains" view in Arch. Exp.)
    graph appears.                                 create a second graph. With this project,
10. Select a zoom scale that makes the             there is too much information to show in a
    graph easier to visualize on your              single Visual Studio editor window well, so
    system (note toolbar zoom controls).           I'll simply zoom in to see the detail.
11. With the content zoomed, use the
                                                  Now we begin to see the architectural
    horizontal scrollbar to show graph.
                                                   features of this application. We see there
                                                   are business components, data
                                                   components, hosts, and so forth. And for
                                                   one of those components, business, we see
                                                   that it consists of workflows and activities,
                                                   entities, and custom business logic
                                                   components. While we could certainly have
                                                   figured this out by drilling into the
                                                   application in Solution Explorer, the
                                                   graphical presentation Architecture
                                                   Explorer provides is easier to visualize and
                                                   can be produced very quickly.
                                                                                                    ("class view" in Arch. Exp.)
12. Close all of the existing graphs (click       Visualizing our solution by project is useful,
    "no" to save for each).                        and in many cases it's all we may need to
13. In Architecture Explorer, click Class          get started. But there are other ways to
    View.                                          visualize the solution. For example, let's
14. Select all of the classes in the class         look at the classes that support this
    view.                                          application.
15. Click Create Graph.
16. Zoom to show content.                         Now, at a glance, we can see the classes
                                                   used to drive this application. In this case,    (selected types in "types view" in Arch. Exp.)
17. Click Quick Clusters. Then click Top to
    Bottom to turn off clustering                  the horizontal or vertical arrangement
    (visualization style toggles).                 might be better visualized with a clustered
                                                   view, so I'll click Quick Clusters to see what
                                                   that looks like.
18. Select                                        Something I like to do is then look at the
    ExpenseSample.Business.Entities from           types involved. For example, let's select
    the class list (second element in list).

19. Select all types from the Types list.        entities.                                         ("quick clusters" toolbar button)
20. Click Create Graph.
                                                Whatever the business logic entails, I
21. Zoom to show content.
                                                 usually like to start with the data elements.
                                                 Whatever work we're to do with the
                                                 application, at the end of the day it'll
                                                 involve manipulating data elements. In this
                                                 case I can quickly drill down into the data
                                                 entities and see we have things like
                                                 expense status and category. We'll have to
                                                 maintain an expense log, so I'm thinking
                                                 about log transactions. We have an
                                                 expense review, so I'm thinking about user
                                                 interface elements to support reporting
                                                 and decision-making.
                                                Could I figure all of this out by drilling into
                                                 the application in Solution Explorer? Sure I
                                                 could, but I'd also be relying on file names
                                                 to guide me, at least initially. I certainly
                                                 don't see how the classes are laid out as
                                                 quickly as I can with Architecture Explorer!

                                                So now let's switch gears a bit. So far what
                                                 we've seen is a static depiction of the
                                                 project layout. The graph tells us where
                                                 things are located, but we don't see what
                                                 depends on what. For that, we'll need
                                                 another tool--the dependency matrix.
                                                 Before this tool, it was more difficult to
                                                 figure out what depends on what.
22. Select all of the classes in the class      I'll first select all of the classes in our
    view.                                        solution and then generate the
23. Click the Dependency Matrix View             dependency matrix.
    toolbar button. The dependency

    matrix view appears. Zoom to better          That's a lot of information! I'll zoom in so
    show content.                                 we can get a better look. In fact, let's see
24. In the graph, from the horizontal             what dependencies main the application
    components select ExpenseSample.              assembly has. I'll scroll down and select
25. Scroll the horizontal scrollbar to the        that. Notice it changes color. The
    right, then the vertical scrollbar            dependencies will also change color so we
    upwards. Note the selected matrix             can better see them. I'll scroll over and
    columns.                                      then you see the classes the main
                                                  application assembly directly depends
                                                  upon. We can also tell if there are no
                                                  dependencies for a given class, which can
                                                  help us refactor code for simplification. In
                                                  this case, we don't see a lot of inter-
                                                  dependencies, so the code is probably
                                                  factored well. It'll certainly be easier to
                                                  maintain later on down the road.
26. Select
                                                 So let's say you're interested in getting into
                                                  the business components. I'll select this in
    in the class list, then
                                                  Architecture Explorer and graph it...
    ExpenseComponent in the type list.
    Click the Create Graph button.               The graph is pretty clean for this
27. Right-click the ExpenseComponent              application, but I'm sure you can imagine
    node and select View Content.                 other applications you've worked with
28. Scroll through the file a bit to show         where things weren't so clear-cut. Anyway,
    content.                                      in this case I can drill down into the code
                                                  very easily from here. I'll simply right-click
                                                  and select View Content. This brings the
                                                  code file up for editing.

29. In the upper right-hand corner of the        Just as with the application itself, it would
    editor, drop the method list and select       be nice to see a graphical depiction
    Approve. This takes the editor to the         representing what's going on within a given
    Approve method.                               method. Let's select a method, for
                                                  example, Approve. In the sample, the
                                                  method is pretty simple, but that's only

                                               because it hasn't been implemented. Even
                                               so, let's try something new. Let's generate
                                               a UML Sequence Diagram from the existing
                                               code and see what we can see.
                                              I'll right-click on the method name and ask
30. Right-click the Approve method text
                                               Visual Studio to create a new sequence
    and select Generate Sequence
                                               diagram. I can select some options, and
                                               once I do and click OK, Visual Studio
31. Uncheck System Namespace. Click OK.
                                               analyzes the code and creates the
    The diagram appears.
                                               sequence diagram.
                                              Now we can scroll through the sequence
                                               diagram and really see what is happening in
                                               this method. As you may already know, a
                                               sequence diagram helps us see how objects
                                               interact and what their life time is. In this
                                               specific, auto-generated case, we can see
                                               all of the internal calls that take place in
                                               our Approve method.
                                              Visual Studio 2010 uses standard UML
                                               notation in its sequence diagram, so
                                               everything you already know about UML
                                               will apply here. And while applying a
                                               sequence diagram to a single method may
                                               seem like overkill, it can help flush out
                                               some interesting behavior about that
32. Scroll down and right to locate the       One thing we notice about our sequence
    creation of the ExpenseLogDataAccess       right away is that we are making an             (Expense review data access component creation/use)
    component (see image).                     asynchronous call to create our expense
                                               data access object.
                                              This is asynchronous from a UML point of
                                               view – not a code point of view. That just

                                                means we are creating the expense review
                                                data access object, but we are not doing
                                                anything with it until we create the
                                                approval record.
                                               If I zoom out a bit, we can see we're also
33. Zoom out to show creation of expense
                                                creating an expense log record. So in the
    log entry.
                                                Approve method we're creating a review
                                                record and then adding that transaction to
                                                an expense log. Let's go back to the code
                                                for a moment...
                                               Looking at the code, there are only four
34. Click the ExpenseComponent.cs               innocent-looking lines of code, and one of
    (ExpenseComponent.vb in case of             them is simply a console write. So by
    VB.Net) tab in the editor to activate       looking at the sequence diagram, we can
    the code tab.                               very quickly see under the covers and
                                                appreciate that the Approve method is
                                                doing more than it would appear at first
                                                glance.                                      C#:


35. Click the sequence diagram tab to
                                                  This is just an example of the type of
    return to the sequence diagram.
                                                   analysis you can do with your code once
                                                   you have a sequence diagram – these kinds
                                                   of diagrams just make it easier to see
                                                   patterns that are otherwise not as obvious.
                                                  We may decide that this method deserves
36. Scroll left and up to the WriteLine            some further investigation. Visual Studio
    method.                                        2010 neatly integrates with the work item
37. Right-click the WriteLine method and           tracking provided by Team Foundation
    select Create Work Item and then               Server so we can easily create a work item
    Task.                                          for this specific part of our model.
38. When the task comes up, change the
    title to "Add diagnostics" and assign to      For example, at least the code wrote
    yourself (or some person in the                something to the console. But a better
    Assigned To droplist).                         approach is to remind ourselves to add true
                                                   diagnostics and tracing. So we could add

     39. Point out the Save Work Item button,            that task now while it's still fresh in our
         but just close the tab without saving.          mind. That's a whole lot better than adding
                                                         a "TODO" comment!

     40. Click the ExpenseComponent.cs
                                                        At the code-level, we can use the new Call
         (ExpenseComponent.vb in case of
                                                         Hierarchy feature to see what methods call
         VB.Net) tab to activate the code editor.
                                                         this Approve method and what methods it
     41. Right-click the Approve method and
                                                         is are calling.
         select View Call Hierarchy.
     42. Expand Calls To 'Approve' and Calls            This gives us a good idea about how risky
         From 'Approve'.                                 changes would be in this area and
                                                         potentially what other code we will affect
                                                         by making a change. Even though we are in
                                                         a very critical part of our source code, it's
                                                         good to know that only one method is
                                                         making a call to Approve right now.
                                                        We won’t make any changes to our method
                                                         in this demonstration, but knowing that
                                                         only one method is calling Approve at this
                                                         time might be motivation for us to make
                                                         any needed changes right now before our
                                                         call hierarchy gets more complicated.

Demo 2 – Architectural Validation
Estimated time to complete demo [20 minutes]
Intro: In this demonstration, see how to create layer diagrams and use them to validate architectural constraints.

Action                                              Script                                                  Screenshot
    1.   With Visual Studio open from the
                                                       Writing good high quality code is just part
         previous demonstration, right-click the
                                                        of the job of a developer.
         solution and select Add|New Project.
         (No need to re-open from TFS since it         What is just as important is that our good,
         should have been in a good state to            high-quality, well-tested code goes in the
         start here, but if you closed Visual           right place. That is, it fits in with the rest of
         Studio, re-open from TFS.)                     our high-level architecture.
                                                       Usually, it is very difficult for a developer to
                                                        see what the high-level architecture looks
                                                        like. There might be a drawing somewhere
                                                        or it might exist on someone’s whiteboard.
                                                        But generally speaking, it is really hard to
                                                        figure out if the code we wrote is in the
                                                        right place.
                                                       Visual Studio 2010 has a new feature in its
                                                        architectural tools that helps us visualize
                                                        and validate our architecture.
                                                       The layer diagram is part of these new
                                                        tools. A layer diagram enables an architect
                                                        to sketch out the general ‘layers’ where
                                                        code should live. This layer diagram defines
                                                        the relationships between our code – we
                                                        can literally drag and drop source files from
                                                        our Solution Explorer to create this layer
    2.   Select Modeling Projects from Installed       The layer diagram is something that models
         Templates, and then select Modeling            your application's architecture, so we'll first
         Project from the templates list (at            add a modeling project to our solution.
         present it's the only installed template
         for modeling).
    3.   Name the project

4.   Right-click Layer References and then
                                                      With that in place, we'll add references to
     Add Reference.
                                                       the projects we will include in our model. In
5.   Click the Projects tab and select all
                                                       this case, we'll select all of them but the
     ExpenseSample projects but UnitTests.
                                                       unit tests.
     Click OK to add the references.

6.   Next add a layer diagram by right-
     clicking the ExpenseSampleModels                 Now we'll add the layer diagram itself.
     project and selecting Add, New Item.
                                                      What we end up with is a designer surface
7.   From the Modeling templates, select
                                                       not unlike other designers. In this case we
     Layer Diagram. Name it
                                                       can drag items from the Toolbox,
     ExpenseSample.layerdiagram. Click OK
                                                       Architecture Explorer, and Solution
     to add the layer diagram.
                                                       Explorer onto the surface to create the
                                                       basic layers.

8.   Open the Toolbox and drag a layer
                                                      In this case, we'll start with the Toolbox. I'll
     onto the surface. Adjust the width to
                                                       open the Toolbox and drag a layer onto the
     nearly fill the designer surface. Adjust
                                                       designer's surface. I'll adjust its size a bit,
     the height such that three more
                                                       since we have room, and I'll rename it to be
     identically-sized layers will easily fit on
                                                       "presentation layer."
     the surface for viewing.
9.   In the Properties window, change the
     name to be Presentation Layer.

10. In the Properties window, change the              I'll change the color as well so that each
    color to Red.                                      layer stands out from the others. Here, I

11. From the Toolbox, drag three more             now have one of the application's layers. I'll
    layers onto the diagram. size each            add the remaining layers as well.
    similarly to the first. Name each
    Service Layer, Business Layer, and Data
    Layer respectively.
12. Color each a different color (orange,
    default, and green respectively, but
    choose any color you like).
                                                 Next I'll add dependencies between the
13. From the Toolbox, click Dependency.
                                                  layers. I'll go back to the Toolbox and select
    Then click the presentation layer
                                                  dependency. I'll then click presentation
    followed by the service layer. Add two
                                                  followed by service to add the necessary
    more dependencies to similarly
                                                  dependency. This unidirectional
    connect service, business, and data. It
                                                  dependency indicates that the presentation
    won't matter where in the layer you
                                                  layer depends upon the service layer.
    click...the designer will align the
14. Save the files.

                                                 The layers we see here are notional, kind of
                                                  like jotting ideas on a napkin. The
                                                  application's architect would create these
                                                  layers and then the developers would
                                                  implement them. However, since we have
                                                  an existing solution, let's add the
                                                  components to the layers in the
                                                  appropriate locations.
                                                 First, I'll open Architecture Explorer.
15. Click View, Architecture Explorer from
    the main menu to open Architecture

                                                 Next, I'll select the Solution View, and from
16. Select Solution View.

17. Select Data in the projects view.               the projects I'll select Data. In the
18. If the data layer isn't showing, scroll         "contains" view we now see the single
    the designer so that it is. With the data       namespace associated with the data access
    layer showing, drag and drop the                logic...I'll select this namespace and drag
    ExpenseSample.Data namespace from               and drop it onto the data layer.
    Architecture Explorer's Contains view
                                                   With that in place, we now see a small '1' in
    onto the Data Layer.
                                                    the upper right-hand corner. This tells us
                                                    that there are namespaces associated with
                                                    this layer as well as how many. One in this
                                                   I'll now do the same for the other
19. Select Business in the projects view.           namespaces. First business logic...then
20. Drag the five namespaces from                   services...and finally presentation, which in
    Contains and drop them onto the                 this case will consist of namespaces from
    Business Layer.                                 both Hosts and UI.
21. Select Services in the projects view.
22. Drag the two namespaces from
    Contains and drop them onto the
    Service Layer.
23. Select Hosts in the projects view.
24. Drag the three namespaces from
    Contains and drop them onto the
    Presentation Layer.
25. Select UI in the projects view.
26. Drag the three namespaces from
    Contains and drop them onto the
    Presentation Layer.
                                                   Since we have an existing solution, we can
27. Right-click the layer diagram and from
                                                    validate what's there against the
    the context menu select Validate
                                                    architectural diagram. Normally we'd start
                                                    with the architectural diagram and validate
                                                    code against that. But here, we can reverse
                                                    engineer the application using validation.

                                                 When we find validation errors, we'll
                                                 correct the layer diagram. This isn't to say
                                                 the architecture we're reverse engineering
                                                 is valid and correct. It merely shows us
                                                 where our layer diagram doesn't match the
                                                 code. If we later decide the final layer
                                                 diagram isn't appropriate, we can modify
                                                 the application accordingly and revalidate.
                                                Now Visual Studio is analyzing the solution.
28. Visual Studio will grind out the
                                                 It is loading each assembly and each
    validation. Continue speaking while it
                                                 namespace to determine what
    works. When completed you should
                                                 dependencies exist, and if there are any,
    see 100+ errors.
                                                 how those dependencies are interwoven.
                                                 You can see it executing as it spits out
                                                 messages to the output window.
                                                If we're lucky, or rather good, we'll find no
                                                 errors. But in this case we see a whopping
                                                 116 errors. Wow! Is this application so bad?
                                                Actually, no. All the errors indicate is the
29. Double-click the first error. Whatever       application's code doesn't match the layer
    file opens, merely point out the code        diagram we created. If we want, we can
    and then close the editor window.            click the error and be taken to the source
                                                 of the problem so corrective measures
                                                 might be taken.
                                                Since the layer diagram doesn't match the
                                                 code, we'll modify the layer diagram. Now,
                                                 unless you're reverse engineering an
                                                 application as I am here, this isn't
                                                 something you'd normally do. Normally
                                                 you'd lay out your architecture and validate
                                                 code against that. Errors then indicate the
                                                 code doesn't conform to the architecture.

                                                  So we have a choice. We can choose to
                                                   change the source code, or we can choose
                                                   to change the layer diagram. In this case,
                                                   we'll change the layer diagram since we're
                                                   reverse engineering the application.
                                                   Typically, however, we'd change the source
                                                  So let's see what's wrong here. The first
30. Return to the Errors window and point
                                                   error tells us that the presentation layer is
    out the first error (point out the text
                                                   using business layer components.
    that says "Layers: Presentation Layer,
    Business Layer")                              This means the presentation layer depends
31. Open the Toolbox and insert a                  on the business layer, so we'll need to add
    dependency between Presentation                a dependency between the two in the
    Layer and Business Layer. Note the             designer. I'll go back to the Toolbox and
    designer will snap the arrow to the            add a dependency, like so.
    center, covering the existing
    dependency arrows. You can move the
    arrow over by selecting the arrow head
    and moving to the left or right. Do the
    same for the tail.

32. Right-click the layer diagram and select
    Validate Architecture. It should              Now I'll revalidate.
    validate more quickly this time.              As before, Visual Studio is grinding through
                                                   the dependencies, looking for where the
                                                   existing dependencies don't match the
                                                   layer diagram.
                                                  Now, we still have errors, but far less than
                                                   before. Let's look at the first one again to
                                                   see what the problem might be.
33. Delete the dependency between the             This error says the business layer depends
    Service Layer and Business Layer.              on the service layer. When we created our
34. Open the Toolbox and add a                     layer diagram, we used a unidirectional

    bidirectional dependency between               dependency. However, this says we should
    Service Layer and Business Layer.              delete that and add instead a bidirectional
                                                   dependency. I'll delete the original
                                                   dependency and add a new one.
                                                  I also happen to know the dependency
35. Delete the dependency between Data
                                                   between the business layer and the data
    Layer and Business Layer.
                                                   layer should be bidirectional, so I'll change
36. Add a bidirectional dependency
                                                   that now as well. Once I re-validate, the
    between Data Layer and Business
                                                   code and layer diagram agree.
37. Right-click the layer diagram and select
    Validate Architecture. It should
    validate with no errors this time.

                                                  At this point we've reverse-engineered an
                                                   application's architecture and now validate
                                                   its code against that architectural diagram.
                                                   From now on, we can use the layer diagram
                                                   to validate new or modified code.
                                                  Imagine you're a new developer on the
                                                   team and you're asked to retrieve a bit of
                                                   data from the database to be presented in
                                                   the user interface. For this application, the
                                                   user interface displays approved expense
                                                   filings. But let's create some requirement
                                                   that could cause troubles.
                                                  For example, and we'll keep it simple, your
                                                   task is to retrieve the total number of

                                                       expense reviews.
                                                      Now, being experienced developers we
                                                       know there should be a service method of
                                                       some kind we can use, but for the sake of
                                                       example, I'm going to intentionally throw in
                                                       an error.
     38. Expand the UI project node in Solution       Here, I'll reference the data access layer
          Explorer.                                    directly. From the layer diagram you know
     39. Expand the WinFormClient node.                there is no direct dependency from the
     40. Right-click References under                  user interface to the database, but it's a
          WinFormClient and add a project              mistake I've seen in the past. It happens.
          reference to ExpenseSample.Data.
     41. Open the code file for ApproverForm.         So I'll go ahead and add a reference to the
Locate the form constructor and add this code          data access assembly. I'll also add a single
prior to the closing brace:                            line of code, just to actually make use of
                                                       the reference.
C#:                                                   When I simply compile the application, no
ExpenseSample.Data.ExpenseReviewDataA                  errors are returned. After all, I didn't break
ccess dal = new                                        any syntactical rules.

Dim dal As ExpenseSample.Data.                        However, let's return to the layer diagram
ExpenseReviewDataAccess = New Data.                    and revalidate the architecture.
ExpenseReviewDataAccess()                             Now, there are errors. The layer diagram
                                                       doesn't indicate any direct reference to the
    42. Compile the application and indicate           data access layer. As soon as I add code
        no errors in the error list.                   that references the data access layer from
                                                       the presentation layer, I've broken the
                                                       architectural model. I can now go in and fix
    43. Click the layer diagram tab to activate        the error.
        the layer diagram in the editor.
    44. Right-click the layer diagram and select      What's truly nice about this is you can add
        Validate Architecture.                         architectural validation as an automated

                                                         build step.

Demo 3 – Code Analysis
Estimated time to complete the demo: [15 minutes]
Intro: In this demo, you will learn how to run code analysis tools for rules compliance and complexity.

 Action                                              Script                                               Screenshot

     1.   Open Visual Studio 2010                       Any development team has a list of
                                                         standard best practices for writing code.
     2.   Open the ExpenseSample solution
                                                         These lists contain everything from how
          from TFS if not open from the previous
                                                         you should name your variables,
                                                         parameters, and methods, to common
                                                         mistakes to avoid.
                                                        The trouble is communicating this
                                                         information – especially to junior and new
                                                         developers. Too often this information is
                                                         buried in some design document. Even if
                                                         the developer read the guidance, the only
                                                         way to monitor compliance is to hold
                                                         frequent code reviews. Then you get
                                                         bogged down in discussing naming
                                                         conventions instead of looking at how the
                                                         code was implemented and whether or not
                                                         it fulfills its intended purpose. This is a
                                                         much better use of a code review.
                                                        However, Visual Studio 2010 continues to
                                                         build on a feature that has been part of
                                                         Visual Studio for a number of years called

                                                      Code Analysis.
                                                     Code Analysis is a feature that will examine
                                                      your code statically and evaluates it against
                                                      a set of known rules.
3.   With the application loaded, build all.         Microsoft has defined a number of these
     There should be no warnings or errors.           rules, but you can also define your own.
                                                     Let's try this feature out. I have our
                                                      expense sample ready to go in Visual
                                                      Studio. First, I'll simply compile it to show
4.   Right-click the                                  there are no errors or warnings.
     project and select Run Code Analysis.           Now, however, I'll select a project and run
                                                      code analysis against it. Since the
                                                      components project is first in the solution,
                                                      let's just use that. I'll right-click the project
                                                      to activate the popup menu. And here you
                                                      can see an option to run code analysis, so
                                                      I'll select that. The solution recompiles, but
                                                      this time I have a few warnings. Let's look
5.   Double-click the first error. It should be       at those.
     for re-throwing an exception.
                                                     By double-clicking on the warning, Visual
6.   Delete "ex" from the throw statement             Studio takes me to the code that failed
     (C#:                                             analysis and validation. Here, I see the code
     throw ex; becomes just throw;                    throws the exception object it was given.
     VB.Net:                                          This is considered a bad thing because the
                                                      exception object is reset and picks up state
     throw ex becomes just throw).
                                                      from where it's thrown. A better way to
                                                      handle this is to simply modify the line of
                                                      code, like so.
                                                     I'll again run the code analysis tool, and this
7.   Re-execute code analysis (step 4) and
                                                      time that warning should be eliminated.
     show that the fifth error was removed.
                                                     In a team setting, you would run code

                                               analysis often, perhaps even as often as
                                               each time the code was checked in. Visual
                                               Studio 2010 and Team Foundation Server
                                               2010 allow for this.
                                              What's more, you can choose which
                                               analysis rules to apply. You can apply one
8.   Right-click the                           of several sets of built-in rules, or you can
     ExpenseSample.Business.Components         create your own.
     project and select Properties.
                                              The rules are chosen from the project's
9.   Select the Code Analysis tab.             property page, like so.
10. Expand the Run This Rule Set list to      You may also enable code analysis on build.
    display the various list choices.          This isn't enabled by default, but if for your
11. Point to the Enable Code Analysis on       situation it makes sense, you have the
    Build check box.                           option.
                                              I mentioned Code Analysis can be applied
                                               at the team level – we can ensure that
12. Close the project Properties window.       every time someone checks in code, Code
13. Open Team Explorer.                        Analysis has been run. Let's see how that's
14. Right-click the ExpenseSample node
    and select Team Project Settings.         Since this is a team function, I'll open Team
                                               Explorer. And since this is affecting the
15. In the resulting sub-menu, select          expense sample application, I'll right-click
    Source Control. This brings up the         the expense sample node and select team
    source control settings dialog box.        project settings and then source control.
                                              Now that the settings dialog has appeared,
                                               I'll activate the check-in policy tab and then
                                               click Add.
16. Click the Check-in Policy tab.
                                              This activates the add check-in policy dialog
17. Click Add.                                 box, and here you can see I can select Code
18. Select Code Analysis and click OK.         Analysis. I'll select that and click OK.

                                               Again I can choose the rules to apply, but in
19. When the Code Analysis Policy Editor
                                                this case I'll simply cancel.
    appears, expand the Run This Rule Set
    list to show the options.                  If you have build definitions, you can also
                                                apply code analysis when the solution is
20. Click Cancel twice (to dismiss both
    dialogs).                                   built, just as you could with the individual
                                                project in its code analysis properties.

                                               Another code metric we often like to
                                                examine is code complexity. Visual Studio
                                                2010 allows you to analyze code and
                                                retrieve code complexity metrics..
21. Return to Solution Explorer.               As developers, it’s great to be able to get a
                                                tangible measurement of how manageable
                                                our code is.
                                               We do that by running the code metric
22. Right-click the                             analysis. Visual Studio will grind through
    ExpenseSample.Business.Components           the selected code using industry and
    project and select Calculate Code           academic standards to evaluate the
    Metrics.                                    complexity.
                                               If our code is excessively complex, it is likely
                                                to be more error-prone and harder to               VB.NET:
23. When the metrics calculation
    completes, point to the various            At a glance, we can get a reading about
    columns as discussed.                       how maintainable our code is – higher
                                                numbers are better.
                                               Cyclomatic complexity measures how deep
                                                loops and if statements are – lower
                                                numbers are better. We might want to re-
                                                factor our code if this number is too high.
                                               And depth of Inheritance helps us maintain

                                                          reasonable class hierarchies – object
                                                          orientation is a great concept, but we want
                                                          to make sure we don’t get too carried away
                                                          with it. Deeper inheritance hierarchies are
                                                          definitely harder to maintain. Changing a
                                                          single low-level base class can have
                                                          devastating effects on subclassed objects
                                                          higher in the inheritance tree.

Demo 4 – Test Impact Analysis
Estimated time to complete the demo: [15 minutes]
Intro: In this demo, you will learn how code to determine which, if any, tests are applicable to a given piece of code.

 Action                                              Script                                                Screenshot

     1.   Open Visual Studio 2010                        Now that we have written some code, a
                                                          natural question to ask is what tests should
     2.   Open the ExpenseSample solution
                                                          we run to verify this code?
          from TFS if not open from the previous
          demonstration.                                 Visual Studio 2010 has a new feature called
                                                          Test Impact analysis to help us answer that
                                                          very question.
     3.   If the Test Impact View window is not
          showing, activate it using Test,               The most obvious place way we can use
          Windows, Test Impact View.                      this feature is to see what tests we have for
                                                          the particular piece of code we are working
     4.   Expand the                                     If I open a source file, and for this I'll use
          ExpenseSample.Business.Components               the same Approve method we've been
          project and select                              using, I can quickly see if any tests cover

          (ExpenseComponents.vb in case of          the method in question. For Approve, I see
          VB.Net) for editing (double-click).       we do have tests.
    5.    Locate the Approve method.
    6.    Right-click the Approve method and
          select Show Calling Tests.
    7.    Point out the test indicated.
                                                   But let's select another method. Here I
    8.    Locate the Reject method (follows         have Reject, and I can immediately see that
          Approve)                                  I have no tests in this area at all. This is an
                                                    easy way to quickly verify that we need at
    9.    Right-click the Reject method and
                                                    least some unit tests in this area.
          select Show Calling Tests.
    10. Point out no test is indicated.            Visual Studio 2010 of course has carried
                                                    over the rich unit testing that was first
                                                    introduced in Visual Studio 2005. And we
                                                    know immediately that our next bit of work
                                                    will probably involve writing some unit

    11. Add the following line of code at the      But the true value with test impact analysis
        beginning of the Approve method:            is you can easily tell which tests need to be
C#:                                                 re-executed.
System.Diagnostics.Trace.WriteLine("A              For example, I'll modify the Approve
pproving...");                                      method to add some diagnostics. This
VB.Net:                                             shouldn't affect the outcome of a unit test,
                                                    but it's an easy code modification I can

                                                        make and one that substantially improves
 pproving...")                                          the quality of the code.
                                                       Now let's see if any of our tests are
                                                        affected. I'll right-click the Approve method
     12. Right-click the Approve method and             again and select Show Calling Tests. Now if
         select Show Calling Tests.                     we look at the Test Impact View, we see
     13. Point out the test requires a refresh.         that Visual Studio detected our code
                                                        changed and that some or all tests need to
     14. Click the Refresh link.                        be run again. In this case there is only one
     15. Point out one test is impacted.                test, but there might be several.

     16. Click the Run Tests link.                     I'll click the Refresh link, after which Visual
                                                        Studio will analyze the tests and come to
     17. Roll over the Test Results window to           the determination that one test requires
         show the test in progress and then             re-execution.
                                                       I can run the test or tests right from the
     18. Point out no tests are now impacted.           Test Impact View window, or run them
                                                        using another means.
                                                       Once I run the tests, however, Visual Studio
                                                        maintains that information and my Test
                                                        Impact View window will again be up to

Demo 5 – Branch Visualization
Estimated time to complete the demo: [15 minutes]
Intro: In this demo, you will learn how to visualize branches in Team Foundation Server 2010.

Action                                            Script                                               Screenshot

    1.   Open Visual Studio 2010                     At this point, we have written code that fits
                                                      correctly into our architecture. We've
    2.   Open the ExpenseSample solution
                                                      verified tests are available and have been
         from TFS if not open from the previous
                                                      run. And we've looked at the code
                                                      complexity metrics to make sure our code
                                                      is well-factored.
                                                     Now it's time to check our code into Team
                                                      Foundation Server.
                                                     This is where things can become really
                                                      difficult for a developer, particularly a
                                                      junior developer.
                                                     In any professional development
                                                      environment, there will likely be a
                                                      hierarchy of branches that make up the
                                                      source base.
                                                     At a minimum, there may be branches for
                                                      different releases, checkpoints, and hot
                                                     Ensuring that our code goes into the right
                                                      place is not trivial and can be very error
                                                     Visual Studio 2010 of course has some new
                                                      features to help us out.
                                                     To get started, let’s check in our code.
    3.   Right-click the ExpenseSample solution
         node in Solution Explorer and select        Our code gets checked in as a change set –
         Check In.                                    which is sort of a package of all the files we
                                                      have been modifying.

                                                  What we can do now is make sure that our
4.   Open Source Control Explorer.
                                                   change set went into the right place. I'll
5.   Right-click the ExpenseSample node            quickly show the history for the project.
     and select View History.
                                                  We can use Visual Studio 2010 to visualize
                                                   our entire branch hierarchy.
                                                  As with everything we have seen so far, our
                                                   job as a developer is easier if we can see
                                                   what we are doing.
                                                  If we can see what tests address our code,
                                                   we can easily decide if we need more tests
                                                   or if the tests require re-execution.
                                                  If we can see our overall architecture, we
                                                   can easily make sure the code we're writing
                                                   fits into that architecture.
                                                  And, if we can see our branch hierarchy, we
                                                   can easily make sure our change went into
                                                   the right place.
6.   Select a change set from the historical
     list.                                        We can choose any change set and track it
                                                   throughout our branch hierarchy.
7.   Right-click that change set and select
     Track Changeset.                             First, we will pick a change set that was
                                                   checked in. I'll right-click an older change
8.   When the Tracking Changeset XYZ tab
                                                   set and choose Track Changeset.
     appears, expand the ExpenseSample
     node.                                        Here, I can select the branches I want to
                                                   visualize, so I'll expand the main branch's
9.   Check ExpenseSampleBranch (or the
                                                   node and check the branches I want, which
     name of the branch you created).
                                                   is one in this case.
10. Click Visualize.
                                                  Then I'll click Visualize.
                                                  This opens another view. I see both
                                                   branches are green, which means this

                                                 change set exists in both branches.

                                                I'll next look at a timeline view by clicking
11. Click Timeline Tracking.
                                                 Timeline Tracking. This shows change sets
                                                 being merged over time.
12. Close the change set tracking tab as        Now let's go and make a change to our
    well as the history tab.                     source code and check that in. This creates
13. Return to the ExpenseComponent.cs            another change set, but it'll only be
    (ExpenseComponent.vb in case of              checked into the main branch. Let's see
    VB.Net) file and locate the Approve          how we propagate it throughout the other
    method.                                      branches.

14. Add a comment to the method (it
    doesn't matter what the comment is,
    only that the file changed).
15. Right-click the ExpenseSample node in
    Solution Explorer and select Check In.      Now let's revisit our mainline's history.

16. Return to Source Control Explorer.          Here we see the latest change set, so I'll
                                                 again click Track Changeset and visualize
17. Right-click the ExpenseSample node           the branches.
    and select View History.
                                                The gray-blue color clearly tells us this
18. Right-click the latest change set and        change set has not made its way to the
    select Track Changeset.                      other branch.
19. When the Tracking Changeset XYZ tab         That may be what we want – this change

    appears, expand the ExpenseSample             set might represent a hot fix that we only
    node.                                         want to exist in one branch.
20. Check ExpenseSampleBranch (or the            But, suppose that this is not the case.
    name of the branch you created).              Suppose that we want to propagate this
                                                  change set to the other branch.
21. Click Visualize.
22. Click Timeline Tracking.                     We can do this by simply dragging and
                                                  dropping. We'll drag the change set from
                                                  the mainline branch to the forked branch
23. Drag the change set (the outlined             and drop it. This brings up the Merge
    rectangle) to the other branch and            Wizard.
    drop.                                        Here we can choose to merge all changes
                                                  up to a specific version, or we can simply
                                                  merge selected change sets. I'll go with the
24. Click Next and then Finish.                   default to bring the other branch entirely
                                                  up to speed.
                                                 Once we commit the merge operation, our
                                                  change set will become part of the other
25. Return to Source Control Explorer.
26. Right-click the branch and select Check
    In Pending Changes.
                                                 When we re-run our visualization, we can
                                                  clearly see how our change set was merged
27. Right-click the ExpenseSample node            from the original branch to the new one
    and select View History.                      that we selected.

28. Right-click the latest change set and        This visualization helps us clearly see
    select Track Changeset.                       exactly where our changes are going and
                                                  gives us control over which branches are
29. When the Tracking Changeset XYZ tab           provided which merged change sets.
    appears, expand the ExpenseSample

30. Check ExpenseSampleBranch (or the
    name of the branch you created).
31. Click Visualize.
32. Click Timeline Tracking.


Shared By: