Exemple #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);
        }
Exemple #2
0
        public TestContext CreateBuilderContextFactoryByConfigFile()
        {
            IServiceCollection service = new ServiceCollection();

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

            return(context);
        }
Exemple #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);
        }
Exemple #4
0
        public TestContext CreateBuilderContextFactoryByDi()
        {
            IServiceCollection service = new ServiceCollection();

            service.AddDataContextFactory <TestContextFactory, TestContext>(builder =>
            {
                builder.UseMssql("Data Source=mssql_test;User ID=sa;Password=1qazxsw23edC;Initial Catalog=LightData_Test;");
                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);
        }