MockerTestBase<(Of <(<'TComponent>)>)> Class

Mock Test Base with Automatic Mocking using Mocker. This class contains the Mocks property to create and track all Mocks from creation of the component.

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

Syntax


public abstract class MockerTestBase<TComponent>
Public MustInherit Class MockerTestBase(Of TComponent)
generic<typename TComponent>
public ref class MockerTestBase abstract

Type Parameters

TComponent
The type of the t component.

Examples


Test example of the base class creating the Car class and auto mocking ICarService. Start by creating the test class that inherits MockerTestBase<(Of <(<'TComponent>)>)>. The object that is passed is the concrete class being tested. Use Component Property to access the test object.
C#
public class CarTest : MockerTestBase<Car> {      public void TestCar() {          Component.CarService.Should().NotBeNull();      } }
ICarService is automatically injected into the Car object when created by the base class.
C#
public partial class Car {      public Car(ICarService carService) => CarService = carService; }
When needing to set up mocks before the component is created, use the [get_SetupMocksAction] property or the base class constructor. This example shows creating a database context and adding it to the Type Map for resolution during creation of objects.
C#
protected override Action<Mocker> SetupMocksAction => mocker =>     mocker.AddType(_ => mocker.GetMockDbContext<ApplicationDbContext>().Object);

Inheritance Hierarchy


Object
  FastMoq..::..MockerTestBase<(Of <(<'TComponent>)>)>