public BaseUnitTest() { ServiceCollection = new ServiceCollection(); #region ConfigurationBuilder var builder = new ConfigurationBuilder() .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) .AddJsonFile("Config/appsettings.json", optional: true, reloadOnChange: true); Configuration = builder.Build(); #endregion ServiceCollection.Configure <WorkDataBaseJwt>(Configuration.GetSection("WorkDataBaseJwt")); ServiceCollection.Configure <WorkDataDbContextOptions>(Configuration.GetSection("WorkDataDbContextOptions")); #region Autofac var paths = new List <string> { "Config/moduleConfig.json" }; BootstrapWarpper.InitiateConfig(ServiceCollection, paths); #endregion }
/// <summary> /// ConfigureServices /// </summary> /// <param name="services"></param> /// <returns></returns> public IServiceProvider ConfigureServices(IServiceCollection services) { services.Configure <WorkDataBaseJwt>(Configuration.GetSection("WorkDataBaseJwt")); services.Configure <WorkDataDbConfig>(Configuration.GetSection("WorkDataDbContextConfig")); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddTransient <IPrincipal>(provider => provider.GetService <IHttpContextAccessor>().HttpContext.User); var workDataBaseJwt = services.ResolveServiceValue <WorkDataBaseJwt>(); #region WebUowFilter services.AddMvc(options => { options.Filters.Add(typeof(WebUowFilter)); options.Filters.Add(typeof(WorkDataExpectionFilter)); }); #endregion #region JWT services.AddAuthentication(options => { //认证middleware配置 options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(o => { //主要是jwt token参数设置 o.TokenValidationParameters = new TokenValidationParameters { //Token颁发机构 ValidIssuer = workDataBaseJwt.Issuer, //颁发给谁 ValidAudience = workDataBaseJwt.Audience, //这里的key要进行加密,需要引用Microsoft.IdentityModel.Tokens IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(workDataBaseJwt.SecretKey)), //ValidateIssuerSigningKey=true, ////是否验证Token有效期,使用当前时间与Token的Claims中的NotBefore和Expires对比 ValidateLifetime = true, ////允许的服务器时间偏移量 ClockSkew = TimeSpan.Zero }; }); #endregion #region Autofac var paths = new List <string> { "Config/moduleConfig.json" }; BootstrapWarpper.InitiateConfig(services, paths); #endregion return(new AutofacServiceProvider (BootstrapWarpper.IocManager.IocContainer)); }
private static void Main(string[] args) { #region 初始化 var paths = new List <string> { "Config/moduleConfig.json", "Config/commonConfig.json" }; BootstrapWarpper.InitiateConfig(paths); #endregion 初始化 //初始化service var service = BootstrapWarpper.IocManager.Resolve <IContentService>(); //初始化预置数据 Contents = InitData(); //赋值 //service.BlukIndex(Contents, "content_test"); //复杂查询 var request = new RequestContentDto { PageSize = 5, SearchKey = "赛乐" }; #region 高亮 var highlightConfig = new HighlightConfig <Content> { Tag = "i", HighlightConfigExpression = new List <Expression <Func <Content, object> > > { x => x.Title } }; request.HighlightConfigEntity = highlightConfig; var data = service.Search(request.CurrentIndex, request.PageSize, request); //删除 service.DeleteByQuery("123852"); //更新 service.UpdateByKey("123754", new Content { Key = "123" }); #endregion 高亮 }
public BaseTest() { BootstrapWarpper.Initiate(); ServiceLocator = BootstrapWarpper.IocManager.ServiceLocatorCurrent; FixtureData = new Fixture(); #region 级联对象构建 FixtureData.Behaviors.OfType <ThrowingRecursionBehavior>().ToList() .ForEach(b => FixtureData.Behaviors.Remove(b)); FixtureData.Behaviors.Add(new OmitOnRecursionBehavior()); #endregion }
/// <summary> /// ConfigureServices /// </summary> /// <param name="services"></param> /// <returns></returns> public IServiceProvider ConfigureServices(IServiceCollection services) { services.Configure <WorkDataBaseJwt>(Configuration.GetSection("WorkDataBaseJwt")); services.Configure <WorkDataDbContextOptions>(Configuration.GetSection("WorkDataDbContextOptions")); services.Configure <WechatAppSettings>(Configuration.GetSection("WechatAppSettings")); services.Configure <DynamicFilterConfig>(Configuration.GetSection("DynamicFilterConfig")); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddTransient <IPrincipal>(provider => provider.GetService <IHttpContextAccessor>().HttpContext?.User); services.AddSingleton <ITypeFinder, WebAppTypeFinder>(); #region AutoMapper services.AddWorkDataAutoMapper(); #endregion #region WorkDataContext services.AddWorkDataDbContext <WorkDataContext>("BaseWorkData"); #endregion #region WebUowFilter services.AddMvc(options => { options.Filters.Add(typeof(WebUowFilter)); options.Filters.Add(typeof(WorkDataExpectionFilter)); }); #endregion #region JWT services.AddWorkDataJwt(); #endregion #region Autofac BootstrapWarpper.InitiateConfig(services, new List <string> { "Config/moduleConfig.json" }); #endregion #region 初始化审计 services.InitAuditable(); #endregion services.AddMemoryCache(); //使用本地缓存必须添加 services.AddSession(); //使用Session services.AddSenparcGlobalServices(Configuration) //Senparc.CO2NET 全局注册 .AddSenparcWeixinServices(Configuration); //Senparc.Weixin 注册 return(new AutofacServiceProvider (BootstrapWarpper.IocManager.IocContainer)); }