Пример #1
0
        public IntegrationTests()
        {
            _config = new ConfigurationBuilder()
                      .SetBasePath(Directory.GetCurrentDirectory())
                      .AddJsonFile("appsettings.json", optional: false)
                      .Build();

            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(_config)
                         .WriteTo.Console()
                         .CreateLogger();

            try
            {
                Log.Information("Serilog enabled for IntegrationTests");
                _server = new TestServer(new WebHostBuilder()
                                         .UseConfiguration(_config)
                                         .UseStartup <IntegrationTestsStartup>()
                                         .UseSerilog());
                _Db      = _server.Host.Services.GetRequiredService <GthxDataContext>();
                _data    = _server.Host.Services.GetService <IGthxData>() as GthxSqlData;
                _client  = _server.Host.Services.GetService <IIrcClient>() as MockIrcClient;
                _botNick = _server.Host.Services.GetService <IBotNick>();
                _gthx    = _server.Host.Services.GetRequiredService <GthxBot>();
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "TestHost terminated unexpectedly");
                throw;
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }