Skip to content

Merge main into live #46570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
uses: github/codeql-action/upload-sarif@fca7ace96b7d713c7035871441bd52efbe39e27e # v3.28.19
with:
sarif_file: results.sarif
4 changes: 4 additions & 0 deletions .openpublishing.redirection.csharp.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@
"source_path_from_root": "/redirections/proposals/csharp-8.0/nested-stackalloc.md",
"redirect_url": "/dotnet/csharp/language-reference/language-specification/structs#164127-stackalloc"
},
{
"source_path_from_root": "/redirections/proposals/csharp-8.0/readonly-instance-members.md",
"redirect_url": "/dotnet/csharp/language-reference/language-specification/structs#16411-properties"
},
{
"source_path_from_root": "/redirections/proposals/csharp-9.0/nullable-reference-types-specification.md",
"redirect_url": "/dotnet/csharp/language-reference/language-specification/types.md#893-nullable-reference-types"
Expand Down
3 changes: 1 addition & 2 deletions docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"csharp-8.0/nullable-reference-types.md",
"csharp-8.0/nullable-reference-types-specification.md",
"csharp-8.0/nested-stackalloc.md",
"csharp-8.0/readonly-instance-members.md",
"csharp-9.0/nullable-reference-types-specification.md",
"csharp-9.0/nullable-constructor-analysis.md",
"csharp-9.0/nullable-parameter-default-value-analysis.md",
Expand Down Expand Up @@ -621,7 +622,6 @@
"_csharplang/proposals/csharp-8.0/ranges.md": "Ranges and indices",
"_csharplang/proposals/csharp-8.0/using.md": "Pattern based using and using declarations",
"_csharplang/proposals/csharp-8.0/null-coalescing-assignment.md": "Null coalescing assignment",
"_csharplang/proposals/csharp-8.0/readonly-instance-members.md": "Readonly instance members",
"_csharplang/proposals/csharp-9.0/covariant-returns.md": "Covariant return types",
"_csharplang/proposals/csharp-9.0/extending-partial-methods.md": "Extending partial methods",
"_csharplang/proposals/csharp-9.0/extension-getenumerator.md": "Extension GetEnumerator support in foreach",
Expand Down Expand Up @@ -748,7 +748,6 @@
"_csharplang/proposals/csharp-8.0/ranges.md": "This feature specification describes the syntax for ranges and indices, which support indexing individual elements of a sequence or a range of a sequence from the start or end of that sequence.",
"_csharplang/proposals/csharp-8.0/using.md": "This feature specification supports pattern based using and using declarations to simplify resource cleanup.",
"_csharplang/proposals/csharp-8.0/null-coalescing-assignment.md": "This feature specification describes the syntax to support null coalescing assignment expressions using the '??=' operator.",
"_csharplang/proposals/csharp-8.0/readonly-instance-members.md": "This feature specification describes the syntax for declaring and using readonly instance members.",
"_csharplang/proposals/csharp-9.0/covariant-returns.md": "This feature specification describes covariant return types, where overriding member declarations can return a type derived from the overridden member declaration.",
"_csharplang/proposals/csharp-9.0/extending-partial-methods.md": "This feature specification describes extensions to partial methods. These extensions enable source generators to create or call partial methods.",
"_csharplang/proposals/csharp-9.0/extension-getenumerator.md": "This feature specification describes the necessary pattern for an extension method to provide the GetEnumerator support in a foreach loop.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.5" />
<PackageReference Include="ModelContextProtocol" Version="0.2.0-preview.2" />
<PackageReference Include="ModelContextProtocol" Version="0.2.0-preview.3" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Logs provide information about how an application or service is running, includi

In monolithic server-based applications, you can write logs to a file on disk (a logfile) and then analyze it with any tool. Since application execution is limited to a fixed server or VM, it generally isn't too complex to analyze the flow of events. However, in a distributed application where multiple services are executed across many nodes in an orchestrator cluster, being able to correlate distributed events is a challenge.

A microservice-based application should not try to store the output stream of events or logfiles by itself, and not even try to manage the routing of the events to a central place. It should be transparent, meaning that each process should just write its event stream to a standard output that underneath will be collected by the execution environment infrastructure where it's running. An example of these event stream routers is [Microsoft.Diagnostic.EventFlow](https://github.com/Azure/diagnostics-eventflow), which collects event streams from multiple sources and publishes it to output systems. These can include simple standard output for a development environment or cloud systems like [Azure Monitor](https://azure.microsoft.com/services/monitor//) and [Azure Diagnostics](/azure/azure-monitor/platform/diagnostics-extension-overview). There are also good third-party log analysis platforms and tools that can search, alert, report, and monitor logs, even in real time, like [Splunk](https://www.splunk.com/goto/Splunk_Log_Management?ac=ga_usa_log_analysis_phrase_Mar17&_kk=logs%20analysis&gclid=CNzkzIrex9MCFYGHfgodW5YOtA).
A microservice-based application should not try to store the output stream of events or logfiles by itself, and not even try to manage the routing of the events to a central place. It should be transparent, meaning that each process should just write its event stream to a standard output that underneath will be collected by the execution environment infrastructure where it's running. An example of these event stream routers is [Microsoft.Diagnostic.EventFlow](https://github.com/Azure/diagnostics-eventflow), which collects event streams from multiple sources and publishes it to output systems. These can include simple standard output for a development environment or cloud systems like [Azure Monitor](https://azure.microsoft.com/services/monitor//) and [Azure Diagnostics](/azure/azure-monitor/platform/diagnostics-extension-overview). There are also good third-party log analysis platforms and tools that can search, alert, report, and monitor logs, even in real time, like [Splunk](https://www.splunk.com/goto/Splunk_Log_Management?ac=ga_usa_log_analysis_phrase_Mar17&_kk=logs%20analysis&gclid=CNzkzIrex9MCFYGHfgodW5YOtA) or [Middleware](https://middleware.io).

### Orchestrators managing health and diagnostics information

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.46.1" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="Moq" Version="[4.20.72]" /> <!-- Context: https://github.com/Azure/azure-sdk-for-net/issues/38111 -->
<PackageReference Include="NSubstitute" Version="5.3.0" />
<PackageReference Include="xunit" Version="2.9.3" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.9.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.9.1" />
<PackageReference Include="coverlet.collector" Version="6.0.4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: MSTest attributes
description: Learn about the various attributes of MSTest.
author: Evangelink
ms.author: amauryleve
ms.date: 07/24/2024
ms.date: 05/30/2025
---

# MSTest attributes
Expand Down Expand Up @@ -73,7 +73,7 @@ Use the following elements to set up data-driven tests. For more information, se
- <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute>

> [!TIP]
> While combinatorial testing isn't directly supported by MSTest, an external [Combinatorial.MSTest NuGet packages](https://www.nuget.org/packages/Combinatorial.MSTest/) adds that support. The package is open source maintained on [Combinatorial.MSTest GitHub repository](https://github.com/Youssef1313/Combinatorial.MSTest). This package is not maintained by Microsoft.
> MSTest doesn't natively support combinatorial testing, but you can add this capability using the open-source [Combinatorial.MSTest](https://www.nuget.org/packages/Combinatorial.MSTest) NuGet package. It's actively maintained by the [community and available on GitHub](https://github.com/Youssef1313/Combinatorial.MSTest). This package isn't maintained by Microsoft.

### `DataRowAttribute`

Expand Down
78 changes: 78 additions & 0 deletions docs/core/testing/unit-testing-mstest-writing-tests-lifecycle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: MSTest test lifecycle
description: Learn about the creation and lifecycle of test classes and test methods in MSTest.
author: marcelwgn
ms.author: marcelwagner
ms.date: 06/03/2025
---

# MSTest lifecycle

MSTest provides a well-defined lifecycle for test classes and test methods, allowing for setup and teardown operations to be performed at various stages of the test execution process. The lifecycle can be grouped into the following three stages:

- Assembly-level lifecycle
- Class-level lifecycle
- Test-level lifecycle

The execution of the lifecycle events occurs from the highest level (assembly) to the lowest level (test method). The order of execution is as follows:

1. Assembly Initialization
1. Class Initialization (for every test class)
1. Test initialization (for every test method)
1. Test Execution
1. Test Cleanup (for every test method)
1. Class Cleanup (for every test class)
1. Assembly Cleanup

## Assembly-level Lifecycle

The assembly lifecycle describes the lifecycle of the entire assembly, which includes all test classes and methods.
To manage the assembly lifecycle, MSTest provides the [AssemblyInitialize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyInitializeAttribute) and [AssemblyCleanup](xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyCleanupAttribute) attributes.
To learn more about these attributes, refer to the [AssemblyInitialize and AssemblyCleanup](./unit-testing-mstest-writing-tests-attributes.md#assembly-level) documentation.

## Class-level Lifecycle

The test class lifecycle refers to the lifecycle of individual test classes within the assembly and can be implemented using the [ClassInitialize](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ClassInitializeAttribute) and [ClassCleanup](xref:Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupAttribute) attributes.
These attributes allow you to define setup and teardown methods that are executed before and after all tests in a class, respectively.
For more information on these attributes, refer to the [ClassInitialize and ClassCleanup](./unit-testing-mstest-writing-tests-attributes.md#class-level) documentation.
The class level lifecycle is only run once per class, regardless of the number of tests in a class.

## Test-level Lifecycle

The test level lifecycle is executed for every test method. For parameterized tests, each set of parameters is treated as a separate test method, and the lifecycle is executed for each set of parameters.
Test level lifecycle can be grouped into setup, execution and cleanup with setup and cleanup supporting multiple ways to be implemented.

#### Setup

The setup phase of the test level lifecycle is responsible for preparing the test environment before the execution of each test method. This can be achieved using the `TestInitialize` attribute or by implementing a constructor in the test class. In the case of inheritance, execution of `TestInitialize` methods follows the order from the base class to the derived class. If a test class implements a constructor, it is executed before the `TestInitialize` method. To learn more about the `TestInitialize` attribute, refer to the [test level attribute](./unit-testing-mstest-writing-tests-attributes.md#test-level) documentation.

> [!NOTE]
> Unlike the class constructor, `TestInitialize` methods can be async and also support attribute usage such as the `TimeoutAttribute`.

#### Execution

The execution phase is the phase where the actual test method is executed. If a test method returns a Task or ValueTask, the test method will be awaited.

> [!WARNING]
> In the case of asynchronous test methods, no [SynchronizationContext](xref:System.Threading.SynchronizationContext) is provided. This does not apply to `UITestMethod` tests for UWP and WinUI as they run on the UI thread which has a [SynchronizationContext](xref:System.Threading.SynchronizationContext).

#### Cleanup

The cleanup phase of the test level lifecycle is responsible for cleaning up the test environment after the execution of each test method.
This can be achieved using the `TestCleanup` attribute or by implementing the `IDisposable`/`IAsyncDisposable` interface in the test class.
If a test class implements `IDisposable` or `IAsyncDisposable`, its `Dispose`/`DisposeAsync` method is executed after the `TestCleanup` method.
In case of inheritance, execution of `TestCleanup` methods follows the order from the derived class to the base class.
To learn more about the `TestInitialize` attribute, refer to the [test level attribute](./unit-testing-mstest-writing-tests-attributes.md#test-level) documentation.

#### Order

The complete order of the test level lifecycle is as follows:

1. Create instance of test class
1. Set `TestContext` property if present
1. Run TestInitialize (if implemented)
1. Test method execution
1. Update `TestContext` with test results (such as `Outcome` property)
1. Run TestCleanup if implemented
1. Run DisposeAsync if implemented
1. Run Dispose if implemented
2 changes: 1 addition & 1 deletion docs/csharp/language-reference/builtin-types/ref-struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ The compiler enforces these restrictions. If you write `ref struct` types that i
For more information, see the following sections of the [C# language specification](~/_csharpstandard/standard/README.md):

- [Structs: Ref modifier](~/_csharpstandard/standard/structs.md#1623-ref-modifier)
- [Safe context constraint for ref struct types](~/_csharpstandard/standard/structs.md#16412-safe-context-constraint)
- [Safe context constraint for ref struct types](~/_csharpstandard/standard/structs.md#16415-safe-context-constraint)

For more information about `ref` fields, see the [Low-level struct improvements](~/_csharplang/proposals/csharp-11.0/low-level-struct-improvements.md) proposal note.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ The preceding syntax would require implementers to use [explicit interface imple
The `allows ref struct` anti-constraint declares that the corresponding type argument can be a [`ref struct`](../../language-reference/builtin-types/ref-struct.md) type. Instances of that type parameter must obey the following rules:

- It can't be boxed.
- It participates in [ref safety rules](~/_csharpstandard/standard/structs.md#16412-safe-context-constraint).
- It participates in [ref safety rules](~/_csharpstandard/standard/structs.md#16415-safe-context-constraint).
- Instances can't be used where a `ref struct` type isn't allowed, such as `static` fields.
- Instances can be marked with the `scoped` modifier.

Expand Down
2 changes: 0 additions & 2 deletions docs/csharp/specification/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,6 @@ items:
href: ../../../_csharplang/proposals/extensions.md
- name: Structs
items:
- name: Readonly instance members
href: ../../../_csharplang/proposals/csharp-8.0/readonly-instance-members.md
- name: Parameterless struct constructors
href: ../../../_csharplang/proposals/csharp-10.0/parameterless-struct-constructors.md
- name: Auto-default struct
Expand Down
33 changes: 31 additions & 2 deletions docs/fsharp/language-reference/task-expressions.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
title: Task expressions
description: Learn about support in the F# programming language for writing task expressions, which author .NET tasks directly.
ms.date: 10/29/2021
ms.date: 05/25/2025
---
# Tasks expressions
# Task expressions

This article describes support in F# for task expressions, which are similar to [async expressions](async-expressions.md) but allow you to author .NET tasks directly. Like async expressions, task expressions execute code asynchronously, that is, without blocking execution of other work.

Expand Down Expand Up @@ -55,6 +55,35 @@ Within task expressions, `use` bindings can bind to values of type <xref:System.

In addition to `let!`, you can use `use!` to perform asynchronous bindings. The difference between `let!` and `use!` is the same as the difference between `let` and `use`. For `use!`, the object is disposed of at the close of the current scope. Note that in F# 6, `use!` does not allow a value to be initialized to null, even though `use` does.

```fsharp
open System
open System.IO
open System.Security.Cryptography
task {
// use IDisposable
use httpClient = new Net.Http.HttpClient()
// use! Task<IDisposable>
use! exampleDomain = httpClient.GetAsync "https://example.com/data.enc"

// use IDisposable
use aes = Aes.Create()
aes.KeySize <- 256
aes.GenerateIV()
aes.GenerateKey()
// do! Task
do! File.WriteAllTextAsync("key.iv.txt", $"Key: {Convert.ToBase64String aes.Key}\nIV: {Convert.ToBase64String aes.IV}")

// use IAsyncDisposable
use outputStream = File.Create "secret.enc"
// use IDisposable
use encryptor = aes.CreateEncryptor()
// use IAsyncDisposable
use cryptoStream = new CryptoStream(outputStream, encryptor, CryptoStreamMode.Write)
// do! Task
do! exampleDomain.Content.CopyToAsync cryptoStream
}
```

## Value Tasks

Value tasks are structs used to avoid allocations in task-based programming. A value task is an ephemeral value that's turned into a real task by using `.AsTask()`.
Expand Down
Loading
Loading