Table of Contents

Class AsyncUtility

Namespace
Xunit.Sdk

Utility class for dealing with asynchronous operations.

public static class AsyncUtility
Inheritance
AsyncUtility
Inherited Members

Methods

IsAsync(MethodInfo)

Determines if the given method is async, as matters to xUnit.net. This means it either (a) returns a Task or ValueTask; or, (b) it is an F# function which was declared as async. Note that this is not the same thing as an "awaitable" method, since xUnit.net does not recreate the compiler's await machinery at runtime.

public static bool IsAsync(MethodInfo method)

Parameters

method MethodInfo

The method to test

Returns

bool

Returns true if the method is async; returns false otherwise.

IsAsyncVoid(MethodInfo)

Determines if the given method is async void by looking for the AsyncStateMachineAttribute and void return type on the method definition.

public static bool IsAsyncVoid(MethodInfo method)

Parameters

method MethodInfo

The method to test

Returns

bool

Returns true if the method is async void; returns false otherwise.

TryConvertToValueTask(object?)

Given an object, will attempt to convert instances of Task or Microsoft.FSharp.Control.FSharpAsync`1 into ValueTask as appropriate. Will return null if the object is not a task of any supported type. Note that this list of supported tasks is purposefully identical to the list used by IsAsync(MethodInfo).

public static ValueTask? TryConvertToValueTask(object? obj)

Parameters

obj object

The object to convert

Returns

ValueTask?

Returns a ValueTask for the given object, if it's compatible; returns null otherwise.