示例#1
0
 public async Task ShouldRunAsync()
 {
     //Act
     using (var actual = await RedisRunner.StartAsync())
     {
         //Assert
         Assert.Equal(State.Running, actual.State);
     }
 }
示例#2
0
        public async Task ShouldTimeoutAsync()
        {
            //Act
            var exception = await Assert.ThrowsAsync <TimeoutException>(
                async() => await RedisRunner.StartAsync(1)
                );

            //Assert
            Assert.NotNull(exception);
        }
        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);
            }
        }