// [Fact] public void Create_Middleware_From_Class_That_Implements_IRequestMiddleware() { RequestCoreMiddleware middleware = RequestClassMiddlewareFactory.Create <CustomMiddlewareThatImplementsInterface>(); var contextMock = new Mock <IRequestContext>(); //middleware.Invoke(c => default(ValueTask)).Invoke(contextMock.Object); }
public async Task Create_CoreMiddleware_InjectOptimizers() { // arrange RequestCoreMiddleware middleware = RequestClassMiddlewareFactory .Create <StubMiddleware <IEnumerable <ISelectionOptimizer> > >(); var applicationServices = new ServiceCollection().BuildServiceProvider(); ServiceProvider schemaServices = new ServiceCollection() .AddSingleton <ISelectionOptimizer, StubOptimizer>() .BuildServiceProvider(); var schemaName = "_Default"; IRequestExecutorOptionsAccessor optionsAccessor = new RequestExecutorOptions(); var factoryContext = new RequestCoreMiddlewareContext( schemaName, applicationServices, schemaServices, optionsAccessor); var context = new RequestContext( new Mock <ISchema>().Object, new Mock <IServiceProvider>().Object, new Mock <IErrorHandler>().Object, new Mock <ITypeConverter>().Object, new Mock <IActivator>().Object, new Mock <IDiagnosticEvents>().Object, new Mock <IQueryRequest>().Object); // act RequestDelegate compiledMiddleware = middleware(factoryContext, context => default); await compiledMiddleware(context); // assert Assert.Single( (context.ContextData["result"] as IEnumerable <ISelectionOptimizer>) !); }
/// <summary> /// Adds a delegate that will be used to create a middleware for the execution pipeline. /// </summary> /// <param name="builder">The <see cref="IRequestExecutorBuilder"/>.</param> /// <param name="middleware">A delegate that is used to create a middleware for the execution pipeline.</param> /// <returns>An <see cref="IRequestExecutorBuilder"/> that can be used to configure a schema and its execution.</returns> public static IRequestExecutorBuilder UseRequest( this IRequestExecutorBuilder builder, RequestCoreMiddleware middleware) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (middleware is null) { throw new ArgumentNullException(nameof(middleware)); } return(Configure( builder, options => options.Pipeline.Add(middleware))); }