skip navigation
  • Product Bundles

    DevCraft

    All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with:

    • AI Coding Assistants
    • Embedded Reporting
    • Document Processing Libraries
    • SSO Account Sign-in

    Web

    Kendo UI UI for Angular UI for Vue UI for jQuery KendoReact UI for Blazor UI for ASP.NET Core UI for ASP.NET MVC UI for ASP.NET AJAX

    Mobile

    UI for .NET MAUI

    Document Management

    Telerik Document Processing

    Desktop

    UI for .NET MAUI UI for WinUI UI for WinForms UI for WPF

    Reporting

    Telerik Reporting Telerik Report Server

    Testing & Mocking

    Test Studio Telerik JustMock

    CMS

    Sitefinity

    AI Productivity Tools

    AI Coding Assistants

    UI/UX Tools

    ThemeBuilder Design System Kit Templates and Building Blocks

    Debugging

    Fiddler Fiddler Everywhere Fiddler Classic Fiddler Everywhere Reporter FiddlerCore

    Free Tools

    KendoReact Free VB.NET to C# Converter Testing Framework
    View all products
  • Overview
    • What's New
    • Roadmap
    • Release History
  • Docs & Support
  • Pricing
  • Shopping cart
    • Account Overview
    • Your Licenses
    • Downloads
    • Support Center
    • Forum Profile
    • Payment Methods
    • Edit Profile
    • Log out
  • Login
  • Contact Us
  • Try now

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
System.Object
Telerik.JustMock.AutoMock.Ninject.Infrastructure.Disposal.DisposableObject
Telerik.JustMock.AutoMock.Ninject.Syntax.BindingRoot
Telerik.JustMock.AutoMock.Ninject.KernelBase
Telerik.JustMock.AutoMock.Ninject.StandardKernel
MockingContainer<T>
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
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
Telerik.JustMock.AutoMock.Ninject.StandardKernel.AddComponents()

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

Overrides
Telerik.JustMock.AutoMock.Ninject.StandardKernel.ShouldAddComponent(System.Type, System.Type)

Extension Methods

FluentHelper.Arrange<T, TResult>(T, Expression<Func<T, TResult>>)
FluentHelper.Arrange<T>(T, Expression<Action<T>>)
FluentHelper.ArrangeSet<T>(T, Action<T>)
FluentHelper.ArrangeLike<T>(T, Expression<Func<T, Boolean>>)
FluentHelper.Assert<T, TReturn>(T, Expression<Func<T, TReturn>>, String)
FluentHelper.Assert<T, TReturn>(T, Expression<Func<T, TReturn>>, Occurs, String)
FluentHelper.Assert<T>(T, Expression<Action<T>>, String)
FluentHelper.Assert<T>(T, Expression<Action<T>>, Occurs, String)
FluentHelper.AssertSet<T>(T, Action<T>, String)
FluentHelper.AssertSet<T>(T, Action<T>, Occurs, String)
FluentHelper.Raise<T>(T, Action<T>, EventArgs)
FluentHelper.Raise<T>(T, Action<T>, Object[])
FluentHelper.Assert<T>(T, String)
FluentHelper.AssertAll<T>(T, String)
Getting Started
  • Unit Testing and Mocking Explained
  • Videos
  • FAQs
Community
  • Forums
  • Blogs
  • Feedback Portal

Copyright © 2019 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.

Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.