Search Results for

    Show / Hide Table of Contents

    Class Factory

    a factory for instantiating endpoints/event/mappers/validators/etc. for testing purposes

    Inheritance
    object
    Factory
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: FastEndpoints
    Assembly: FastEndpoints.dll
    Syntax
    public static class Factory

    Methods

    AddServicesForUnitTesting(IServiceCollection)

    adds the minimum required set of services for unit testing FE endpoints

    Declaration
    public static IServiceCollection AddServicesForUnitTesting(this IServiceCollection services)
    Parameters
    Type Name Description
    IServiceCollection services
    Returns
    Type Description
    IServiceCollection

    AddTestServices(HttpContext, Action<IServiceCollection>)

    register fake/mock/test services for the http context. typically only used with unit tests with the Factory.Create() method/>

    Declaration
    public static void AddTestServices(this HttpContext ctx, Action<IServiceCollection> s)
    Parameters
    Type Name Description
    HttpContext ctx
    Action<IServiceCollection> s

    an action for adding services to the IServiceCollection

    Exceptions
    Type Condition
    InvalidOperationException

    thrown if the RequestServices is not empty

    CreateEvent<TEvent>(IEnumerable<IEventHandler<TEvent>>, Action<IServiceCollection>?)

    get an instance of an event suitable for unit testing.

    Declaration
    public static TEvent CreateEvent<TEvent>(IEnumerable<IEventHandler<TEvent>> handlers, Action<IServiceCollection>? s = null) where TEvent : class, IEvent
    Parameters
    Type Name Description
    IEnumerable<IEventHandler<TEvent>> handlers

    the fake/mock event handlers to register for this event

    Action<IServiceCollection> s

    an optional action for adding services to the IServiceCollection

    Returns
    Type Description
    TEvent
    Type Parameters
    Name Description
    TEvent

    the type of the event

    CreateMapper<TMapper>(Action<IServiceCollection>)

    get an instance of a mapper that uses Resolve<T>() methods to obtain services registered in the DI container.

    Declaration
    public static TMapper CreateMapper<TMapper>(Action<IServiceCollection> s) where TMapper : class, IMapper
    Parameters
    Type Name Description
    Action<IServiceCollection> s

    an action for adding services to the IServiceCollection

    Returns
    Type Description
    TMapper
    Type Parameters
    Name Description
    TMapper

    the type of the mapper

    CreateValidator<TValidator>(Action<IServiceCollection>)

    get an instance of a validator that uses Resolve<T>() methods to obtain services registered in the DI container.

    Declaration
    public static TValidator CreateValidator<TValidator>(Action<IServiceCollection> s) where TValidator : class, IValidator
    Parameters
    Type Name Description
    Action<IServiceCollection> s

    an action for adding services to the IServiceCollection

    Returns
    Type Description
    TValidator
    Type Parameters
    Name Description
    TValidator

    the type of the validator

    Create<TEndpoint>(DefaultHttpContext, params object?[])

    get an instance of an endpoint suitable for unit testing

    Declaration
    public static TEndpoint Create<TEndpoint>(DefaultHttpContext httpContext, params object?[] ctorDependencies) where TEndpoint : class, IEndpoint
    Parameters
    Type Name Description
    DefaultHttpContext httpContext

    a default http context object

    object[] ctorDependencies

    the dependencies of the endpoint if it has any constructor injected dependencies

    Returns
    Type Description
    TEndpoint
    Type Parameters
    Name Description
    TEndpoint

    the type of the endpoint to create an instance of

    Create<TEndpoint>(Action<DefaultHttpContext>, params object?[])

    get an instance of an endpoint suitable for unit testing

    Declaration
    public static TEndpoint Create<TEndpoint>(Action<DefaultHttpContext> httpContext, params object?[] ctorDependencies) where TEndpoint : class, IEndpoint
    Parameters
    Type Name Description
    Action<DefaultHttpContext> httpContext

    an action for configuring the default http context object

    object[] ctorDependencies

    the dependencies of the endpoint if it has any constructor injected arguments

    Returns
    Type Description
    TEndpoint
    Type Parameters
    Name Description
    TEndpoint

    the type of the endpoint to create an instance of

    Create<TEndpoint>(params object?[])

    get an instance of an endpoint suitable for unit testing

    Declaration
    public static TEndpoint Create<TEndpoint>(params object?[] ctorDependencies) where TEndpoint : class, IEndpoint
    Parameters
    Type Name Description
    object[] ctorDependencies

    the dependencies of the endpoint if it has any constructor injected dependencies

    Returns
    Type Description
    TEndpoint
    Type Parameters
    Name Description
    TEndpoint

    the type of the endpoint to create an instance of

    RegisterTestServices(Action<IServiceCollection>)

    register fake/mock/test services for the current test execution context.

    Declaration
    public static void RegisterTestServices(Action<IServiceCollection> s)
    Parameters
    Type Name Description
    Action<IServiceCollection> s

    an action for adding services to the IServiceCollection

    In this article
    Back to top Developed by Đĵ ΝιΓΞΗΛψΚ and contributors / Licensed under MIT / Website generated by DocFX