Exemple #1
0
        public IDatabase CreateDatabase(IMetaPopulation metaPopulation, bool init)
        {
            var configuration = new SqlClient.Configuration
            {
                ObjectFactory     = this.CreateObjectFactory(metaPopulation),
                ConnectionString  = this.ConnectionString,
                ConnectionFactory = this.connectionFactory,
                CacheFactory      = this.cacheFactory,
            };
            var database = new Database(this.ServiceProvider, configuration);

            if (init)
            {
                database.Init();
            }

            return(database);
        }
Exemple #2
0
        protected Test(TestFixture fixture)
        {
            // Init Browser
            this.DriverManager = new DriverManager();
            this.DriverManager.Start();

            // Init Server
            this.Driver.Navigate().GoToUrl(Test.DatabaseInitUrl);

            CultureInfo.CurrentCulture   = new CultureInfo("nl-BE");
            CultureInfo.CurrentUICulture = CultureInfo.CurrentCulture;

            // Init Allors
            var configurationBuilder = new ConfigurationBuilder();

            const string root = "/config/base";

            configurationBuilder.AddCrossPlatform(".");
            configurationBuilder.AddCrossPlatform(root);
            configurationBuilder.AddCrossPlatform(Path.Combine(root, "server"));
            configurationBuilder.AddEnvironmentVariables();

            var configuration = configurationBuilder.Build();

            var services = new ServiceCollection();

            services.AddAllors();
            services.AddSingleton <IConfiguration>(configuration);
            services.AddSingleton <ILoggerFactory, LoggerFactory>();
            services.AddSingleton(typeof(ILogger <>), typeof(Logger <>));
            services.AddLogging(builder => builder.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace));
            services.AddSingleton <Faker>();

            this.ServiceProvider = services.BuildServiceProvider();

            var loggerFactory = this.ServiceProvider.GetService <ILoggerFactory>();

            loggerFactory.AddNLog(new NLogProviderOptions {
                CaptureMessageTemplates = true, CaptureMessageProperties = true
            });
            NLog.LogManager.LoadConfiguration("nlog.config");

            this.Logger = (ILogger)this.ServiceProvider.GetService(typeof(ILogger <>).MakeGenericType(new[] { this.GetType() }));

            var database = new Database(this.ServiceProvider, new Configuration
            {
                ConnectionString = configuration["ConnectionStrings:DefaultConnection"],
                ObjectFactory    = new ObjectFactory(MetaPopulation.Instance, typeof(User)),
            });

            if ((population == null) && populationFileInfo.Exists)
            {
                population = File.ReadAllText(populationFileInfo.FullName);
            }

            if (population != null)
            {
                using (var stringReader = new StringReader(population))
                    using (var reader = XmlReader.Create(stringReader))
                    {
                        database.Load(reader);
                    }
            }
            else
            {
                database.Init();

                using (var session = database.CreateSession())
                {
                    var config = new Config();
                    new Setup(session, config).Apply();
                    session.Commit();

                    new IntranetPopulation(session, null).Execute();

                    session.Commit();

                    using (var stringWriter = new StringWriter())
                    {
                        using (var writer = XmlWriter.Create(stringWriter))
                        {
                            database.Save(writer);
                        }

                        population = stringWriter.ToString();
                        File.WriteAllText(populationFileInfo.FullName, population);
                    }
                }
            }

            this.Session = database.CreateSession();
        }