示例#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();
 }