Exemple #1
0
        static void Main(string[] args)
        {
            AppServer.Run(AppConfig.Default, () =>
            {
                //Config config = AppConfig.Load<Config>();
                AppLogger.Info("Server Start.");

                #region 调试模式下给Swagger附加参数

                //SwaggerAttachParams.Add("appId", "header");  //TODO

                #endregion

                //使用OwinContext 中间件

                MiddlewareExtensions.Use(app => { app.Use <OwinContextMiddleware>(); });

                //允许JSON输出驼峰格式化
                //JsonConfig.SetCamelCase(true);
                //OwinContext.Current.Request.Accept = "text/html, application/xhtml+xml, */*";
                //注入 //TODO
                //AutofacConfig.Builder.Register<string>(c =>
                //{
                //    return OwinContext.Current.Request.Headers.Get("appId") ?? string.Empty;
                //}).As<string>().InstancePerRequest();


                //AutofacConfig.Builder.RegisterType(typeof(Logger)).SingleInstance();
            }, () =>
            {
                AppLogger.Info("Server Stop.");
            });
        }
Exemple #2
0
        public static IApplicationBuilder UseHangfireDashboard(
            [NotNull] this IApplicationBuilder builder,
            [NotNull] string pathMatch,
            [NotNull] DashboardOptions options,
            [NotNull] JobStorage storage)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (pathMatch == null)
            {
                throw new ArgumentNullException(nameof(pathMatch));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }

            return(builder.Map(pathMatch, subApp =>
            {
                subApp.UseOwin(next =>
                {
                    next(MiddlewareExtensions.UseHangfireDashboard(options, storage, DashboardRoutes.Routes));
                });
            }));
        }
        public void GivenBadPatternWhenMapPowerToolsEFCoreBasedCalledThenShouldThrowArgument(
            string pattern)
        {
            IEndpointRouteBuilder builder = null;

            CreateSimpleServer(config => builder = config);
            Assert.Throws <ArgumentException>(
                () => MiddlewareExtensions.MapPowerToolsEFCore(
                    builder,
                    RoutePatternFactory.Parse(pattern),
                    defaultTypes));
        }
        public void GivenBadDbContextTypesWhenMapPowerToolsEFCoreBaseCalledThenShouldThrowArgument(
            Type[] dbContextTypes)
        {
            IEndpointRouteBuilder builder = null;

            CreateSimpleServer(config => builder = config);

            Assert.Throws <ArgumentException>(
                () => MiddlewareExtensions.MapPowerToolsEFCore(
                    builder,
                    routePattern,
                    dbContextTypes));
        }
Exemple #5
0
        public void ToDelegate()
        {
            Func <Dummy, DummyResult> middlewareResult = _ => new DummyResult();
            var middleware = new SpyMiddleware(middlewareResult);
            Func <Dummy, DummyResult> next = _ => new DummyResult();

            new TestCaseRunner()
            .Run(() => MiddlewareExtensions.ToDelegate(middleware)(next))
            .Verify((actual, desc) => {
                Assert.AreEqual(middlewareResult, actual, desc);

                Assert.AreEqual(next, middleware.ActualNext, desc);
            }, (Type)null);
        }
Exemple #6
0
        public MessageHandlerMiddleware(IHandlerFactory factory)
        {
            CreateHandler = MiddlewareExtensions.Lambda <Type, IHandlerInstance>((execution) => factory.Create(execution.Context));

            BeginHandle = MiddlewareExtensions.Lamda <HandlerContext>();

            ActualHandle = new DynamicMessageHandle();

            EndHandle = MiddlewareExtensions.Lamda <HandlerContext>();

            Error = MiddlewareExtensions.Lamda <ErrorContext>();

            Finalize = MiddlewareExtensions.Lamda <HandleContext>();
        }
        public void GivenNullInputsWhenMapPowerToolsEFCoreBaseCalledThenShouldThrowArgumentNull(
            bool useEndPointRouteBuilder,
            RoutePattern pattern,
            Type[] contextTypes)
        {
            IEndpointRouteBuilder builder = null;

            if (useEndPointRouteBuilder)
            {
                CreateSimpleServer(config => builder = config);
            }

            Assert.Throws <ArgumentNullException>(
                () => MiddlewareExtensions.MapPowerToolsEFCore(
                    builder,
                    pattern,
                    contextTypes));
        }
Exemple #8
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseExceptionHandler(async context => await MiddlewareExtensions.HandleExceptionAsync(context));

            app.UseStaticFiles();

            app.UseRouting();
            app.UseCors("default");
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Post}/{action=Index}/{id?}");
            });
        }
Exemple #9
0
 public void ToDelegate_Null()
 {
     new TestCaseRunner()
     .Run(() => MiddlewareExtensions.ToDelegate((SpyMiddleware)null))
     .Verify((actual, desc) => { }, typeof(ArgumentNullException));
 }