Table of Contents

Class MockCollection<TMock>

Namespace
Mokkit.Containers.Common
Assembly
Mokkit.Containers.Common.dll

Represents a concrete implementation of Mokkit.Containers.Common.IMockCollection`1 that manages a collection of mock registrations. This class provides list functionality while adding mock-specific registration methods with validation and fluent API support.

public class MockCollection<TMock> : IMockCollection<TMock>, IList<MockRegistration<TMock>>, ICollection<MockRegistration<TMock>>, IEnumerable<MockRegistration<TMock>>, IEnumerable

Type Parameters

TMock

The type of mock objects managed by this collection.

Inheritance

Implements

Inherited Members

Properties

Count

public int Count { get; }

Property Value

int

IsReadOnly

public bool IsReadOnly { get; }

Property Value

bool

Registrations

Gets a read-only collection of all mock registrations in this collection.

public IReadOnlyCollection<MockRegistration<TMock>> Registrations { get; }

Property Value

IReadOnlyCollection<MockRegistration<TMock>>

this[int]

public MockRegistration<TMock> this[int index] { get; set; }

Property Value

MockRegistration<TMock>

Methods

Add(MockRegistration<TMock>)

public void Add(MockRegistration<TMock> item)

Parameters

item MockRegistration<TMock>

AddMock<T>(Func<TMock>)

Adds a new mock registration to the collection using the provided factory method.

public IMockCollection<TMock> AddMock<T>(Func<TMock> factory)

Parameters

factory Func<TMock>

A factory method that creates a new instance of the mock object.

Returns

IMockCollection<TMock>

The current instance of the Mokkit.Containers.Common.MockCollection`1 for fluent API support.

Type Parameters

T

The type of the mock object being registered.

Exceptions

InvalidOperationException

Thrown if a mock registration for the same type already exists in the collection.

Clear()

public void Clear()

Contains(MockRegistration<TMock>)

public bool Contains(MockRegistration<TMock> item)

Parameters

item MockRegistration<TMock>

Returns

bool

CopyTo(MockRegistration<TMock>[], int)

public void CopyTo(MockRegistration<TMock>[] array, int arrayIndex)

Parameters

array MockRegistration<TMock>[]
arrayIndex int

GetEnumerator()

public IEnumerator<MockRegistration<TMock>> GetEnumerator()

Returns

IEnumerator<MockRegistration<TMock>>

IndexOf(MockRegistration<TMock>)

public int IndexOf(MockRegistration<TMock> item)

Parameters

item MockRegistration<TMock>

Returns

int

Insert(int, MockRegistration<TMock>)

public void Insert(int index, MockRegistration<TMock> item)

Parameters

index int
item MockRegistration<TMock>

MakeReadOnly()

Makes the collection read-only, preventing further modifications.

public void MakeReadOnly()

Remove(MockRegistration<TMock>)

public bool Remove(MockRegistration<TMock> item)

Parameters

item MockRegistration<TMock>

Returns

bool

RemoveAt(int)

public void RemoveAt(int index)

Parameters

index int

TryAddMock<T>(Func<TMock>)

Adds a new mock registration to the collection using the provided factory method if it does not already exist.

public IMockCollection<TMock> TryAddMock<T>(Func<TMock> factory)

Parameters

factory Func<TMock>

A factory method that creates a new instance of the mock object.

Returns

IMockCollection<TMock>

The current instance of the Mokkit.Containers.Common.MockCollection`1 for fluent API support.

Type Parameters

T

The type of the mock object being registered.