ClassMockingContainer<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:
public sealed class MockingContainer<T> : StandardKernel, IServiceProvider, IDisposable where T : class
Inheritance: objectDisposableObjectBindingRootKernelBaseStandardKernelMockingContainer<T>
Implements:
Constructors
MockingContainer(AutoMockSettings)
Initializes a new instance of the MockingContainer<T> class.
Declaration
public MockingContainer(AutoMockSettings settings = null)
Parameters
settings
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
public T Instance { get; }
Property Value
T
Settings
Gets the kernel settings.
Declaration
public AutoMockSettings Settings { get; }
Property Value
Methods
AddComponents()
Implementation detail.
Declaration
protected override void AddComponents()
Overrides
Arrange<TInterface, TResult>(Expression<Func<TInterface, Task<TResult>>>)
Declaration
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
public ActionExpectation Arrange<TInterface>(Expression<Action<TInterface>> expression)
Parameters
expression
Expression<Action<TInterface>>
Target expression
Returns
Reference to ActionExpectation to setup the mock.
Arrange<TInterface>(Expression<Func<TInterface, Task>>)
Declaration
public FuncExpectation<Task> Arrange<TInterface>(Expression<Func<TInterface, Task>> expression)
Parameters
expression
Expression<Func<TInterface, Task>>
Returns
Arrange<TInterface>(Expression<Func<TInterface, object>>)
Entry-point for setting expectations.
Declaration
public FuncExpectation<object> Arrange<TInterface>(Expression<Func<TInterface, object>> expression)
Parameters
expression
Expression<Func<TInterface, object>>
Target expression
Returns
Reference to FuncExpectation<TReturn> to setup the mock.
ArrangeSet<TInterface>(Action<TInterface>)
Entry-point for setting expectations.
Declaration
public ActionExpectation ArrangeSet<TInterface>(Action<TInterface> action)
Parameters
action
Action<TInterface>
Target action
Returns
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
public void Assert(string message = null)
Parameters
message
A message to display if the assertion fails.
Assert<TService>()
Asserts a specific dependency
Declaration
public void Assert<TService>()
Assert<TService>(Expression<Action<TService>>, Occurs, string)
Asserts the specific call
Declaration
public void Assert<TService>(Expression<Action<TService>> expression, Occurs occurs, string message = null)
Parameters
expression
Expression<Action<TService>>
Target expression
occurs
Specifies the number of times a mock call should occur.
message
A message to display if the assertion fails.
Assert<TService>(Expression<Action<TService>>, string)
Asserts the specific call
Declaration
public void Assert<TService>(Expression<Action<TService>> expression, string message = null)
Parameters
expression
Expression<Action<TService>>
Target expression.
message
A message to display if the assertion fails.
Assert<TService>(Expression<Func<TService, object>>, Occurs, string)
Asserts the specific call
Declaration
public void Assert<TService>(Expression<Func<TService, object>> expression, Occurs occurs, string message = null)
Parameters
expression
Expression<Func<TService, object>>
Target expression.
occurs
Specifies the number of times a mock call should occur.
message
A message to display if the assertion fails.
Assert<TService>(Expression<Func<TService, object>>, string)
Asserts the specific call
Declaration
public void Assert<TService>(Expression<Func<TService, object>> expression, string message = null)
Parameters
expression
Expression<Func<TService, object>>
Target expression
message
A message to display if the assertion fails.
Assert<TService>(string, Expression<Action<TService>>, Occurs, string)
Asserts the specific call
Declaration
public void Assert<TService>(string bindingName, Expression<Action<TService>> expression, Occurs occurs, string message = null)
Parameters
bindingName
Name.
expression
Expression<Action<TService>>
Target expression.
occurs
Specifies the number of times a mock call should occur.
message
A message to display if the assertion fails.
Assert<TService>(string, Expression<Action<TService>>, string)
Asserts the specific call
Declaration
public void Assert<TService>(string bindingName, Expression<Action<TService>> expression, string message = null)
Parameters
bindingName
Name.
expression
Expression<Action<TService>>
Target expression.
message
A message to display if the assertion fails.
Assert<TService>(string, Expression<Func<TService, object>>, Occurs, string)
Asserts the specific call
Declaration
public void Assert<TService>(string bindingName, Expression<Func<TService, object>> expression, Occurs occurs, string message = null)
Parameters
bindingName
Name.
expression
Expression<Func<TService, object>>
Target expression.
occurs
Specifies the number of times a mock call should occur.
message
A message to display if the assertion fails.
Assert<TService>(string, Expression<Func<TService, object>>, string)
Asserts the specific call
Declaration
public void Assert<TService>(string bindingName, Expression<Func<TService, object>> expression, string message = null)
Parameters
bindingName
Name.
expression
Expression<Func<TService, object>>
Target expression.
message
A message to display if the assertion fails.
Assert<TService>(string, string)
Asserts a specific dependency
AssertAll(string)
Asserts all expected setups.
Declaration
public void AssertAll(string message = null)
Parameters
message
A message to display if the assertion fails.
AssertSet<TService>(Action<TService>, Occurs, string)
Asserts the specific call
Declaration
public void AssertSet<TService>(Action<TService> action, Occurs occurs, string message = null)
Parameters
action
Action<TService>
Target action.
occurs
Specifies the number of times a mock call should occur.
message
A message to display if the assertion fails.
AssertSet<TService>(Action<TService>, string)
Asserts the specific call
ShouldAddComponent(Type, Type)
Implementation detail.