replacing Live Unit Testing script

This commit is contained in:
Srivatsa M S 2017-03-07 09:14:40 +05:30
Родитель ce28c46773
Коммит cb57e2a081
77 изменённых файлов: 193 добавлений и 214 удалений

Просмотреть файл

@ -56,10 +56,6 @@ entries:
url: labs/tfs/branchingandmerging
output: web, pdf
- title: Code Discovery using Live Dependency Validation in Visual Studio Enterprise 2017
url: labs/tfs/architecturevalidation
output: web, pdf
- title: Collaboration Experiences for Development Teams using Team Foundation Server 2017
url: labs/tfs/devteamcollaboration
output: web, pdf
@ -80,7 +76,7 @@ entries:
url: labs/tfs/intellitest
output: web, pdf
- title: Live Unit Testing in Visual Studio 2017
- title: Live Unit Testing and Live Dependency Validation in Visual Studio 2017
url: /labs/tfs/liveunittesting
output: web, pdf

Просмотреть файл

@ -8,7 +8,7 @@ comments: true
<br>
<br>
The ALM VM update is a massive exercise and takes several weeks from start and finish. I would like to thank the following indiviudals for their contributions and support, without their expertise and generous time, this could not have been a possibility
The ALM VM update is a massive exercise and takes several weeks from start and finish. I would like to thank the following individuals for their contributions and support, without their expertise and generous time, this could not have been a possibility.
<table class ="mainTable" width="100%" cellspacing="0" cellpadding="0" border="0">
<tr class ="mainTable" >

Двоичные данные
labs/tfs/architecturevalidation/images/01.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 36 KiB

Двоичные данные
labs/tfs/architecturevalidation/images/02.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 22 KiB

Двоичные данные
labs/tfs/architecturevalidation/images/03.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 112 KiB

Двоичные данные
labs/tfs/architecturevalidation/images/04.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 27 KiB

Двоичные данные
labs/tfs/architecturevalidation/images/1.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 7.8 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 44 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 35 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 59 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 46 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 27 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 28 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 60 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 63 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 90 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 109 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 33 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 20 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 18 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 26 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 55 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 391 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 41 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 13 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 16 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 18 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 128 KiB

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 86 KiB

Просмотреть файл

