예제 #1
0
 public void Dispose()
 {
     _clientApi.Dispose();
     _testServerCliente.Dispose();
     _redisRunner.Dispose();
     _postgresRunner.Dispose();
 }
예제 #2
0
        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);
            }
        }