예제 #1
0
        public void ConfigureTest(CSContext context, string connection)
        {
            // create database
            var dbExisted = context.Database.EnsureCreated();

            // create postgis extension
            context.Database.ExecuteSqlCommand("create extension if not exists postgis");

            // Reload type for npgsql
            using (NpgsqlConnection conn = new NpgsqlConnection(connection))
            {
                conn.Open();
                conn.ReloadTypes();
                conn.Close();
            }

            if (!dbExisted)
            {
                _configureNHibernate(connection);

                context.Database.ExecuteSqlCommand("INSERT INTO public.__connection(id, name, username, password, databasename, isdefault, state) VALUES (1, 'localhost', 'postgres', 'EAAAAI7FtR5YKUudVuY+WVtbLLjXOgGLSdufb0CksAQISC4L', 'daty2004', 't', 0);");
                context.Database.ExecuteSqlCommand("INSERT into __folder (name,state) VALUES('Test',0)");
                context.Database.ExecuteSqlCommand("INSERT INTO public.__service(id, connectionid, folderid, name, state, spatialreference, servicetype, iscached, iswmsenabled, isallowanonymous, isstopped, minscale, maxscale, maxrecordcount) VALUES (1, 1, 1, 'daty', 0, 102100, 0, 'f', 'f', 'f', 'f', 0, 0, 1000);");
            }
        }
예제 #2
0
        public PostgresTest()
        {
            var services = new ServiceCollection();

            services.AddSingleton <IAdminService, AdminService>();
            services.AddDbContext <CSContext>(builder =>
            {
                builder.UseNpgsql(_connectionString, option =>
                {
                    option.UseNetTopologySuite();
                });
            });
            _addNHibernateSession(services);
            _serviceProvider = services.BuildServiceProvider();
            _adminService    = _serviceProvider.GetRequiredService <IAdminService>();
            _context         = _serviceProvider.GetRequiredService <CSContext>();
            _session         = _serviceProvider.GetRequiredService <ISession>();
        }