Skip to content

Commit 2e5ba7d

Browse files
authored
Merge pull request #10499 from MicrosoftDocs/repo_sync_working_branch
Confirm merge from repo_sync_working_branch to main to sync with https://github.com/MicrosoftDocs/visualstudio-docs (branch main)
2 parents 8c87f01 + 6bba5da commit 2e5ba7d

16 files changed

+121
-104
lines changed

docs/code-quality/roslyn-analyzers-overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ms.workload:
2424

2525
Analyzers are divided into the following groups:
2626

27-
- [Code style](/dotnet/fundamentals/code-analysis/code-style-rule-options?preserve-view=true&view=vs-2019#convention-categories) analyzers are built into Visual Studio. The analyzer's diagnostic ID, or code format is IDExxxx, for example, IDE0067. You can configure preferences in the [text editor options page](../ide/code-styles-and-code-cleanup.md) or in an [EditorConfig file](/dotnet/fundamentals/code-analysis/code-style-rule-options). Starting in .NET 5.0, code style analyzers are included with the .NET SDK and can be strictly enforced as build warnings or errors. For more information, see [Overview of .NET source code analysis](/dotnet/fundamentals/productivity/code-analysis#code-style-analysis).
27+
- [Code style](/dotnet/fundamentals/code-analysis/code-style-rule-options?preserve-view=true&view=vs-2019#convention-categories) analyzers are built into Visual Studio. The analyzer's diagnostic ID, or code format is IDExxxx, for example, IDE0001. You can configure preferences in the [text editor options page](../ide/code-styles-and-code-cleanup.md) or in an [EditorConfig file](/dotnet/fundamentals/code-analysis/code-style-rule-options). Starting in .NET 5.0, code style analyzers are included with the .NET SDK and can be strictly enforced as build warnings or errors. For more information, see [Overview of .NET source code analysis](/dotnet/fundamentals/productivity/code-analysis#code-style-analysis).
2828

2929
- [Code quality](/dotnet/fundamentals/code-analysis/quality-rules/index) analyzers are now included with the .NET 5 SDK and enabled by default. The analyzer's diagnostic ID, or code format is CAxxxx, for example, CA1822. For more information, see [Overview of .NET code quality analysis](/dotnet/fundamentals/productivity/code-analysis#code-quality-analysis).
3030

@@ -103,4 +103,4 @@ You can't configure the severity of rules from analyzers that were installed as
103103

104104
- [Analyzers FAQ](analyzers-faq.yml)
105105
- [Write your own code analyzer](../extensibility/getting-started-with-roslyn-analyzers.md)
106-
- [.NET Compiler Platform SDK](/dotnet/csharp/roslyn-sdk/)
106+
- [.NET Compiler Platform SDK](/dotnet/csharp/roslyn-sdk/)

docs/extensibility/roslyn-version-support.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ As an example, to ensure that your custom analyzer works on all versions of Visu
2323

2424
| Roslyn package version | Minimum supported Visual Studio version |
2525
| - | - |
26-
| 4.3.0 | Visual Studio 2022 version 17.3 |
26+
| 4.3.1 | Visual Studio 2022 version 17.3 |
2727
| 4.2.0 | Visual Studio 2022 version 17.2 |
2828
| 4.1.0 | Visual Studio 2022 version 17.1 |
2929
| 4.0.1 | Visual Studio 2022 RTM |

docs/ide/file-nesting-solution-explorer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ ms.technology: vs-ide-general
1616

1717
[!INCLUDE [Visual Studio](~/includes/applies-to-version/vs-windows-only.md)]
1818

19-
**Solution Explorer** nests related files to help organize them and make them easier to locate. For example, if you add a Windows Forms form to a project, the code file for the form is nested below the form in **Solution Explorer**. In ASP.NET Core projects, file nesting can be taken a step further. You can choose between the file nesting presets **Off**, **Default**, and **Web**. You can also [customize how files are nested](#customize-file-nesting) or [create solution-specific and project-specific settings](#create-project-specific-settings).
19+
**Solution Explorer** nests related files to help organize them and make them easier to locate. For example, if you add a Windows Forms form to a project, the code file for the form is nested below the form in **Solution Explorer**. In .NET Core (and .NET 5 and later) projects, file nesting can be taken a step further. You can choose between the file nesting presets **Off**, **Default**, and **Web**. You can also [customize how files are nested](#customize-file-nesting) or [create solution-specific and project-specific settings](#create-project-specific-settings).
2020

2121
> [!NOTE]
22-
> Until Visual Studio 2022 version 17.3, this feature was only supported for ASP.NET Core projects.
22+
> In Visual Studio 2022 version 17.2 and earlier, this feature was only supported for ASP.NET Core projects.
2323
2424
## File nesting options
2525

docs/ide/reference/options-text-editor-javascript-linting.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Options, Text Editor, JavaScript, Linting
33
description: Learn how to use the Linting page of the Options dialog box to set options for analyzing code in the Code Editor.
44
ms.custom: SEO-VS-2020
5-
ms.date: 1/15/2019
5+
ms.date: 9/30/2022
66
ms.technology: vs-javascript
77
ms.topic: reference
88
f1_keywords:
@@ -20,7 +20,7 @@ ms.workload:
2020

2121
[!INCLUDE [Visual Studio](~/includes/applies-to-version/vs-windows-only.md)]
2222

23-
Use the **Linting** page of the **Options** dialog box to set options for analyzing code in the Code Editor. To access this page, on the menu bar, choose **Tools** > **Options**, and then expand **Text Editor** > **JavaScript/TypeScript** > **Linting**.
23+
Use the **Linting** page of the **Options** dialog box to set options for analyzing code in the Code Editor (note that you can override these options in some project types, like the [standalone React project templates](../../javascript/tutorial-create-react-app.md)). To access this page, on the menu bar, choose **Tools** > **Options**, and then expand **Text Editor** > **JavaScript/TypeScript** > **Linting**.
2424

2525
## ESLint Settings
2626

@@ -31,12 +31,9 @@ These options let you enable static JavaScript and TypeSCript code analysis, and
3131
|Option|Description|
3232
|------------|-----------------|
3333
|**Enable ESLint**|When this option is selected, the Code Editor allows for static analysis on the code.|
34-
|**Lint all files included in project, even closed files**|When this option is selected, closed files are analyzed, unless diagnostics are only reported for open files.|
35-
36-
## Global ESLint Config Options
37-
38-
This option lets you copy the location of the global ESLint configuration file. Also, if you previously changed the location, you can reset the file to its default location.
34+
|**Lint *file extension* files**|These options allow you to configure which file extensions should be linted. For example, if "Lint TypeScript files" is selected, then documents with a *.ts* file extension will be linted.|
3935

4036
## See also
4137

42-
- [General, Environment, Options Dialog Box](../../ide/reference/general-environment-options-dialog-box.md)
38+
- [Linting JavaScript in Visual Studio](../../javascript/linting-javascript.md)
39+
- [General, Environment, Options Dialog Box](../../ide/reference/general-environment-options-dialog-box.md)

docs/javascript/linting-javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ To enable linting support in Visual Studio 2022 or later versions, enable the **
2525

2626
:::image type="content" source="media/vs-2022/linting-tools-options.png" alt-text="Screenshot of linting Tools Options page.":::
2727

28-
In the options page, you can also modify the set of files that you want to lint. By default, all file extensions that can be linted (*.js*, *.jsx*, *.ts*, *.tsx*) will be linted.
28+
In the options page, you can also modify the set of files that you want to lint. By default, all file extensions that can be linted (*.js*, *.jsx*, *.ts*, *.tsx*, *.vue*, *.html*) will be linted. The HTML LSP-based editor must be enabled for linting Vue and HTML files. The respective setting can be found in **Tools > Options > Environment > Preview Features**.
2929

3030
You can override these options in some project types, like the [standalone React project templates](../javascript/tutorial-create-react-app.md). In these projects, you can override the settings from the **Tools > Options** page using project properties:
3131

Loading
Loading

docs/msbuild/msbuild-roslyncodetaskfactory.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ms.workload:
1616
---
1717
# MSBuild inline tasks with RoslynCodeTaskFactory
1818

19-
Similar to the [CodeTaskFactory](../msbuild/msbuild-inline-tasks.md), RoslynCodeTaskFactory uses the cross-platform Roslyn compilers to generate in-memory task assemblies for use as inline tasks. RoslynCodeTaskFactory tasks target .NET Standard and can work on .NET Framework and .NET Core runtimes as well as other platforms such as Linux and Mac OS.
19+
Similar to the [CodeTaskFactory](../msbuild/msbuild-inline-tasks.md), RoslynCodeTaskFactory uses the cross-platform Roslyn compilers to generate in-memory task assemblies for use as inline tasks. RoslynCodeTaskFactory tasks target .NET Standard and can work on .NET Framework and .NET Core runtimes as well as other platforms such as Linux and macOS.
2020

2121
>[!NOTE]
2222
>The RoslynCodeTaskFactory is available in MSBuild 15.8 and above only. MSBuild versions follow Visual Studio versions, so RoslynCodeTaskFactory is available in Visual Studio 2017 version 15.8 and higher.

docs/test/how-to-create-a-data-driven-unit-test.md

Lines changed: 96 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Create Data-Driven Unit Tests
33
description: Learn how to use the Microsoft unit test framework for managed code to set up a unit test method to retrieve values from a data source.
44
ms.custom: SEO-VS-2020
5-
ms.date: 05/08/2019
5+
ms.date: 10/17/2012
66
ms.topic: how-to
77
f1_keywords:
88
- vs.test.testresults.unittest.datadriven
@@ -22,17 +22,13 @@ author: mikejo5000
2222

2323
[!INCLUDE [Visual Studio](~/includes/applies-to-version/vs-windows-only.md)]
2424

25-
You can use the Microsoft unit test framework for managed code to set up a unit test method to retrieve values from a data source. The method is run successively for each row in the data source, which makes it easy to test a variety of input by using a single method.
25+
You can use the Microsoft unit test framework (MSTest) for managed code to set up a unit test method to retrieve values from a data source. The method is run successively for each row in the data source, which makes it easy to test a variety of input by using a single method.
2626

27-
Creating a data-driven unit test involves the following steps:
27+
A data-driven unit test can use any of the following kind:
2828

29-
1. Create a data source that contains the values that you use in the test method. The data source can be any type that is registered on the machine that runs the test.
30-
31-
2. Add a private <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext> field and a public `TestContext` property to the test class.
32-
33-
3. Create a unit test method and add a <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute> attribute to it.
34-
35-
4. Use the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.DataRow%2A> indexer property to retrieve the values that you use in a test.
29+
- inline data using the `DataRow` attribute
30+
- member data using the `DynamicData` attribute
31+
- from some well-known source provider using the `DataSource` attribute
3632

3733
## The method under test
3834

@@ -54,15 +50,94 @@ We'll test a method in `Maths` that adds two integers using a loop:
5450
public int AddIntegers(int first, int second)
5551
{
5652
int sum = first;
57-
for( int i = 0; i < second; i++)
53+
for (int i = 0; i < second; i++)
5854
{
5955
sum += 1;
6056
}
57+
6158
return sum;
6259
}
6360
```
6461

65-
## Create a data source
62+
## Test test method
63+
64+
### Inline data-driven test
65+
66+
For inline tests, MSTest uses `DataRow` to specify values used by the data-driven test. The test in this example runs successively for each data row.
67+
68+
```csharp
69+
[DataTestMethod]
70+
[DataRow(1, 1, 2)]
71+
[DataRow(2, 2, 4)]
72+
[DataRow(3, 3, 6)]
73+
[DataRow(0, 0, 1)] // The test run with this row fails
74+
public void AddIntegers_FromDataRowTest(int x, int y, int expected)
75+
{
76+
var target = new Maths();
77+
int actual = target.AddIntegers(x, y);
78+
Assert.AreEqual(expected, actual,
79+
"x:<{0}> y:<{1}>",
80+
new object[] {x, y});
81+
}
82+
```
83+
84+
### Member data-driven test
85+
86+
MSTest uses `DynamicData` attribute to specify the name, kind (property, the default, or method) and defining type (by default current type is used) of the member that will provide the data used by the data-driven test.
87+
88+
```csharp
89+
public static IEnumerable<object[]> AdditionData
90+
{
91+
get
92+
{
93+
return new[]
94+
{
95+
new object[] { 1, 1, 2 },
96+
new object[] { 2, 2, 4 },
97+
new object[] { 3, 3, 6 },
98+
new object[] { 0, 0, 1 }, // The test run with this row fails
99+
};
100+
}
101+
}
102+
103+
[TestMethod]
104+
[DynamicData(nameof(ReusableTestDataProperty))]
105+
public void AddIntegers_FromDynamicDataTest(int x, int y, int expected)
106+
{
107+
var target = new Maths();
108+
int actual = target.AddIntegers(x, y);
109+
Assert.AreEqual(expected, actual,
110+
"x:<{0}> y:<{1}>",
111+
new object[] {x, y});
112+
}
113+
```
114+
115+
It is also possible to override the default generated display name, using the `DynamicDataDisplayName` property of the `DynamicData` attribute. The display name method signature must be `publc static string` and accept two parameters, the first of type `MethodInfo` and the second of type `object[]`.
116+
117+
```csharp
118+
public static string GetCustomDynamicDataDisplayName(MethodInfo methodInfo, object[] data)
119+
{
120+
return string.Format("DynamicDataTestMethod {0} with {1} parameters", methodInfo.Name, data.Length);
121+
}
122+
123+
[DynamicData(nameof(AdditionData), DynamicDataDisplayName = nameof(GetCustomDynamicDataDisplayName))]
124+
```
125+
126+
### Source provider data-driven test
127+
128+
Creating a data source driven unit test involves the following steps:
129+
130+
1. Create a data source that contains the values that you use in the test method. The data source can be any type that is registered on the machine that runs the test.
131+
132+
2. Add a public `TestContext` property of type <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext> to the test class.
133+
134+
3. Create a unit test method
135+
136+
4. Add a <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute> attribute to it.
137+
138+
5. Use the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.DataRow%2A> indexer property to retrieve the values that you use in a test.
139+
140+
#### Create a data source
66141

67142
To test the `AddIntegers` method, create a data source that specifies a range of values for the parameters and the sum that you expect to be returned. In this example, we'll create a Sql Compact database named `MathsData` and a table named `AddIntegersData` that contains the following column names and values
68143

@@ -72,31 +147,26 @@ To test the `AddIntegers` method, create a data source that specifies a range of
72147
|1|1|2|
73148
|2|-3|-1|
74149

75-
## Add a TestContext to the test class
150+
#### Add a TestContext to the test class
76151

77152
The unit test framework creates a `TestContext` object to store the data source information for a data-driven test. The framework then sets this object as the value of the `TestContext` property that you create.
78153

79154
```csharp
80-
private TestContext testContextInstance;
81-
public TestContext TestContext
82-
{
83-
get { return testContextInstance; }
84-
set { testContextInstance = value; }
85-
}
155+
public TestContext TestContext { get; set; }
86156
```
87157

88158
In your test method, you access the data through the `DataRow` indexer property of the `TestContext`.
89159

90160
> [!NOTE]
91-
> .NET Core does not support the [DataSource](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute) attribute. If you try to access test data in this way in a .NET Core or UWP unit test project, you'll see an error similar to **"'TestContext' does not contain a definition for 'DataRow' and no accessible extension method 'DataRow' accepting a first argument of type 'TestContext' could be found (are you missing a using directive or an assembly reference?)"**.
161+
> .NET Core does not support the [DataSource](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute) attribute. If you try to access test data in this way in a .NET Core, UWP or WinUI unit test project, you will see an error similar to **"'TestContext' does not contain a definition for 'DataRow' and no accessible extension method 'DataRow' accepting a first argument of type 'TestContext' could be found (are you missing a using directive or an assembly reference?)"**.
92162
93-
## Write the test method
163+
#### Write the test method
94164

95165
The test method for `AddIntegers` is fairly simple. For each row in the data source, call `AddIntegers` with the **FirstNumber** and **SecondNumber** column values as parameters, and verify the return value against **Sum** column value:
96166

97167
```csharp
168+
[TestMethod]
98169
[DataSource(@"Provider=Microsoft.SqlServerCe.Client.4.0; Data Source=C:\Data\MathsData.sdf;", "Numbers")]
99-
[TestMethod()]
100170
public void AddIntegers_FromDataSourceTest()
101171
{
102172
var target = new Maths();
@@ -105,16 +175,14 @@ public void AddIntegers_FromDataSourceTest()
105175
int x = Convert.ToInt32(TestContext.DataRow["FirstNumber"]);
106176
int y = Convert.ToInt32(TestContext.DataRow["SecondNumber"]);
107177
int expected = Convert.ToInt32(TestContext.DataRow["Sum"]);
108-
int actual = target.IntegerMethod(x, y);
178+
int actual = target.AddIntegers(x, y);
109179
Assert.AreEqual(expected, actual,
110180
"x:<{0}> y:<{1}>",
111181
new object[] {x, y});
112182
}
113183
```
114184

115-
The `Assert` method includes a message that displays the `x` and `y` values of a failed iteration. By default, the asserted values - `expected` and `actual` - are already included in failed test details.
116-
117-
### Specify the DataSourceAttribute
185+
#### Specify the DataSourceAttribute
118186

119187
The `DataSource` attribute specifies the connection string for the data source and the name of the table that you use in the test method. The exact information in the connection string differs, depending on what kind of data source you are using. In this example, we used a SqlServerCe database.
120188

@@ -149,7 +217,7 @@ The connection strings depend on the type of the type of data source, but it sho
149217
)]
150218
```
151219

152-
### Use TestContext.DataRow to access the data
220+
#### Use TestContext.DataRow to access the data
153221

154222
To access the data in the `AddIntegersData` table, use the `TestContext.DataRow` indexer. `DataRow` is a <xref:System.Data.DataRow> object, so retrieve column values by index or column names. Because the values are returned as objects, convert them to the appropriate type:
155223

@@ -166,26 +234,10 @@ The test results bar at the top of **Test Explorer** is animated as your test ru
166234
> [!NOTE]
167235
> There's a result for each row of data and also one summary result. If the test passed on each row of data, the summary run shows as **Passed**. If the test failed on any data row, the summary run shows as **Failed**.
168236
169-
If you ran the `AddIntegers_FromDataSourceTest` method in our example, the results bar turns red and the test method is moved to the **Failed Tests**. A data-driven test fails if any of the iterated methods from the data source fails. When you choose a failed data-driven test in the **Test Explorer** window, the details pane displays the results of each iteration that is identified by the data row index. In our example, it appears that the `AddIntegers` algorithm does not handle negative values correctly.
237+
If you ran any of the `AddIntegers_FromDataRowTest`, `AddIntegers_FromDynamicDataTest` or `AddIntegers_FromDataSourceTest` method in our example, the results bar turns red and the test method is moved to the **Failed Tests**. A data-driven test fails if any of the iterated methods from the data source fails. When you choose a failed data-driven test in the **Test Explorer** window, the details pane displays the results of each iteration that is identified by the data row index. In our example, it appears that the `AddIntegers` algorithm does not handle negative values correctly.
170238

171239
When the method under test is corrected and the test rerun, the results bar turns green and the test method is moved to the **Passed Test** group.
172240

173-
## Run an inline data-driven test
174-
175-
For inline tests, MSTest uses `DataRow` to retrieve values from a data source. The test in this example runs successively for each data row.
176-
177-
```csharp
178-
[DataTestMethod]
179-
[DataRow(1, 1, 2)]
180-
[DataRow(2, 2, 4)]
181-
[DataRow(3, 3, 6)]
182-
[DataRow(0, 0, 1)] // The test run with this row fails
183-
public void AddTests(int x, int y, int expected)
184-
{
185-
Assert.AreEqual(expected, x + y);
186-
}
187-
```
188-
189241
## See also
190242

191243
- <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute?displayProperty=fullName>

0 commit comments

Comments
 (0)