/// <summary>
 /// 测试初始化
 /// </summary>
 public DCRepositoriesServiceTest()
 {
     _scope = Ioc.BeginScope();
     _dCRepositoriesRepository = _scope.Create <IDCRepositoriesRepository>();
     _dCRepositoriesService    = _scope.Create <IDCRepositoriesService>();
     _dCRepositoriesDto        = DCRepositoriesDtoTest.Create();
 }
Example #2
0
 public void TestScope()
 {
     using (var scope = Ioc.BeginScope()) {
         var sample = scope.Create <ISample>();
         Assert.NotNull(sample);
     }
 }
        public IUnitOfWorkCompleteHandle Begin(UnitOfWorkOptions options)
        {
            _childScope = Ioc.BeginScope();

            options.FillDefaultsForNonProvidedOptions(_defaultOptions);

            IUnitOfWork outerUow = _currentUnitOfWorkProvider.Current;

            if (options.Scope == TransactionScopeOption.Required && outerUow != null)
            {
                return(new InnerUnitOfWorkCompleteHandle());
            }

            var uow = _childScope.Create <IUnitOfWork>();  //AppHelper.GetService<IUnitOfWork>();

            uow.Completed += (sender, args) => { _currentUnitOfWorkProvider.Current = null; };

            uow.Failed += (sender, args) => { _currentUnitOfWorkProvider.Current = null; };

            uow.Disposed += (sender, args) => { _childScope.Dispose(); };

            //Inherit filters from outer UOW
            if (outerUow != null)
            {
                options.FillOuterUowFiltersForNonProvidedOptions(outerUow.Filters.ToList());
            }

            uow.Begin(options);
            _currentUnitOfWorkProvider.Current = uow;
            //    System.Console.WriteLine(uow.GetType().Name);
            return(uow);
        }
Example #4
0
 /// <summary>
 /// 测试初始化
 /// </summary>
 public ProductRepositoryTest()
 {
     _scope             = Ioc.BeginScope();
     _unitOfWork        = _scope.Create <ISqlServerUnitOfWork>();
     _productRepository = _scope.Create <IProductRepository>();
     _random            = new Util.Helpers.Random();
 }
Example #5
0
 /// <summary>
 /// 测试初始化
 /// </summary>
 public SqlQueryTest()
 {
     _scope              = Ioc.BeginScope();
     _unitOfWork         = _scope.Create <ISqlServerUnitOfWork>();
     _customerRepository = _scope.Create <ICustomerRepository>();
     _query              = _scope.Create <ISqlQuery>();
 }
Example #6
0
 /// <summary>
 /// 测试初始化
 /// </summary>
 public UsersServiceTest()
 {
     _scope           = Ioc.BeginScope();
     _usersRepository = _scope.Create <IUsersRepository>();
     _usersService    = _scope.Create <IUsersService>();
     _usersDto        = UsersDtoTest.Create();
 }
Example #7
0
 /// <summary>
 /// 测试初始化
 /// </summary>
 public WHLogsServiceTest()
 {
     _scope            = Ioc.BeginScope();
     _wHLogsRepository = _scope.Create <IWHLogsRepository>();
     _wHLogsService    = _scope.Create <IWHLogsService>();
     _wHLogsDto        = WHLogsDtoTest.Create();
 }
Example #8
0
 /// <summary>
 /// 测试初始化
 /// </summary>
 public WHMiddlewareServiceTest()
 {
     _scope = Ioc.BeginScope();
     _wHMiddlewareRepository = _scope.Create <IWHMiddlewareRepository>();
     _wHMiddlewareService    = _scope.Create <IWHMiddlewareService>();
     _wHMiddlewareDto        = WHMiddlewareDtoTest.Create();
 }
Example #9
0
 /// <summary>
 /// 测试初始化
 /// </summary>
 public SqlQueryTest(ITestOutputHelper output)
 {
     _output             = output;
     _scope              = Ioc.BeginScope();
     _unitOfWork         = _scope.Create <ISqlServerUnitOfWork>();
     _customerRepository = _scope.Create <ICustomerRepository>();
     _query              = _scope.Create <ISqlQuery>();
 }
Example #10
0
 /// <summary>
 /// 测试初始化
 /// </summary>
 public SqlQueryTest(ITestOutputHelper output)
 {
     _output             = output;
     _scope              = Ioc.BeginScope();
     _unitOfWork         = _scope.Create <ISqlServerUnitOfWork>();
     _customerRepository = _scope.Create <ICustomerRepository>();
     _query              = _scope.Create <ISqlQuery>();
     _query.Config(t => t.IsClearAfterExecution = false);
 }
Example #11
0
        public void TestOrderSync()
        {
            var tenantName = "tenant2";

            using (var scope = Ioc.BeginScope())
            {
                //switch database
                //TenantContext.SwitchDatabase(scope, tenantName);
                //new ProductSyncService(scope).ProductDataSync();
            }

            //var webService = new OrderWebService(Ioc.BeginScope());
            //webService.SyncOrdersFromPlatform();
            //webService.SyncOrdersToPlatform();
        }
Example #12
0
 /// <summary>
 ///     执行
 /// </summary>
 /// <param name="context">执行上下文</param>
 public async Task Execute(Qz.IJobExecutionContext context)
 {
     using (var scope = Ioc.BeginScope()) {
         try {
             //get tenant and switch
             var jobDataMap = context.JobDetail.JobDataMap;
             var tenantName = jobDataMap.GetString(nameof(Tenant));
             if (!string.IsNullOrWhiteSpace(tenantName))
             {
                 TenantContext.SwitchDatabase(scope, tenantName);
             }
             //execute
             await Execute(context, scope);
         } catch (Exception ex) {
             var type = context.JobInstance;
             ExceptionLogs.Write(ex, type.GetType().Name);
         }
     }
 }
Example #13
0
 /// <summary>
 /// 执行
 /// </summary>
 /// <param name="context">执行上下文</param>
 public async Task Execute(IJobExecutionContext context)
 {
     using (var scope = Ioc.BeginScope()) {
         await Execute(context, scope);
     }
 }