Esempio n. 1
0
        public TestContext CreateBuilderContextFactoryByDiConfigGlobalDefault()
        {
            IServiceCollection service = new ServiceCollection();

            service.AddDataContextFactory <TestContextFactory, TestContext>(DataContextConfiguration.Global, config =>
            {
                config.SetCommandOutput(commandOutput);
            }, ServiceLifetime.Transient);
            var provider = service.BuildServiceProvider();
            TestContextFactory contextFactory = provider.GetRequiredService <TestContextFactory>();
            TestContext        context        = contextFactory.CreateDataContext();

            return(context);
        }
Esempio n. 2
0
        public TestContext CreateBuilderContextFactoryByConfigFile()
        {
            IServiceCollection service = new ServiceCollection();

            service.AddDataContextFactory <TestContextFactory, TestContext>("lightdata2.json", config =>
            {
                config.ConfigName = "mysql2";
                config.SetCommandOutput(commandOutput);
            }, ServiceLifetime.Transient);
            var provider = service.BuildServiceProvider();
            TestContextFactory contextFactory = provider.GetRequiredService <TestContextFactory>();
            TestContext        context        = contextFactory.CreateDataContext();

            return(context);
        }
Esempio n. 3
0
        public TestContext CreateBuilderContextFactoryByDiConfigSpecifiedDefault()
        {
            var builder = new ConfigurationBuilder();

            builder.AddJsonFile("appsettings.json");
            var configuration = builder.Build();

            IServiceCollection service = new ServiceCollection();

            service.AddDataContextFactory <TestContextFactory, TestContext>(configuration.GetSection("lightData"), config =>
            {
                config.SetCommandOutput(commandOutput);
            }, ServiceLifetime.Transient);
            var provider = service.BuildServiceProvider();
            TestContextFactory factory = provider.GetRequiredService <TestContextFactory>();
            TestContext        context = factory.CreateDataContext();

            return(context);
        }
Esempio n. 4
0
        public TestContext CreateBuilderContextFactoryByDi()
        {
            IServiceCollection service = new ServiceCollection();

            service.AddDataContextFactory <TestContextFactory, TestContext>(builder =>
            {
                builder.UseMysql("server=mysql_test;Port=3306;User Id=root;password=1qazxsw23edC;database=LightData_Test;Allow Zero Datetime=True;charset=utf8;Min Pool Size=1;Max Pool Size=5;SslMode=None;");
                builder.SetCommandOutput(commandOutput);
                builder.SetTimeout(2000);
                builder.SetBatchInsertCount(10);
                builder.SetBatchUpdateCount(10);
                builder.SetBatchDeleteCount(10);
            }, ServiceLifetime.Transient);
            var provider = service.BuildServiceProvider();
            TestContextFactory factory = provider.GetRequiredService <TestContextFactory>();
            TestContext        context = factory.CreateDataContext();

            return(context);
        }