public void Tracking()
        {
            using var scop = RootServiceProvider.CreateScope();
            var db = scop.ServiceProvider.GetService <IDbAccessor>();

            db.Insert(_insertList);

            var data = db.GetIQueryable <Base_UnitTest>(true).FirstOrDefault();

            data.Age = 10000;
            db.SaveChanges();

            var newData = db.GetIQueryable <Base_UnitTest>(true).FirstOrDefault();

            Assert.AreEqual(data.ToJson(), newData.ToJson());
        }
Exemple #2
0
        protected IntegratedTest()
        {
            var services = CreateServiceCollection();

            BeforeAddApplication(services);

            var application = services.AddApplication <TStartupModule>();

            Application = services.GetService <IModuleApplication>();

            AfterAddApplication(services);

            RootServiceProvider = CreateServiceProvider(services);
            TestServiceScope    = RootServiceProvider.CreateScope();
            ((StartupModuleRunner)Application).Initialize(TestServiceScope.ServiceProvider);
        }
Exemple #3
0
        protected AbpIntegratedTest()
        {
            var services = CreateServiceCollection();

            BeforeAddApplication(services);

            var application = services.AddApplication <TStartupModule>(SetAbpApplicationCreationOptions);

            Application = application;

            AfterAddApplication(services);

            RootServiceProvider = CreateServiceProvider(services);
            TestServiceScope    = RootServiceProvider.CreateScope();

            application.Initialize(TestServiceScope.ServiceProvider);
        }
Exemple #4
0
        protected IntegratedTest()
        {
            var services = CreateServiceCollection();

            BeforeAddBootstrapper(services);

            var bootstrapper = new InternalBootstrapper(typeof(TStartupModule), services, null, SetBootstrapperCreationOptions);

            Bootstrapper = bootstrapper;

            AfterAddBootstrapper(services);

            RootServiceProvider = CreateServiceProvider(services);
            TestServiceScope    = RootServiceProvider.CreateScope();
            bootstrapper.SetServiceProvider(TestServiceScope.ServiceProvider);
            bootstrapper.Initialize();
        }
Exemple #5
0
        protected IntegratedTest()
        {
            var services = CreateServiceCollection();

            BeforeAddBootstrapper(services);

            var bootstrapper = CreateBootstrapper(services);

            Bootstrapper = bootstrapper;

            AfterAddBootstrapper(services);

            RootServiceProvider = CreateServiceProvider(bootstrapper);
            TestServiceScope    = RootServiceProvider.CreateScope();
            bootstrapper.SetServiceProvider(TestServiceScope.ServiceProvider);
            bootstrapper.Initialize();
        }
    public virtual async Task InitializeAsync()
    {
        var services = await CreateServiceCollectionAsync();

        await BeforeAddApplicationAsync(services);

        var application = await services.AddApplicationAsync <TStartupModule>(await SetAbpApplicationCreationOptionsAsync());

        await AfterAddApplicationAsync(services);

        RootServiceProvider = await CreateServiceProviderAsync(services);

        TestServiceScope = RootServiceProvider.CreateScope();
        await application.InitializeAsync(TestServiceScope.ServiceProvider);

        ServiceProvider = application.ServiceProvider;
        Application     = application;

        await InitializeServicesAsync();
    }
        protected MongoDbTestBase()
        {
            var services = CreateServiceCollection();

            services.AddLogging();
            services.AddMongoDbService();

            services.Configure <MongoDbConnectStringOption>(option => option.MongoDbServer = "mongodb://localhost:27017");

            services.AddSingleton <ITestMongoDbContext, TestMongoDbContext>();

            RegisterRepository(services);

            Services = services;

            RootServiceProvider = CreateServiceProvider(services);

            LoggerFactory = RootServiceProvider.GetService <ILoggerFactory>() !;

            LoggerFactory.AddProvider(new MongoDbLoggerProvider(RootServiceProvider.GetService <IMongoDbLogRepository>() !));
        }
Exemple #8
0
        public static void Initialize(TestContext testContext)
        {
            IPrincipal         genericPrincipal;
            ServiceProvider    serviceProvider;
            ApplicationContext context;

            // Initialise DI
            var services = new ServiceCollection();

            // Add Csla
            services.AddCsla();
            serviceProvider = services.BuildServiceProvider();

            // Initialise CSLA security
            context          = serviceProvider.GetRequiredService <ApplicationContext>();
            genericPrincipal = new GenericPrincipal(new GenericIdentity("Fred"), new string[] { "Users" });
            context.User     = genericPrincipal;

            // Set up the workaround for accessing DI from tests
            RootServiceProvider.SetServiceProvider(serviceProvider);
        }
