Table of Contents

Class ProxyDemo.MockFramework.Mock<TIn, TOut>

Namespace
PatternKit.Examples.ProxyDemo
Assembly
PatternKit.Examples.dll

Creates a mock object for testing.

public sealed class ProxyDemo.MockFramework.Mock<TIn, TOut> where TIn : notnull

Type Parameters

TIn

The input type for the mocked operation.

TOut

The output type for the mocked operation.

Inheritance
ProxyDemo.MockFramework.Mock<TIn, TOut>
Inherited Members
Extension Methods

Remarks

The mock records all invocations and allows verification of interactions, similar to popular mocking frameworks.

Properties

Invocations

Get all recorded invocations.

public IReadOnlyList<TIn> Invocations { get; }

Property Value

IReadOnlyList<TIn>

Methods

Build()

Build the mock proxy.

public Proxy<TIn, TOut> Build()

Returns

Proxy<TIn, TOut>

Returns(TOut)

Configure the mock to return a specific value for any input.

public ProxyDemo.MockFramework.Mock<TIn, TOut> Returns(TOut result)

Parameters

result TOut

Returns

ProxyDemo.MockFramework.Mock<TIn, TOut>

Setup(Func<TIn, bool>, TOut)

Configure the mock to return a specific value when the predicate matches.

public ProxyDemo.MockFramework.Mock<TIn, TOut> Setup(Func<TIn, bool> predicate, TOut result)

Parameters

predicate Func<TIn, bool>
result TOut

Returns

ProxyDemo.MockFramework.Mock<TIn, TOut>

Throws<TException>()

Configure the mock to throw an exception when invoked.

public ProxyDemo.MockFramework.Mock<TIn, TOut> Throws<TException>() where TException : Exception, new()

Returns

ProxyDemo.MockFramework.Mock<TIn, TOut>

Type Parameters

TException

Verify(Func<TIn, bool>, int)

Verify that the mock was called with the specified input.

public void Verify(Func<TIn, bool> predicate, int times = 1)

Parameters

predicate Func<TIn, bool>
times int

VerifyAny(Func<TIn, bool>)

Verify that the mock was called at least once.

public void VerifyAny(Func<TIn, bool> predicate)

Parameters

predicate Func<TIn, bool>