Ejemplo n.º 1
0
 public RServiceMiddleware(RequestDelegate next, ILoggerFactory logFactory, RService service,
                           IServiceProvider serviceProvider, IOptions <RServiceOptions> options)
 {
     _next            = next;
     _logger          = logFactory.CreateLogger <RServiceMiddleware>();
     _service         = service;
     _serviceProvider = serviceProvider;
     _options         = options.Value;
 }
Ejemplo n.º 2
0
        private RServiceMiddleware BuildMiddleware(TestSink sink, string routePath = null, Delegate.Activator routeActivator  = null,
                                                   RequestDelegate handler         = null, IOptions <RServiceOptions> options = null, IServiceProvider serviceProvider = null,
                                                   IService service = null)
        {
            options = options ?? _options;

            var loggerFactory = new TestLoggerFactory(sink, true);
            var next          = handler ?? (c => Task.FromResult <object>(null));
            var rservice      = new RService(options);

            if (serviceProvider == null)
            {
                var mockServiceProvider = new Mock <IServiceProvider>().SetupAllProperties();
                mockServiceProvider.Setup(x => x.Invoke(It.IsAny <HttpContext>()))
                .Returns(Task.FromResult(0));

                serviceProvider = mockServiceProvider.Object;
            }

            if (!routePath.IsNullOrEmpty() && routeActivator != null)
            {
                rservice.Routes.Add(routePath, new ServiceDef
                {
                    ServiceMethod = routeActivator,
                    ServiceType   = service?.GetType() ?? typeof(IService)
                });
            }

            return(new RServiceMiddleware(next, loggerFactory, rservice, serviceProvider, options));
        }