Exemple #9
0
        public static void Begin(TestContext context)
        {
            ServiceCollection services = new ServiceCollection();

            services.AddEFCoreSharding(config =>
            {
                config.UseDatabase(Config.CONSTRING1, DatabaseType.SqlServer);
                config.UseDatabase <ISQLiteDb1>(Config.SQLITE1, DatabaseType.SQLite);
                config.UseDatabase <ISQLiteDb2>(Config.SQLITE2, DatabaseType.SQLite);
                config.UseDatabase <ICustomDbAccessor>(Config.CONSTRING1, DatabaseType.SqlServer);

                //分表配置
                //添加数据源
                config.AddDataSource(Config.CONSTRING1, ReadWriteType.Read | ReadWriteType.Write, DatabaseType.SqlServer);
                //设置分表规则
                config.SetHashModSharding <Base_UnitTest>(nameof(Base_UnitTest.Id), 3);
            });

            RootServiceProvider = services.BuildServiceProvider();
            ServiceScopeFactory = RootServiceProvider.GetService <IServiceScopeFactory>();
        }
Exemple #10
0
 protected BaseTest()
 {
     CurrentServiceScope    = RootServiceProvider.CreateScope();
     CurrentServiceProvider = CurrentServiceScope.ServiceProvider;
 }
Exemple #11
0
 public MongoDbTest() : base()
 {
     _cityRepository = RootServiceProvider.GetService <ICityRepository>() !;
     Logger          = NullLogger <MongoDbTest> .Instance;
 }
 public override void OnInitialized()
 {
     _navigationManager = RootServiceProvider.GetRequiredService <NavigationManager>();
 }
Exemple #13
0
 public IServiceProvider CreateScopedServiceProvider()
 {
     return(RootServiceProvider.CreateScope().ServiceProvider);
 }
Exemple #14
0
        public void DistributedTransaction()
        {
            //失败事务
            var db1 = RootServiceProvider.GetService <ISQLiteDb1>();
            var db2 = RootServiceProvider.GetService <ISQLiteDb2>();

            db1.DeleteAll <Base_UnitTest>();
            db2.DeleteAll <Base_UnitTest>();
            Base_UnitTest data1 = new Base_UnitTest
            {
                Id       = Guid.NewGuid().ToString(),
                UserId   = "1",
                UserName = Guid.NewGuid().ToString()
            };
            Base_UnitTest data2 = new Base_UnitTest
            {
                Id       = data1.Id,
                UserId   = "1",
                UserName = Guid.NewGuid().ToString()
            };
            Base_UnitTest data3 = new Base_UnitTest
            {
                Id       = Guid.NewGuid().ToString(),
                UserId   = "2",
                UserName = Guid.NewGuid().ToString()
            };

            new Action(() =>
            {
                var transaction = DistributedTransactionFactory.GetDistributedTransaction();
                transaction.AddDbAccessor(db1, db2);
                var succcess = transaction.RunTransaction(() =>
                {
                    db1.ExecuteSql("insert into Base_UnitTest(Id,CreateTime) values('10',@CreateTime) ", ("@CreateTime", DateTime.Now));
                    db1.Insert(data1);
                    db1.Insert(data2);
                    db2.Insert(data1);
                    db2.Insert(data3);
                });
                Assert.IsFalse(succcess.Success);
                Assert.AreEqual(0, db1.GetIQueryable <Base_UnitTest>().Count());
                Assert.AreEqual(0, db2.GetIQueryable <Base_UnitTest>().Count());
            })();

            //成功事务
            new Action(() =>
            {
                var transaction = DistributedTransactionFactory.GetDistributedTransaction();
                transaction.AddDbAccessor(db1, db2);

                var succcess = transaction
                               .RunTransaction(() =>
                {
                    db1.ExecuteSql("insert into Base_UnitTest(Id,CreateTime) values('10',@CreateTime) ", ("@CreateTime", DateTime.Now));
                    db1.Insert(data1);
                    db1.Insert(data3);
                    db2.Insert(data1);
                    db2.Insert(data3);
                });
                int count1 = db1.GetIQueryable <Base_UnitTest>().Count();
                int count2 = db2.GetIQueryable <Base_UnitTest>().Count();
                Assert.IsTrue(succcess.Success);
                Assert.AreEqual(3, count1);
                Assert.AreEqual(2, count2);
            })();
        }
 protected BaseTest()
 {
     ServiceScope    = RootServiceProvider.CreateScope();
     ServiceProvider = ServiceScope.ServiceProvider;
 }