/// <summary> /// Configures a mock of the specified type to setup a call matching the specified expression to return the specified result. /// </summary> /// <typeparam name="TService">The type of the service.</typeparam> /// <typeparam name="TResult">The type of the result.</typeparam> /// <param name="fixture">The fixture.</param> /// <param name="expression">The expression.</param> /// <param name="result">The result.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public static ITestFixture HavingMockedAsync <TService, TResult>( this ITestFixture fixture, Expression <Func <TService, Task <TResult> > > expression, TResult result, params Parameter[] parameters) where TService : class => fixture.HavingMock <TService>(m => m.Setup(expression).ReturnsAsync(result).Verifiable(), parameters);
/// <summary> /// Configures a mock of the specified type to setup a call matching the specified expression to throw the specified exception. /// </summary> /// <typeparam name="TService">The type of the service.</typeparam> /// <param name="fixture">The fixture.</param> /// <param name="expression">The expression.</param> /// <param name="exception">The exception.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public static ITestFixture HavingMockThrow <TService>( this ITestFixture fixture, Expression <Action <TService> > expression, Exception exception, params Parameter[] parameters) where TService : class => fixture.HavingMock <TService>(m => m.Setup(expression).Throws(exception).Verifiable(), parameters);
/// <summary> /// Gets a mocked object of the specified type /// </summary> /// <typeparam name="TService">The type of the service.</typeparam> /// <param name="fixture">The fixture.</param> /// <param name="service">The service.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public static ITestFixture HavingMock <TService>( this ITestFixture fixture, out TService service, params Parameter[] parameters) where TService : class => fixture.HavingMock(_ => {}, out service, parameters);
/// <summary> /// Configures a mock of the specified type. /// </summary> /// <typeparam name="TService">The type of the service.</typeparam> /// <param name="fixture">The fixture.</param> /// <param name="mockAction">The mock action.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public static ITestFixture HavingMock <TService>( this ITestFixture fixture, Action <Mock <TService> > mockAction, params Parameter[] parameters) where TService : class => fixture.HavingMock(mockAction, out _, parameters);
/// <summary> /// Configures a mock of the specified type to setup a call matching the specified expression to return a completed task. /// </summary> /// <typeparam name="TService">The type of the service.</typeparam> /// <param name="fixture">The fixture.</param> /// <param name="expression">The expression.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> public static ITestFixture HavingMockedAsync <TService>( this ITestFixture fixture, Expression <Func <TService, Task> > expression, params Parameter[] parameters) where TService : class => fixture.HavingMock <TService>(m => m.Setup(expression).Returns(Task.CompletedTask).Verifiable(), parameters);