You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/code-quality/roslyn-analyzers-overview.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ ms.workload:
24
24
25
25
Analyzers are divided into the following groups:
26
26
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).
28
28
29
29
-[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).
30
30
@@ -103,4 +103,4 @@ You can't configure the severity of rules from analyzers that were installed as
103
103
104
104
-[Analyzers FAQ](analyzers-faq.yml)
105
105
-[Write your own code analyzer](../extensibility/getting-started-with-roslyn-analyzers.md)
**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).
20
20
21
21
> [!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.
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**.
24
24
25
25
## ESLint Settings
26
26
@@ -31,12 +31,9 @@ These options let you enable static JavaScript and TypeSCript code analysis, and
31
31
|Option|Description|
32
32
|------------|-----------------|
33
33
|**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.|
Copy file name to clipboardExpand all lines: docs/javascript/linting-javascript.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ To enable linting support in Visual Studio 2022 or later versions, enable the **
25
25
26
26
:::image type="content" source="media/vs-2022/linting-tools-options.png" alt-text="Screenshot of linting Tools Options page.":::
27
27
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**.
29
29
30
30
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:
Copy file name to clipboardExpand all lines: docs/msbuild/msbuild-roslyncodetaskfactory.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ ms.workload:
16
16
---
17
17
# MSBuild inline tasks with RoslynCodeTaskFactory
18
18
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.
20
20
21
21
>[!NOTE]
22
22
>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.
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.
26
26
27
-
Creating a data-driven unit test involves the following steps:
27
+
A data-driven unit test can use any of the following kind:
28
28
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
36
32
37
33
## The method under test
38
34
@@ -54,15 +50,94 @@ We'll test a method in `Maths` that adds two integers using a loop:
54
50
publicintAddIntegers(intfirst, intsecond)
55
51
{
56
52
intsum=first;
57
-
for( inti=0; i<second; i++)
53
+
for (inti=0; i<second; i++)
58
54
{
59
55
sum+=1;
60
56
}
57
+
61
58
returnsum;
62
59
}
63
60
```
64
61
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
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
+
publicstaticIEnumerable<object[]>AdditionData
90
+
{
91
+
get
92
+
{
93
+
returnnew[]
94
+
{
95
+
newobject[] { 1, 1, 2 },
96
+
newobject[] { 2, 2, 4 },
97
+
newobject[] { 3, 3, 6 },
98
+
newobject[] { 0, 0, 1 }, // The test run with this row fails
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[]`.
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
66
141
67
142
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
68
143
@@ -72,31 +147,26 @@ To test the `AddIntegers` method, create a data source that specifies a range of
72
147
|1|1|2|
73
148
|2|-3|-1|
74
149
75
-
## Add a TestContext to the test class
150
+
####Add a TestContext to the test class
76
151
77
152
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.
78
153
79
154
```csharp
80
-
privateTestContexttestContextInstance;
81
-
publicTestContextTestContext
82
-
{
83
-
get { returntestContextInstance; }
84
-
set { testContextInstance=value; }
85
-
}
155
+
publicTestContextTestContext { get; set; }
86
156
```
87
157
88
158
In your test method, you access the data through the `DataRow` indexer property of the `TestContext`.
89
159
90
160
> [!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 Coreor 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?)"**.
92
162
93
-
## Write the test method
163
+
####Write the test method
94
164
95
165
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:
96
166
97
167
```csharp
168
+
[TestMethod]
98
169
[DataSource(@"Provider=Microsoft.SqlServerCe.Client.4.0; Data Source=C:\Data\MathsData.sdf;", "Numbers")]
99
-
[TestMethod()]
100
170
publicvoidAddIntegers_FromDataSourceTest()
101
171
{
102
172
vartarget=newMaths();
@@ -105,16 +175,14 @@ public void AddIntegers_FromDataSourceTest()
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
118
186
119
187
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.
120
188
@@ -149,7 +217,7 @@ The connection strings depend on the type of the type of data source, but it sho
149
217
)]
150
218
```
151
219
152
-
### Use TestContext.DataRow to access the data
220
+
####Use TestContext.DataRow to access the data
153
221
154
222
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:
155
223
@@ -166,26 +234,10 @@ The test results bar at the top of **Test Explorer** is animated as your test ru
166
234
> [!NOTE]
167
235
> 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**.
168
236
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.
170
238
171
239
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.
172
240
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
0 commit comments