Class
MockingContainer<T>

Auto-mocking container that can automatically inject mocks for all dependencies of the tested class. The container is based on NInject and supports the core NInject syntax as well as syntax extensions for arranging mocks and injecting mocks into properties and constructor arguments.

Definition

Namespace:Telerik.JustMock.AutoMock

Assembly:Telerik.JustMock.dll

Type Parameters:

T

The type of the class whose dependencies should be mocked. If this is an abstract class, then a Behavior.CallOriginal mock is created for the instance. Abstract members of the instance can be manipulated using the methods in the Mock class.

Syntax:

cs-api-definition
public sealed class MockingContainer<T> : StandardKernel, IServiceProvider, IDisposable where T : class

Inheritance: objectDisposableObjectBindingRootKernelBaseStandardKernelMockingContainer<T>

Implements: IDisposableIServiceProvider

Constructors

MockingContainer(AutoMockSettings)

Initializes a new instance of the MockingContainer<T> class.

Declaration

cs-api-definition
public MockingContainer(AutoMockSettings settings = null)

Parameters

settings

AutoMockSettings

Optional settings that modify the way the auto-mocking container works.

Properties

Instance

Resolves the instance of the underlying type with all dependencies injected.

Declaration

cs-api-definition
public T Instance { get; }

Property Value

T

Settings

Gets the kernel settings.

Declaration

cs-api-definition
public AutoMockSettings Settings { get; }

Property Value

AutoMockSettings

Methods

AddComponents()

Implementation detail.

Declaration

cs-api-definition
protected override void AddComponents()

Overrides StandardKernel.AddComponents()

Arrange<TInterface, TResult>(Expression<Func<TInterface, Task<TResult>>>)

Declaration

cs-api-definition
public FuncExpectation<Task<TResult>> Arrange<TInterface, TResult>(Expression<Func<TInterface, Task<TResult>>> expression)

Parameters

expression

Expression<Func<TInterface, Task<TResult>>>

Returns

FuncExpectation<Task<TResult>>

Arrange<TInterface>(Expression<Action<TInterface>>)

Entry-point for setting expectations.

Declaration

cs-api-definition
public ActionExpectation Arrange<TInterface>(Expression<Action<TInterface>> expression)

Parameters

expression

Expression<Action<TInterface>>

Target expression

Returns

ActionExpectation

Reference to ActionExpectation to setup the mock.

Arrange<TInterface>(Expression<Func<TInterface, Task>>)

Declaration

cs-api-definition
public FuncExpectation<Task> Arrange<TInterface>(Expression<Func<TInterface, Task>> expression)

Parameters

expression

Expression<Func<TInterface, Task>>

Returns

FuncExpectation<Task>

Arrange<TInterface>(Expression<Func<TInterface, object>>)

Entry-point for setting expectations.

Declaration

cs-api-definition
public FuncExpectation<object> Arrange<TInterface>(Expression<Func<TInterface, object>> expression)

Parameters

expression

Expression<Func<TInterface, object>>

Target expression

Returns

FuncExpectation<object>

Reference to FuncExpectation<TReturn> to setup the mock.

ArrangeSet<TInterface>(Action<TInterface>)

Entry-point for setting expectations.

Declaration

cs-api-definition
public ActionExpectation ArrangeSet<TInterface>(Action<TInterface> action)

Parameters

action

Action<TInterface>

Target action

Returns

ActionExpectation

Reference to ActionExpectation to setup the mock.

Assert(string)

Asserts all expected calls that are marked as must or to be occurred a certain number of times.

Declaration

cs-api-definition
public void Assert(string message = null)

Parameters

message

string

A message to display if the assertion fails.

Assert<TService>()

Asserts a specific dependency

Declaration

cs-api-definition
public void Assert<TService>()

Assert<TService>(Expression<Action<TService>>, Occurs, string)

Asserts the specific call

Declaration

cs-api-definition
public void Assert<TService>(Expression<Action<TService>> expression, Occurs occurs, string message = null)

Parameters

expression

Expression<Action<TService>>

Target expression

