Table of Contents

Class TestAttachment

Namespace
Xunit.Sdk

Represents an attachment to a test result.

public class TestAttachment
Inheritance
TestAttachment
Inherited Members
Extension Methods

Constructors

TestAttachment()

Called by the de-serializer; should only be called by deriving classes for de-serialization purposes

[Obsolete("Called by the de-serializer; should only be called by deriving classes for de-serialization purposes")]
public TestAttachment()

Properties

AttachmentType

Gets the type of the test attachment.

public TestAttachmentType AttachmentType { get; }

Property Value

TestAttachmentType

Methods

AsByteArray()

Gets the attachment content as a byte array, along with the media type. Can only be called when AttachmentType returns ByteArray.

public (byte[] ByteArray, string MediaType) AsByteArray()

Returns

(byte[] ByteArray, string MediaType)

AsString()

Gets the attachment content as a string. Can only be called when AttachmentType returns String.

public string AsString()

Returns

string

Create(byte[], string)

Creates an instance of TestAttachment that wraps a byte array value.

public static TestAttachment Create(byte[] value, string mediaType)

Parameters

value byte[]

The byte array value

mediaType string

The media type

Returns

TestAttachment

Remarks

The mediaType value must be in the MIME "type/subtype" form, and does not support parameter values. The subtype is allowed to have a single "+" to denote specialization of the subtype (i.e., "application/xhtml+xml"). For more information on media types, see https://datatracker.ietf.org/doc/html/rfc2045#section-5.1.

Create(string)

Creates an instance of TestAttachment that wraps a string value.

public static TestAttachment Create(string value)

Parameters

value string

Returns

TestAttachment

Parse(string)

Parses a value that was obtained by calling ToString() back into a TestAttachment.

public static TestAttachment Parse(string value)

Parameters

value string

Returns

TestAttachment

ToString()

Gets a string value for the test attachment. For string value attachments, will return the string value; for byte array values, it will return the base-64 encoded value of the bytes.

public override string ToString()

Returns

string