public PgFixture()
 {
     _pgRunner = PostgresRunner
                 .Start(new PostgresRunnerOptions {
         BinariesSearchPattern = "/pg-dist/pgsql-10.1-linux-binaries/bin"
     });
 }
Exemple #2
0
 public PgFixture()
 {
     _pgRunner = PostgresRunner
                 .Start(new PostgresRunnerOptions {
         BinariesSearchPattern = GetPgBinariesRelativePath()
     });
 }
        public void Test1()
        {
            using (var runner = PostgresRunner.Start(options: new PostgresRunnerOptions()
            {
            }))
                using (var conn = new NpgsqlConnection(runner.GetConnectionString()))
                    using (var cmd = new NpgsqlCommand("select version()", conn))
                    {
                        conn.Open();
                        var version = cmd.ExecuteScalar() as string;

                        Console.WriteLine($"PostgreSQL version: {version}");
                    }
        }
Exemple #4
0
        public TestServerFixture()
        {
            try
            {
                runner = PostgresRunner.Start(new PostgresRunnerOptions()
                {
                    Port = 5432
                });
                MontaBaseDados(runner);

                var projectPath = GetContentRootPath("../src/SME.SGP.Api");

                var builderCliente = new WebHostBuilder()
                                     .UseContentRoot(projectPath)
                                     .UseEnvironment("teste-integrado")
                                     .UseConfiguration(new ConfigurationBuilder()
                                                       .SetBasePath(projectPath)
                                                       .AddJsonFile("appsettings.teste-integrado.json")
                                                       .Build())
                                     .UseStartup <Startup>();

                _testServerCliente = new TestServer(builderCliente);

                _clientApi = _testServerCliente.CreateClient();

                var config = new ConfigurationBuilder()
                             .AddJsonFile(ObterArquivoConfiguracao(), optional: false)
                             .Build();

                //TODO: INJETAR UM REPOSITORIO DE CACHE E HTTPCONTEXT
                var repositorioCache = new Mock <RepositorioCache>();
                servicoTokenJwt = new ServicoTokenJwt(config, null, repositorioCache.Object);
            }
            catch (Exception ex)
            {
                if (runner != null)
                {
                    runner.Dispose();
                }
                throw new Exception(ex.Message);
            }
        }
        private void MontaBaseDados(PostgresRunner runner)
        {
            ExecutarPreScripts();

            var scripts = ObterScripts();

            using (var conn = new NpgsqlConnection(runner.GetConnectionString()))
            {
                conn.Open();

                DirectoryInfo d = new DirectoryInfo(scripts);

                var files = d.GetFiles("*.sql").OrderBy(a => int.Parse(CleanStringOfNonDigits_V1(a.Name)));

                foreach (var file in files)
                {
                    string script = File.ReadAllText(file.FullName);

                    byte[] b = File.ReadAllBytes(file.FullName);

                    Encoding enc = null;

                    var textoComEncodeCerto = ReadFileAndGetEncoding(b, ref enc);

                    using (var cmd = new NpgsqlCommand(textoComEncodeCerto, conn))
                    {
                        try
                        {
                            cmd.ExecuteNonQuery();
                        }
                        catch (Exception ex)
                        {
                            throw new Exception($"Erro ao executar o script {file.FullName}. Erro: {ex.Message}");
                        }
                    }
                }
            }
        }
Exemple #6
0
        private void MontaBaseDados(PostgresRunner runner)
        {
            var scripts = ObterScripts();

            using (var conn = new NpgsqlConnection(runner.GetConnectionString()))
            {
                conn.Open();

                DirectoryInfo d = new DirectoryInfo(scripts);

                var files = d.GetFiles("*.sql").OrderBy(a => int.Parse(CleanStringOfNonDigits_V1(a.Name)));

                foreach (var file in files)
                {
                    string script = File.ReadAllText(file.FullName);

                    using (var cmd = new NpgsqlCommand(script, conn))
                    {
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }
 public PgFixture()
 {
     _pgRunner = PostgresRunner.Start();
 }
        public TestServerFixture()
        {
            try
            {
                Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

                _postgresRunner = PostgresRunner.Start(new PostgresRunnerOptions()
                {
                    Port = 5434
                });
                MontaBaseDados(_postgresRunner);

                _redisRunner = RedisRunner.Start();

                Environment.SetEnvironmentVariable("ApplicationInsights__InstrumentationKey", "ab");

                var projectPath = GetContentRootPath("../src/SME.SGP.Api");

                var servicoLog = new Mock <IServicoLog>();
                servicoLog.Setup(sl => sl.Registrar(new Exception()));
                servicoLog.Setup(sl => sl.Registrar(string.Empty));

                var builderCliente = new WebHostBuilder()
                                     .UseContentRoot(projectPath)
                                     .ConfigureServices(services =>
                {
                    services.AddSingleton <IConnectionMultiplexerSME>(new ConnectionMultiplexerSME($"localhost:{_redisRunner.Port}", servicoLog.Object));
                })
                                     .UseEnvironment("teste-integrado")
                                     .UseConfiguration(new ConfigurationBuilder()
                                                       .SetBasePath(projectPath)
                                                       .AddJsonFile("appsettings.teste-integrado.json")
                                                       .Build())
                                     .UseStartup <Startup>();

                _testServerCliente = new TestServer(builderCliente);

                _clientApi = _testServerCliente.CreateClient();

                var config = new ConfigurationBuilder()
                             .AddJsonFile(ObterArquivoConfiguracao(), optional: false)
                             .Build();

                var contextoTesteIntegrado = new ContextoTesteIntegrado("");

                servicoTokenJwt = new ServicoTokenJwt(config, contextoTesteIntegrado);
            }
            catch (Exception ex)
            {
                if (_postgresRunner != null)
                {
                    _postgresRunner.Dispose();
                }

                if (_redisRunner != null)
                {
                    _redisRunner.Dispose();
                }

                throw new Exception(ex.Message);
            }
        }