occurs

Occurs

Specifies the number of times a mock call should occur.

message

string

A message to display if the assertion fails.

Assert<TService>(Expression<Action<TService>>, string)

Asserts the specific call

Declaration

cs-api-definition
public void Assert<TService>(Expression<Action<TService>> expression, string message = null)

Parameters

expression

Expression<Action<TService>>

Target expression.

message

string

A message to display if the assertion fails.

Assert<TService>(Expression<Func<TService, object>>, Occurs, string)

Asserts the specific call

Declaration

cs-api-definition
public void Assert<TService>(Expression<Func<TService, object>> expression, Occurs occurs, string message = null)

Parameters

expression

Expression<Func<TService, object>>

Target expression.

occurs

Occurs

Specifies the number of times a mock call should occur.

message

string

A message to display if the assertion fails.

Assert<TService>(Expression<Func<TService, object>>, string)

Asserts the specific call

Declaration

cs-api-definition
public void Assert<TService>(Expression<Func<TService, object>> expression, string message = null)

Parameters

expression

Expression<Func<TService, object>>

Target expression

message

string

A message to display if the assertion fails.

Assert<TService>(string, Expression<Action<TService>>, Occurs, string)

Asserts the specific call

Declaration

cs-api-definition
public void Assert<TService>(string bindingName, Expression<Action<TService>> expression, Occurs occurs, string message = null)

Parameters

bindingName

string

Name.

expression

Expression<Action<TService>>

Target expression.

occurs

Occurs

Specifies the number of times a mock call should occur.

message

string

A message to display if the assertion fails.

Assert<TService>(string, Expression<Action<TService>>, string)

Asserts the specific call

Declaration

cs-api-definition
public void Assert<TService>(string bindingName, Expression<Action<TService>> expression, string message = null)

Parameters

bindingName

string

Name.

expression

Expression<Action<TService>>

Target expression.

message

string

A message to display if the assertion fails.

Assert<TService>(string, Expression<Func<TService, object>>, Occurs, string)

Asserts the specific call

Declaration

cs-api-definition
public void Assert<TService>(string bindingName, Expression<Func<TService, object>> expression, Occurs occurs, string message = null)

Parameters

bindingName

string

Name.

expression

Expression<Func<TService, object>>

Target expression.

occurs

Occurs

Specifies the number of times a mock call should occur.

message

string

A message to display if the assertion fails.

Assert<TService>(string, Expression<Func<TService, object>>, string)

Asserts the specific call

Declaration

cs-api-definition
public void Assert<TService>(string bindingName, Expression<Func<TService, object>> expression, string message = null)

Parameters

bindingName

string

Name.

expression

Expression<Func<TService, object>>

Target expression.

message

string

A message to display if the assertion fails.

Assert<TService>(string, string)

Asserts a specific dependency

Declaration

cs-api-definition
public void Assert<TService>(string bindingName, string message = null)

Parameters

bindingName

string

Name.

message

string

A message to display if the assertion fails.

AssertAll(string)

Asserts all expected setups.

Declaration

cs-api-definition
public void AssertAll(string message = null)

Parameters

message

string

A message to display if the assertion fails.

AssertSet<TService>(Action<TService>, Occurs, string)

Asserts the specific call

Declaration

cs-api-definition
public void AssertSet<TService>(Action<TService> action, Occurs occurs, string message = null)

Parameters

action

Action<TService>

Target action.

occurs

Occurs

Specifies the number of times a mock call should occur.

message

string

A message to display if the assertion fails.

AssertSet<TService>(Action<TService>, string)

Asserts the specific call

Declaration

cs-api-definition
public void AssertSet<TService>(Action<TService> action, string message = null)

Parameters

action

Action<TService>

Target action.

message

string

A message to display if the assertion fails.

ShouldAddComponent(Type, Type)

Implementation detail.

Declaration

cs-api-definition
protected override bool ShouldAddComponent(Type component, Type implementation)

Parameters

component

Type

implementation

Type

Returns

bool

Overrides StandardKernel.ShouldAddComponent(Type, Type)