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.
Inheritance
Inherited Members
Namespace: Telerik.JustMock.AutoMock
Assembly: Telerik.JustMock.dll
Syntax
public sealed class MockingContainer<T> : StandardKernel, IKernel, IBindingRoot, IResolutionRoot, IFluentSyntax, IServiceProvider, INotifyWhenDisposed, IDisposableObject, IDisposable where T : class
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. |
Constructors
MockingContainer(AutoMockSettings)
Initializes a new instance of the MockingContainer<T> class.
Declaration
public MockingContainer(AutoMockSettings settings = null)
Parameters
|
AutoMockSettings
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
|
AutoMockSettings
|
Methods
AddComponents()
Implementation detail.
Declaration
protected override void AddComponents()
Overrides
Arrange<TInterface>(Expression<Action<TInterface>>)
Entry-point for setting expectations.
Declaration
public ActionExpectation Arrange<TInterface>(Expression<Action<TInterface>> expression)
Parameters
|
System.Linq.Expressions.Expression<System.Action<TInterface>>
expression
Target expression |
Returns
|
ActionExpectation
Reference to ActionExpectation to setup the mock. |
Type Parameters
|
TInterface
Mocking interface |
Arrange<TInterface>(Expression<Func<TInterface, Object>>)
Entry-point for setting expectations.
Declaration
public FuncExpectation<object> Arrange<TInterface>(Expression<Func<TInterface, object>> expression)
Parameters
|
System.Linq.Expressions.Expression<System.Func<TInterface, System.Object>>
expression
Target expression |
Returns
|
FuncExpectation<System.Object>
Reference to FuncExpectation<TReturn> to setup the mock. |
Type Parameters
|
TInterface
Mocking interface |
Arrange<TInterface>(Expression<Func<TInterface, Task>>)
Declaration
public FuncExpectation<Task> Arrange<TInterface>(Expression<Func<TInterface, Task>> expression)
Parameters
|
System.Linq.Expressions.Expression<System.Func<TInterface, System.Threading.Tasks.Task>>
expression
|
Returns
|
FuncExpectation<System.Threading.Tasks.Task>
|
Type Parameters
|
TInterface
|
Arrange<TInterface, TResult>(Expression<Func<TInterface, Task<TResult>>>)
Declaration
public FuncExpectation<Task<TResult>> Arrange<TInterface, TResult>(Expression<Func<TInterface, Task<TResult>>> expression)
Parameters
|
System.Linq.Expressions.Expression<System.Func<TInterface, System.Threading.Tasks.Task<TResult>>>
expression
|
Returns
|
FuncExpectation<System.Threading.Tasks.Task<TResult>>
|
Type Parameters
|
TInterface
|
|
TResult
|
ArrangeSet<TInterface>(Action<TInterface>)
Entry-point for setting expectations.
Declaration
public ActionExpectation ArrangeSet<TInterface>(Action<TInterface> action)
Parameters
|
System.Action<TInterface>
action
Target action |
Returns
|
ActionExpectation
Reference to ActionExpectation to setup the mock. |
Type Parameters
|
TInterface
Mocking interface |
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
|
System.String
message
A message to display if the assertion fails. |
Assert<TService>()
Asserts a specific dependency
Declaration
public void Assert<TService>()
Type Parameters
|
TService
Service type. |
Assert<TService>(Expression<Action<TService>>, String)
Asserts the specific call
Declaration
public void Assert<TService>(Expression<Action<TService>> expression, string message = null)
Parameters
|
System.Linq.Expressions.Expression<System.Action<TService>>
expression
Target expression. |
|
System.String
message
A message to display if the assertion fails. |
Type Parameters
|
TService
Service type. |
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
|
System.Linq.Expressions.Expression<System.Action<TService>>
expression
Target expression |
|
Occurs
occurs
Specifies the number of times a mock call should occur. |
|
System.String
message
A message to display if the assertion fails. |
Type Parameters
|
TService
Service Type. |
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
|
System.Linq.Expressions.Expression<System.Func<TService, System.Object>>
expression
Target expression |
|
System.String
message
A message to display if the assertion fails. |
Type Parameters
|
TService
Service type. |
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
|
System.Linq.Expressions.Expression<System.Func<TService, System.Object>>
expression
Target expression. |
|
Occurs
occurs
Specifies the number of times a mock call should occur. |
|
System.String
message
A message to display if the assertion fails. |
Type Parameters
|
TService
Service Type. |
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
|
System.String
bindingName
Name. |
|
System.Linq.Expressions.Expression<System.Action<TService>>
expression
Target expression. |
|
System.String
message
A message to display if the assertion fails. |
Type Parameters
|
TService
Service Type. |
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
|
System.String
bindingName
Name. |
|
System.Linq.Expressions.Expression<System.Action<TService>>
expression
Target expression. |
|
Occurs
occurs
Specifies the number of times a mock call should occur. |
|
System.String
message
A message to display if the assertion fails. |
Type Parameters
|
TService
Service Type. |
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
|
System.String
bindingName
Name. |
|
System.Linq.Expressions.Expression<System.Func<TService, System.Object>>
expression
Target expression. |
|
System.String
message
A message to display if the assertion fails. |
Type Parameters
|
TService
Service Type. |
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
|
System.String
bindingName
Name. |
|
System.Linq.Expressions.Expression<System.Func<TService, System.Object>>
expression
Target expression. |
|
Occurs
occurs
Specifies the number of times a mock call should occur. |
|
System.String
message
A message to display if the assertion fails. |
Type Parameters
|
TService
Service Type. |
Assert<TService>(String, String)
Asserts a specific dependency
Declaration
public void Assert<TService>(string bindingName, string message = null)
Parameters
|
System.String
bindingName
Name. |
|
System.String
message
A message to display if the assertion fails. |
Type Parameters
|
TService
Service Type. |
AssertAll(String)
Asserts all expected setups.
Declaration
public void AssertAll(string message = null)
Parameters
|
System.String
message
A message to display if the assertion fails. |
AssertSet<TService>(Action<TService>, String)
Asserts the specific call
Declaration
public void AssertSet<TService>(Action<TService> action, string message = null)
Parameters
|
System.Action<TService>
action
Target action. |
|
System.String
message
A message to display if the assertion fails. |
Type Parameters
|
TService
Service type. |
AssertSet<TService>(Action<TService>, Occurs, String)
Asserts the specific call
Declaration
public void AssertSet<TService>(Action<TService> action, Occurs occurs, string message = null)
Parameters
|
System.Action<TService>
action
Target action. |
|
Occurs
occurs
Specifies the number of times a mock call should occur. |
|
System.String
message
A message to display if the assertion fails. |
Type Parameters
|
TService
Service type. |
ShouldAddComponent(Type, Type)
Implementation detail.
Declaration
protected override bool ShouldAddComponent(Type component, Type implementation)
Parameters
|
System.Type
component
|
|
System.Type
implementation
|
Returns
|
System.Boolean
|