예제 #1
0
 // TODO move to proper project
 public static void BootstrapDataAccess(IServiceCollection services, ApiConfiguration appConfiguration)
 {
     services.AddScoped <ICharacterRepository, CharacterRepository>();
     if (!IsInMemmoryDb(appConfiguration))
     {
         services.AddDbContext <StarWarsDbContext>(options =>
                                                   options.UseSqlite(appConfiguration.DatabasePath));
     }
     else
     {
         // for tests keep single connection all the time
         var connection = InMemoryDbConnectionFactory.CreateInMemoryDbConnection();
         var options    = new DbContextOptionsBuilder <StarWarsDbContext>()
                          .UseSqlite(connection)
                          .Options;
         PrepareContext(options);
         services.AddScoped <StarWarsDbContext>(_ => new StarWarsDbContext(options));
     }
예제 #2
0
        public async Task Setup()
        {
            _connection = InMemoryDbConnectionFactory.CreateInMemoryDbConnection();
            IConfiguration configuration = Substitute.For <IConfiguration>();

            configuration["PageSize"].Returns("5");
            configuration["DatabasePath"].Returns(DataAccessConstants.InMemoryDbPath);

            var services = new ServiceCollection();

            services.AddSingleton <IConfiguration>(configuration);
            services.Bootstrap(configuration);
            // overwrites
            services.AddDbContext <StarWarsDbContext>(options =>
                                                      options.UseSqlite(_connection));
            // resolve tested component
            var provider = services.BuildServiceProvider();

            _serviceUnderTests = provider.GetRequiredService <ICharactersService>();
        }
예제 #3
0
 public void Setup()
 {
     _connection = InMemoryDbConnectionFactory.CreateInMemoryDbConnection();
 }