@ -1,117 +0,0 @@
---
title: Code Discovery using Live Dependency Validation in Visual Studio Enterprise 2017
layout: page
sidebar: tfs
permalink: /labs/tfs/architecturevalidation/
folder: /labs/tfs/architecturevalidation/
---
Lab version: 15.0.26020.0
Last updated: 2/19/2017
## Overview
Visual Studio enables teams to validate architectural dependencies in their solutions using the [Layer Designer](https://msdn.microsoft.com/en-us/library/dd465141.aspx).
It first shipped in Visual Studio 2010. The experience of the Layer Designer has been improved in Visual Studio 2017 with the introduction Dependency Validation experience to help ensure that developers respect the architectural constraints of the application as they edit their code.
In Visual Studio 2017 we have re-written the validation code to use **Roslyn analyzers**, which not only fixes many of these issues that were in the previous versions, but also gives us live validation in the IDE. As you type you get issues, and squiggles in the editor, and you can immediately stop introducing architectural flaws.
Weve also renamed layer diagrams to **dependency validation** diagrams to make it clearer what they are for.
## Related Resources
- Read this [Blog Post](https://blogs.msdn.microsoft.com/visualstudioalm/2016/11/30/live-dependency-validation-in-visual-studio-2017/) for a detailed discussion comparing the new experience with the past
## Pre-requisites
- Visual Studio 2017 (download [here](https://www.visualstudio.com/vs/visual-studio-2017-rc/))
- Download the Parts Unlimited project [here](https://github.com/Microsoft/PartsUnlimited/tree/aspnet45)
### Task 1: Real Time Dependency Validation in Visual Studio 2017
1. Download and extract the zip file
2. Open the solution in Visual Studio 2017
3. Right click on the **Parts Unlimited** solution and click **Restore Nuget Packages**. Make sure your project builds locally without any issues
<img src="images/01.png">
4. Now that we have a clean solution, I have opened the solution in my **Visual Studio 2017**. A Dependency Validation diagram was created by a code expert before he left for his retirement, and it describes the design principles he enforced, and want them to be enforced in future changes. I was asked to add a feature, and I understand what to do. I will edit some code to add a feature.
The below diagram indicates **Dependency Validation** for Parts Unlimited
<img src="images/02.png">
5. I'm trying to access **HomeController** under **Controllers**, from the **Category** class under **Models** by instantiating it in the constructor, but I am notified early with a clear message as to what I am trying to do is violating architectural constraints as shown below-
<img src="images/03.png">
This validation is well integrated in the **Error List**, which means I can use all the filters and sorting capabilities. This is implemented as a **static analyzer** and therefore I can change the severity of the error to a warning if I want to.
### Task 2: Creating Validation Diagrams in Visual Studio 2017
Now that we have seen what the developer experience is in the editor, let's see how to create a dependency diagram.
1. Load the Parts Unlimited solution
2. Go to **Architecture** tab in your Visual Studio and select **New Dependency Validation Diagram** as shown below. You should see a new project being added in your **Solution Explorer**
<img src="images/image13.png">
3. You will be prompted with a new window, give the name and select **ok**. You will be prompted with an **update** in your **Solution Explorer**. Update the project to enable **Live Dependency** by clicking on the **update** button
<img src="images/image14.png">
<img src="images/image15.png">
Your Project is amended to enable the **Live Validation**, in particular **Rosyln analyzer** is provisioned as a Nuget package.
4. Open the file **YOURFILENAME.layerdiagram** in your Visual Studio from the Solution Explorer as shown below
<img src="images/image16.png">
5. Let's add layers. A simple way to do this is by drag & drop from **Solution Explorer or Class View**.
Drag and drop the **controllers & models** from the solution explorer and add a **dependency** from the toolbox as shown below
<img src="images/image17.png">
6. Let's test now. Open the file **Category.cs** from **Models** and add the following code
**using PartsUnlimited.Controllers;**
**HomeController c;**
You can see that, I immediately get red squiggly and an error that clearly explains that this reference is not allowed.
<img src="images/image18.png">
7. Now try building the solution you will see that failure of dependency validation gets flagged as build errors.
<img src="images/image19.png">
8. You can convert these **errors** to **warnings** by updating the rule settings. Right click and select **Open Active Rule Set** from the **Analyzers node** under **PartsUnlimitedWebsite** as shown
<img src="images/image20.png">
9. You can now change the error level for all or select a set of dependency validation checks. Let's change the **Invalid Dependency** rule to **Warning** as shown below
<img src="images/image21.png">
10. Now rebuild the solution. You can see that the build succeeds with **warnings**
<img src="images/image22.png">
Once the code is committed to the source control repository, this will enable the whole team to benefit from the dependency validation **(including in Visual Studio Pro and Community where dependency diagrams cannot be created but can be viewed as read-only)**. The dependency validation will also happen during **Continuous Integration** builds and if you install the **[SonarQube](https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarqube)** plugin for Dependency Validation, you will even see the architectural flaws in SonarQube.

Двоичные данные
labs/tfs/liveunittesting/images/000.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 15 KiB

Двоичные данные
labs/tfs/liveunittesting/images/001.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 18 KiB

Двоичные данные
labs/tfs/liveunittesting/images/002.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 26 KiB

Двоичные данные
labs/tfs/liveunittesting/images/003.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 4.4 KiB

Двоичные данные
labs/tfs/liveunittesting/images/004.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 13 KiB

Двоичные данные
labs/tfs/liveunittesting/images/005.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 15 KiB

Двоичные данные
labs/tfs/liveunittesting/images/006.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 24 KiB

Двоичные данные
labs/tfs/liveunittesting/images/007.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 65 KiB

Двоичные данные
labs/tfs/liveunittesting/images/008.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 13 KiB

Двоичные данные
labs/tfs/liveunittesting/images/009.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 16 KiB

Двоичные данные
labs/tfs/liveunittesting/images/010.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 27 KiB

Двоичные данные
labs/tfs/liveunittesting/images/011.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 30 KiB

Двоичные данные
labs/tfs/liveunittesting/images/012.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 103 KiB

Двоичные данные
labs/tfs/liveunittesting/images/013.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 8.3 KiB

Двоичные данные
labs/tfs/liveunittesting/images/014.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 20 KiB

Двоичные данные
labs/tfs/liveunittesting/images/015.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 18 KiB

Двоичные данные
labs/tfs/liveunittesting/images/016.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 6.7 KiB

Двоичные данные
labs/tfs/liveunittesting/images/017.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 27 KiB

Двоичные данные
labs/tfs/liveunittesting/images/018.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 14 KiB

Двоичные данные
labs/tfs/liveunittesting/images/019.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 9.5 KiB

Двоичные данные
labs/tfs/liveunittesting/images/020.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 19 KiB

Двоичные данные
labs/tfs/liveunittesting/images/021.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 72 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image1.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 17 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image10.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 19 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image11.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 8.3 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image12.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 31 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image13.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 98 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image14.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 8.7 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image15.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 24 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image16.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 21 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image17.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 7.4 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image18.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 20 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image19.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 8.9 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image2.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 20 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image20.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 12 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image21.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 23 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image22.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 39 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image3.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 30 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image4.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 5.2 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image5.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 16 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image6.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 16 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image7.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 29 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image8.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 34 KiB

Двоичные данные
labs/tfs/liveunittesting/media/image9.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 15 KiB

Просмотреть файл

@ -1,154 +1,265 @@
---
title: Live Unit Testing and Live Dependency Validation in Visual Studio 2017
layout: page
layout: page
sidebar: tfs
permalink: /labs/tfs/liveunittesting/
folder: /labs/tfs/liveunittesting/
---
Lab version:15.0.26228.0
Lab version: 15.0.26228.0
Last updated:3/6/2017
Last updated: 3/6/2017
<a name="Overview"></a>
## Overview ##
## Overview
Live Unit Testing is a new feature introduced in Visual Studio 2017. It visualizes unit test results and code coverage live in the editor alongside your code and updates while you are coding. It works with C# and VB projects for the .NET framework and supports three test frameworks: MSTest, xUnit, and NUnit. Live Unit Testing makes it easy to maintain quality and test coverage during rapid development and takes your productivity to a whole new level. Imagine fixing a bug in a code base in which you may not be completely familiar with. With Live Unit Testing, you can know right away-as you are making edits to fix the bug-that you did not break another part of the system. Getting this feedback as you type will help you feel confident that your effort is delivering the results you expect.
Visual Studio also enables teams to validate architectural dependencies in their solutions using the [Layer Designer](https://msdn.microsoft.com/en-us/library/dd465141.aspx), which first shipped in Visual Studio 2010. This feature helps ensure that developers respect the architectural constraints of the application as they edit their code. It has been re-written in Visual Studio 2017 to use Roslyn analyzers for a more robust, reliable experience. Developers now get real-time design feedback in the editor so they can immediately stop introducing architectural flaws. "Layer" diagrams have also been renamed "dependency validation" diagrams to make it clearer what they are for.
Live Unit Testing is a new feature introduced in Visual Studio 2017. It
visualizes unit test results and code coverage live in the editor
alongside your code and updates while you are coding. It works with C\#
and VB projects for the .NET framework and supports three test
frameworks: MSTest, xUnit, and NUnit. Live Unit Testing makes it easy to
maintain quality and test coverage during rapid development and takes
your productivity to a whole new level. Imagine fixing a bug in a code
base in which you may not be completely familiar with. With Live Unit
Testing, you can know right away—as you are making edits to fix the
bug—that you did not break another part of the system. Getting this
feedback as you type will help you feel confident that your effort is
delivering the results you expect.
<a name="Related Resources"></a>
### Related Resources ###
Visual Studio also enables teams to validate architectural dependencies
in their solutions using the [Layer
Designer](https://msdn.microsoft.com/en-us/library/dd465141.aspx), which
first shipped in Visual Studio 2010. This feature helps ensure that
developers respect the architectural constraints of the application as
they edit their code. It has been re-written in Visual Studio 2017 to
use Roslyn analyzers for a more robust, reliable experience. Developers
now get real-time design feedback in the editor so they can immediately
stop introducing architectural flaws. “Layer” diagrams have also been
renamed “dependency validation” diagrams to make it clearer what they
are for.
See this [blog post](https://blogs.msdn.microsoft.com/visualstudio/2016/11/18/live-unit-testing-visual-studio-2017-rc/) for more information on live unit testing.
## Related Resources
See this [blog post](https://blogs.msdn.microsoft.com/visualstudioalm/2016/11/30/live-dependency-validation-in-visual-studio-2017/) for a detailed discussion comparing the new live dependency validation experience with the past.
See this [blog
post](https://blogs.msdn.microsoft.com/visualstudio/2016/11/18/live-unit-testing-visual-studio-2017-rc/)
for more information on live unit testing.
<a name="Prerequisites"></a>
### Prerequisites ###
See this [blog
post](https://blogs.msdn.microsoft.com/visualstudioalm/2016/11/30/live-dependency-validation-in-visual-studio-2017/)
for a detailed discussion comparing the new live dependency validation
experience with the past.
In order to complete this lab you will need the Visual Studio 2017 virtual machine provided by Microsoft. For more information on acquiring and using this virtual machine, please see [this blog post](http://aka.ms/almvm).
## Pre-requisites
<a name="Exercise1"></a>
## Exercise 1: Live Unit Testing in Visual Studio 2017 ##
In order to complete this lab you will need the Visual Studio 2017
virtual machine provided by Microsoft. For more information on acquiring
and using this virtual machine, please see [this blog
post](http://aka.ms/almvm).
Live Unit Testing is a service that watches your codebase for changes. As you edit files, it automatically detects which tests are impacted and runs those tests in the background. The results are provided immediately so that you can get feedback on how your changes affect the overall codebase quality. It also indicates which lines of code have no test coverage so that you can think about testability as you develop.
## Exercise 1: Live Unit Testing in Visual Studio 2017
<a name="Ex1Task1"></a>
### Task 1: Live unit testing ###
Live Unit Testing is a service that watches your codebase for changes.
As you edit files, it automatically detects which tests are impacted and
runs those tests in the background. The results are provided immediately
so that you can get feedback on how your changes affect the overall
codebase quality. It also indicates which lines of code have no test
coverage so that you can think about testability as you develop.
1. Log in as **Sachin Raj (VSALM\Sachin)**. All user passwords are **P2ssw0rd**.
### Task 1: Live unit testing
1. Launch **Visual Studio 2017** from the taskbar.
1. Log in as **Sachin Raj (VSALM\\Sachin)**. All user passwords are
**P2ssw0rd**.
1. Open the **PartsUnlimited** solution from the **Start Page**.
2. Launch **Visual Studio 2017** from the taskbar.
![](images/000.png)
3. Open the **PartsUnlimited** solution from the **Start Page**.
1. In **Solution Explorer**, search for **"string"** and double click **StringContainsProductSearch.cs** to open it.
<img src="media/image1.png" width="380" height="223" />
![](images/001.png)
4. In **Solution Explorer**, search for **“string”** and double click
**StringContainsProductSearch.cs** to open it.
1. This class already has some tests written and is currently in pretty good shape. However, suppose you were planning to make some changes and wanted to get an understanding of the quality of the code before you begin. Rather than running all tests, you can now simply enable live unit testing and let it illustrate the coverage.
<img src="media/image2.png" width="346" height="208" />
1. Select **Test | Live Unit Testing | Start** to start live unit testing. After a moment you will see glyphs appear in the left margin of the editor. There are three types of glyphs that indicate that all tests for a line pass (a green check), at least one test fails (a red X), or that the line is not tested (a blue line). In this case, you can see that the code in the constructor and beginning of **Search** pass their tests.
5. This class already has some tests written and is currently in pretty
good shape. However, suppose you were planning to make some changes
and wanted to get an understanding of the quality of the code before
you begin. Rather than running all tests, you can now simply enable
live unit testing and let it illustrate the coverage.
![](images/002.png)
6. Select **Test | Live Unit Testing | Start** to start live
unit testing. After a moment you will see glyphs appear in the left
margin of the editor. There are three types of glyphs that indicate
that all tests for a line pass (a green check), at least one test
fails (a red X), or that the line is not tested (a blue line). In
this case, you can see that the code in the constructor and
beginning of **Search** pass their tests.
1. Looking further down, it's clear that the exception case for this method is not tested, which is something you should think about adding later on.
<img src="media/image3.png" width="581" height="330" />
![](images/003.png)
7. Looking further down, its clear that the exception case for this
method is not tested, which is something you should think about
adding later on.
1. Now let's experiment with a change to the code. Delete the .**ToLower()** call in **Search**.
<img src="media/image4.png" width="336" height="77" />
![](images/004.png)
8. Now lets experiment with a change to the code. Delete the
.**ToLower()** call in **Search**.
1. The live unit testing service will immediately detect the change in code and re-run the tests (note the clock element is added to the glyphs). You don't even need to save the file.
<img src="media/image5.png" width="473" height="167" />
![](images/005.png)
9. The live unit testing service will immediately detect the change in
code and re-run the tests (note the clock element is added to
the glyphs). You dont even need to save the file.
1. Since the change above broke some tests, the glyphs are changed to reflect which lines of code are now part of failing tests. It's important to note that these glyphs don't indicate that the error occurred on their respective lines, but rather that those lines are executed by tests that ultimately fail.
<img src="media/image6.png" width="539" height="156" />
![](images/006.png)
10. Since the change above broke some tests, the glyphs are changed to
reflect which lines of code are now part of failing tests. Its
important to note that these glyphs dont indicate that the error
occurred on their respective lines, but rather that those lines are
executed by tests that ultimately fail.
1. Pres **Ctrl+Z** to undo the changes made earlier. You may need to press it multiple times to restore the **.ToLower()** from above. The glyphs should all return to passing.
<img src="media/image7.png" width="553" height="321" />
<a name="Exercise2"></a>
## Exercise 2: Real Time Dependency Validation in Visual Studio 2017 ##
11. Pres **Ctrl+Z** to undo the changes made earlier. You may need to
press it multiple times to restore the **.ToLower()** from above.
The glyphs should all return to passing.
<a name="Ex2Task1"></a>
### Task 1: Creating a dependency diagram ###
## Exercise 2: Real Time Dependency Validation in Visual Studio 2017
1. Press **Ctrl+Shift+B** to rebuild the solution.
### Task 1: Creating a dependency diagram
1. Select **Architecture | New Dependency Validation Diagram** from the main menu.
1. Press **Ctrl+Shift+B** to rebuild the solution.
1. Enter a **Name** of **"PartsUnlimited.Dependencies"** and click **OK**.
2. Select **Architecture \| New Dependency Validation Diagram** from the
main menu.
![](images/007.png)
3. Enter a **Name** of **“PartsUnlimited.Dependencies”** and click
**OK**.
1. If asked to update projects to support dependency validation, click **Update**.
<img src="media/image8.png" width="624" height="350" />
![](images/008.png)
4. If asked to update projects to support dependency validation, click
**Update**.
1. Note that the new project has been added to the solution. Double-click **DependencyValidation1.layerdiagram** to open it.
<img src="media/image9.png" width="349" height="136" />
![](images/009.png)
5. Note that the new project has been added to the solution.
Double-click **DependencyValidation1.layerdiagram** to open it.
1. There are a lot of ways to add layers to the diagram, including from the **Solution Explorer**, **Class View**, and **Object Browser**.
<img src="media/image10.png" width="347" height="205" />
![](images/010.png)
6. There are a lot of ways to add layers to the diagram, including from
the **Solution Explorer**, **Class View**, and **Object Browser**.
1. In this case, we're going to automatically generate a code map and then use that to codify our architecture via the diagram. Select **Architecture | Generate Code Map for Solution**. This code map will pull in everything it can about the project and represent it in a diagram so we can easily walk through the de facto dependencies and relationships each component (class, etc) has.
<img src="media/image11.png" width="624" height="55" />
1. Expand the **PartsUnlimited.dll** component to see the namespaces it contains.
7. In this case, were going to automatically generate a code map and
then use that to codify our architecture via the diagram. Select
**Architecture | Generate Code Map for Solution**. This code map
will pull in everything it can about the project and represent it in
a diagram so we can easily walk through the de facto dependencies
and relationships each component (class, etc) has.
![](images/011.png)
8. Expand the **PartsUnlimited.dll** component to see the namespaces
it contains.
1. It gets a little messy at this point because we have lots of relationships and dependencies mapped across and within the project and its tests. Use **Ctrl+Click** to select **PartsUnlimited.Controllers**, **PartsUnlimited.ViewModels**, and **PartsUnlimited.ProductSearch**. Press **Ctrl+C** to copy them.
<img src="media/image12.png" width="399" height="336" />
![](images/012.png)
9. It gets a little messy at this point because we have lots of
relationships and dependencies mapped across and within the project
and its tests. Use **Ctrl+Click** to select
**PartsUnlimited.Controllers**, **PartsUnlimited.ViewModels**, and
**PartsUnlimited.ProductSearch**. Press **Ctrl+C** to copy them.
1. Switch back to the layer diagram and press **Ctrl+V** to paste the three components from the last step. You may want to rearrange them as shown below to make their relationships easier to understand. Put simply, the controllers namespace depends on the product search and viewmodel namespaces. While these relationships existed before and may have been unofficial while the project was being developed, putting them into the layer diagram makes them official architectural law moving forward.
<img src="media/image13.png" width="624" height="236" />
![](images/013.png)
10. Switch back to the layer diagram and press **Ctrl+V** to paste the
three components from the last step. You may want to rearrange them
as shown below to make their relationships easier to understand. Put
simply, the controllers namespace depends on the product search and
viewmodel namespaces. While these relationships existed before and
may have been unofficial while the project was being developed,
putting them into the layer diagram makes them official
architectural law moving forward.
1. It's important to understand that the rules only exist for layers that exist on the diagram. For example, the **Controllers** namespace can reference the **ProductSearch** or **ViewModels** namespaces because their relationships are explicitly defined. At the same time, those two namespaces may not reference anything from the **Controllers** namespace because the dependency is directional (there are bidirectional dependencies available if two-way references are desired). **ProductSearch** and **ViewModels** may also not reference each other because they do not have an explicit dependency in the diagram. However, a namespace like **PartsUnlimited.Utils** is not used in the layer diagram and therefore is not enforced by the dependency validation engine. It may reference anything and anything may reference it. However, if it were added to the diagram, then all of its dependencies with every other layer in the diagram would be enforced.
<img src="media/image14.png" width="443" height="213" />
![](images/014.png)
11. Its important to understand that the rules only exist for layers
that exist on the diagram. For example, the **Controllers**
namespace can reference the **ProductSearch** or **ViewModels**
namespaces because their relationships are explicitly defined. At
the same time, those two namespaces may not reference anything from
the **Controllers** namespace because the dependency is directional
(there are bidirectional dependencies available if two-way
references are desired). **ProductSearch** and **ViewModels** may
also not reference each other because they do not have an explicit
dependency in the diagram. However, a namespace like
**PartsUnlimited.Utils** is not used in the layer diagram and
therefore is not enforced by the dependency validation engine. It
may reference anything and anything may reference it. However, if it
were added to the diagram, then all of its dependencies with every
other layer in the diagram would be enforced.
1. Press **Ctrl+S** to save the diagram.
12. In addition to the methods discussed earlier, you can also easily
add new layers and dependencies by right-clicking the diagram or
layers and selecting them. The layers can be at any level, whether
its a namespace, class, or even a
method.<img src="media/image15.png" width="563" height="170" />
<a name="Ex2Task2"></a>
### Task 2: Live dependency validation ###
13. Press **Ctrl+S** to save the diagram.
1. Now it's time to break some rules. Press **Ctrl+Shift+B** to rebuild the solution. It should build as expected because we haven't violated any policy...yet.
### Task 2: Live dependency validation
1. In **Solution Explorer**, search for **"string"** and open **StringContainsProductSearch**. This class is a member of the **PartsUnlimited.ProductSearch** namespace, and therefore is not allowed to reference anything from **PartsUnlimited.ViewModels**.
1. Now its time to break some rules. Press **Ctrl+Shift+B** to rebuild
the solution. It should build as expected because we havent
violated any policy…yet.
![](images/015.png)
2. In **Solution Explorer**, search for **“string”** and open
**StringContainsProductSearch**. This class is a member of the
**PartsUnlimited.ProductSearch** namespace, and therefore is not
allowed to reference anything from **PartsUnlimited.ViewModels**.
1. Locate the **Search** method. It currently returns a **Task<IEnumerable<Product>>**. Change it to return a **Task<IEnumerable<ViewModels.ProductViewModel>>**.
<img src="media/image16.png" width="346" height="217" />
![](images/016.png)
3. Locate the **Search** method. It currently returns a
**Task&lt;IEnumerable&lt;Product&gt;&gt;**. Change it to return a
**Task&lt;IEnumerable&lt;ViewModels.ProductViewModel&gt;&gt;**.
1. While this change introduces other errors as well, the key thing to focus on here is that the editor immediately provides a red squiggle indicating that this reference is not allowed based on its defined relationships. This live dependency validation provides immediate feedback to enforce architectural practices so that developers can feel confident that they're following the project rules.
<img src="media/image17.png" width="430" height="42" />
![](images/017.png)
4. While this change introduces other errors as well, the key thing to
focus on here is that the editor immediately provides a red squiggle
indicating that this reference is not allowed based on its
defined relationships. This live dependency validation provides
immediate feedback to enforce architectural practices so that
developers can feel confident that theyre following the
project rules.
1. And even if the developer were to ignore the red squiggle, they would still be unable to build the solution due to error-level enforcement of the policy.
<img src="media/image18.png" width="624" height="51" />
![](images/018.png)
5. And even if the developer were to ignore the red squiggle, they
would still be unable to build the solution due to error-level
enforcement of the policy.
1. However, you can customize exactly how dependency rule violations are treated. In **Solution Explorer**, clear the search box.
<img src="media/image19.png" width="624" height="28" />
![](images/019.png)
6. However, you can customize exactly how dependency rule violations
are treated. In **Solution Explorer**, clear the search box.
1. Under **References**, right-click **Analyzers** and select **Open Active Rule Set**.
<img src="media/image20.png" width="355" height="184" />
![](images/020.png)
7. Under **References**, right-click **Analyzers** and select **Open
Active Rule Set**.
1. Expand the **Microsoft.DependencyValidation.Analyzers** rule set and note how you could change the violation behavior from an **Error** to a **Warning** (or whatever you prefer). There is great flexibility in managing dependency validation.
<img src="media/image21.png" width="353" height="273" />
8. Expand the **Microsoft.DependencyValidation.Analyzers** rule set and
note how you could change the violation behavior from an **Error**
to a **Warning** (or whatever you prefer). There is great
flexibility in managing dependency validation.
<img src="media/image22.png" width="624" height="248" />
![](images/021.png)

Просмотреть файл

@ -57,7 +57,6 @@ Lab Name</b>
<tr><td><a href="agile/">Agile Planning and Portfolio Management with Team Foundation Server 2017</a></td></tr>
<tr><td><a href="branchingandmerging/">Branching and Merging Visualization with Visual Studio Team Foundation Server 2017</a></td></tr>
<tr><td><a href="storyboarding/">Building the Right Software - Generating Storyboards and Collecting Stakeholder Feedback with Visual Studio 2017</a></td></tr>
<tr><td><a href="architecturevalidation/">Code Discovery using Live Dependency Validation in Visual Studio Enterprise 2017</a> <span class="label label-success">New</span></td></tr>
<tr><td><a href="devteamcollaboration/">Collaboration Experiences for Development Teams using Team Foundation Server 2017</a></td></tr>
<tr><td><a href="devexp/">Developer experience enhancements in Visual Studio 2017</a> <span class="label label-success">New</span></td></tr>
<tr><td><a href="debugging/">Debugging with IntelliTrace using Visual Studio Enterprise 2017</a></td></tr>
@ -67,7 +66,7 @@ Lab Name</b>
<tr><td><a href="intellitest/">Generate Unit Tests with IntelliTest using Visual Studio Enterprise 2017</a></td></tr>
<tr><td><a href="smartword4tfs/">Introduction to the Modern Requirements Suite4TFS & Team Foundation Server 2017</a></td></tr>
<tr><td><a href="appinsights/">Instrumenting ASP.NET with Application Insights in Visual Studio 2017</a></td></tr>
<tr><td><a href="liveunittesting/">Live Unit Testing in Visual Studio 2017</a> <span class="label label-success">New</span></td></tr>
<tr><td><a href="liveunittesting/">Live Unit Testing and Live Dependency Validation in Visual Studio 2017</a> <span class="label label-success">New</span></td></tr>
<tr><td><a href="vsproductivity/">Making Developers More Productive with Visual Studio Team Foundation Server 2017</a></td></tr>
<tr><td><a href="technicaldebt/">Managing Technical Debt with Team Foundation Server 2017 and SonarQube</a></td></tr>
<tr><td><a href="packagemanagement/">Package Management in Team Foundation Server 2017</a> <span class="label label-success">New</span></td></tr>

Просмотреть файл

@ -14,7 +14,7 @@ Technical debt is the set of problems in a development effort that make forward
> SonarQube is an open source platform for understanding and managing technical debt, it provides different ways to analyze and measure technical quality from project portfolio to method.
### Prerequisites
## Pre-requisites
1- In order to complete this lab you will need the Visual Studio 2017 virtual machine provided by Microsoft. For more information on acquiring and using this virtual machine, please see [this blog post](http://aka.ms/ALMVM).
@ -24,16 +24,6 @@ Technical debt is the set of problems in a development effort that make forward
4- Complete
### Exercises
This hands-on lab includes the following exercises:
* Install and configure SonarQube Server and Extensions.
* Analyzing Projects with SonarQube Extension for VSTS/TFS.
Estimated time to complete this lab: **45 minutes**.
## Exercise 1: Install and Configure SonarQube Server and Extensions
In this exercise, you will learn about the main installation and configuration points required to install and configure SonarQube for demo purposes