Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DiffControllerTests"/> class.
        /// </summary>
        public DiffControllerTests()
        {
            WebHostBuilder hostBuilder = new WebHostBuilder();

            hostBuilder.ConfigureServices(s => s.AddDbContext <DataComparerContext>(options =>
                                                                                    options.UseSqlite("Data Source=comparer.integration.db")));

            _server = new TestServer(hostBuilder.UseStartup <Startup>());
            _client = _server.CreateClient();

            _dbContext = _server.Host.Services.GetRequiredService <DataComparerContext>();
            Task.Run(() => DataComparerInitializer.InitializeAsync(_dbContext));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Mains the specified arguments.
        /// </summary>
        /// <param name="args">The arguments.</param>
        public static async Task Main(string[] args)
        {
            IWebHost host = BuildWebHost(args);

            using (IServiceScope scope = host.Services.CreateScope())
            {
                IServiceProvider services = scope.ServiceProvider;

                try
                {
                    DataComparerContext context = services.GetRequiredService <DataComparerContext>();
                    await DataComparerInitializer.InitializeAsync(context);
                }
                catch (Exception ex)
                {
                    ILogger <Program> logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }

            host.Run();
        }