> ## Documentation Index
> Fetch the complete documentation index at: https://easyaf.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# TestContext

> Extension methods for TestContext from MSTest.TestFramework.Extensions

## Definition

**Assembly:** MSTest.TestFramework.Extensions.dll

**Namespace:** Microsoft.VisualStudio.TestTools.UnitTesting

## Syntax

```csharp theme={"dark"}
Microsoft.VisualStudio.TestTools.UnitTesting.TestContext
```

## Summary

This type is defined in MSTest.TestFramework.Extensions.

## Methods

### <Icon icon="puzzle-piece" iconType="duotone" color="#419AC5" size={24} className="mr-2" /> LogAndReturnMessageContentAsync <Badge color="green">Extension</Badge>

<Note>Extension method from `Microsoft.VisualStudio.TestTools.UnitTesting.Breakdance_MsTest2_TestContextExtensions`</Note>

Attempts to unwrap the [Content](https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage.content) and log it to the *testContext* if possible.

#### Syntax

```csharp theme={"dark"}
public static System.Threading.Tasks.Task<string> LogAndReturnMessageContentAsync(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext testContext, System.Net.Http.HttpResponseMessage message, bool nullIsExpected = false)
```

#### Parameters

| Name             | Type                                                       | Description                                                                                                                                              |
| ---------------- | ---------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `testContext`    | `Microsoft.VisualStudio.TestTools.UnitTesting.TestContext` | -                                                                                                                                                        |
| `message`        | `System.Net.Http.HttpResponseMessage`                      | -                                                                                                                                                        |
| `nullIsExpected` | `bool`                                                     | Specifies whether the [Content](https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage.content) in *message* is expected to be null. |

#### Returns

Type: `System.Threading.Tasks.Task<string>`

#### Remarks

This exists in order to safely allow the tests to continue in the absence of correct content. This is because the tests should log
the response content BEFORE failing the test for an incorrect [StatusCode](https://learn.microsoft.com/dotnet/api/system.net.http.httpresponsemessage.statuscode).
