Table of Contents

Class ResultAssertions<TValue>

Namespace
Trellis.Testing
Assembly
Trellis.Testing.dll

Contains assertion methods for Result types.

public class ResultAssertions<TValue> : ReferenceTypeAssertions<Result<TValue>, ResultAssertions<TValue>>

Type Parameters

TValue
Inheritance
ResultAssertions<TValue>
Inherited Members
Extension Methods

Constructors

ResultAssertions(Result<TValue>)

Initializes a new instance of the ResultAssertions<TValue> class.

public ResultAssertions(Result<TValue> result)

Parameters

result Result<TValue>

Properties

Identifier

Returns the type of the subject the assertion applies on. It should be a user-friendly name as it is included in the failure message.

protected override string Identifier { get; }

Property Value

string

Methods

BeFailure(string, params object[])

Asserts that the result is a failure.

public AndWhichConstraint<ResultAssertions<TValue>, Error> BeFailure(string because = "", params object[] becauseArgs)

Parameters

because string

A formatted phrase explaining why the assertion is needed.

becauseArgs object[]

Zero or more objects to format using the placeholders in because.

Returns

AndWhichConstraint<ResultAssertions<TValue>, Error>

BeFailureOfType<TError>(string, params object[])

Asserts that the result is a failure with a specific error type.

public AndWhichConstraint<ResultAssertions<TValue>, TError> BeFailureOfType<TError>(string because = "", params object[] becauseArgs) where TError : Error

Parameters

because string

A formatted phrase explaining why the assertion is needed.

becauseArgs object[]

Zero or more objects to format using the placeholders in because.

Returns

AndWhichConstraint<ResultAssertions<TValue>, TError>

Type Parameters

TError

The expected error type.

BeSuccess(string, params object[])

Asserts that the result is a success.

public AndWhichConstraint<ResultAssertions<TValue>, TValue> BeSuccess(string because = "", params object[] becauseArgs)

Parameters

because string

A formatted phrase as is supported by Format(string, params object[]) explaining why the assertion is needed. If the phrase does not start with the word because, it is prepended automatically.

becauseArgs object[]

Zero or more objects to format using the placeholders in because.

Returns

AndWhichConstraint<ResultAssertions<TValue>, TValue>

HaveErrorCode(string, string, params object[])

Asserts that the failure has a specific error code.

public AndConstraint<ResultAssertions<TValue>> HaveErrorCode(string expectedCode, string because = "", params object[] becauseArgs)

Parameters

expectedCode string

The expected error code.

because string

A formatted phrase explaining why the assertion is needed.

becauseArgs object[]

Zero or more objects to format using the placeholders in because.

Returns

AndConstraint<ResultAssertions<TValue>>

HaveErrorDetail(string, string, params object[])

Asserts that the failure has a specific error detail.

public AndConstraint<ResultAssertions<TValue>> HaveErrorDetail(string expectedDetail, string because = "", params object[] becauseArgs)

Parameters

expectedDetail string

The expected error detail.

because string

A formatted phrase explaining why the assertion is needed.

becauseArgs object[]

Zero or more objects to format using the placeholders in because.

Returns

AndConstraint<ResultAssertions<TValue>>

HaveErrorDetailContaining(string, string, params object[])

Asserts that the failure error detail contains the specified substring.

public AndConstraint<ResultAssertions<TValue>> HaveErrorDetailContaining(string substring, string because = "", params object[] becauseArgs)

Parameters

substring string

The substring to search for.

because string

A formatted phrase explaining why the assertion is needed.

becauseArgs object[]

Zero or more objects to format using the placeholders in because.

Returns

AndConstraint<ResultAssertions<TValue>>

HaveValue(TValue, string, params object[])

Asserts that the success value equals the expected value.

public AndConstraint<ResultAssertions<TValue>> HaveValue(TValue expectedValue, string because = "", params object[] becauseArgs)

Parameters

expectedValue TValue

The expected value.

because string

A formatted phrase explaining why the assertion is needed.

becauseArgs object[]

Zero or more objects to format using the placeholders in because.

Returns

AndConstraint<ResultAssertions<TValue>>

HaveValueEquivalentTo(TValue, string, params object[])

Asserts that the success value is equivalent to the expected value using structural comparison.

public AndConstraint<ResultAssertions<TValue>> HaveValueEquivalentTo(TValue expectedValue, string because = "", params object[] becauseArgs)

Parameters

expectedValue TValue

The expected value.

because string

A formatted phrase explaining why the assertion is needed.

becauseArgs object[]

Zero or more objects to format using the placeholders in because.

Returns

AndConstraint<ResultAssertions<TValue>>

HaveValueMatching(Func<TValue, bool>, string, params object[])

Asserts that the success value satisfies a predicate.

public AndConstraint<ResultAssertions<TValue>> HaveValueMatching(Func<TValue, bool> predicate, string because = "", params object[] becauseArgs)

Parameters

predicate Func<TValue, bool>

The predicate the value should satisfy.

because string

A formatted phrase explaining why the assertion is needed.

becauseArgs object[]

Zero or more objects to format using the placeholders in because.

Returns

AndConstraint<ResultAssertions<TValue>>