Mocker Class

Initializes the mocking helper object. This class creates and manages the automatic mocking and custom mocking.

Namespace:  FastMoq
Assembly:  FastMoq.Core (in FastMoq.Core.dll)

Syntax


public class Mocker
Public Class Mocker
public ref class Mocker

Remarks


This class is used inside MockerTestBase<(Of <(<'TComponent>)>)>. This may be used independently; however, to ensure that mocks are not duplicated, use only one instance of this class. If using MockerTestBase<(Of <(<'TComponent>)>)>, use the Mocks property or create this class for a specific test only.

Examples


C#
// Arrange
var id = 1234;
var blogsTestData = new List<Blog> { new Blog { Id = id } };

// Create a mock DbContext
var mocker = new Mocker(); // Create a new mocker only if not already using MockerTestBase; otherwise use Mocks included in the base class.

var dbContextMock = mocker.GetMockDbContext<ApplicationDbContext>();
var dbContext = dbContextMock.Object;
dbContext.Blogs.Add(blogsTestData); // Can also be dbContext.Set<Blog>().Add(blogsTestData)

var validator = new BtnValidator(dbContext);

// Act
var result = validator.IsValid(id);

// Assert
Assert.True(result);

Inheritance Hierarchy


Object
  FastMoq..::..Mocker