Ejemplo n.º 1
0
        public static async Task ClearAndMarkTestDatabase(VamBooruDbContext dbContext)
        {
            if (dbContext.Database.GetDbConnection().Database.EndsWith("Test"))
            {
                throw new UnauthorizedAccessException("Cannot use a non-test database in tests");
            }

            var tables = dbContext.Model.GetEntityTypes().Select(entity => entity.Relational().TableName).ToArray();

            if (!new HashSet <string>(Tables).SetEquals(tables))
            {
                throw new InvalidOperationException($"Tables to delete do not match tables specified in DbContext entities: {string.Join(", ", tables)}");
            }

            foreach (var table in Tables)
            {
                try
                {
                    var sql = $"DELETE FROM \"{table}\"";
                                        #pragma warning disable EF1000
                    await dbContext.Database.ExecuteSqlCommandAsync(sql);

                                        #pragma warning restore EF1000
                }
                catch (PostgresException exc)
                {
                    throw new InvalidOperationException($"Could not delete table {table} - check that the delete sequence respects constraints.", exc);
                }
            }
        }
Ejemplo n.º 2
0
 public Bootstrapper(IHostingEnvironment env, VamBooruDbContext dbContext, IUsersRepository usersRepository, IPostsRepository postsRepository, IPostCommentsRepository commentsRepository, IVotesRepository votesRepository, IStorage storage)
 {
     _env                = env ?? throw new ArgumentNullException(nameof(env));
     _dbContext          = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _usersRepository    = usersRepository ?? throw new ArgumentNullException(nameof(usersRepository));
     _postsRepository    = postsRepository ?? throw new ArgumentNullException(nameof(postsRepository));
     _storage            = storage ?? throw new ArgumentNullException(nameof(storage));
     _commentsRepository = commentsRepository ?? throw new ArgumentNullException(nameof(commentsRepository));
     _votesRepository    = votesRepository ?? throw new ArgumentNullException(nameof(votesRepository));
 }
Ejemplo n.º 3
0
 protected void Cleanup()
 {
     DbContext?.Dispose();
     DbContext = null;
 }
Ejemplo n.º 4
0
 protected abstract T Create(VamBooruDbContext context);
Ejemplo n.º 5
0
 protected void CreateDbContext()
 {
     DbContext?.Dispose();
     DbContext  = new TestsDbContextFactory().CreateDbContext(new string[0]);
     Repository = Create(DbContext);
 }
 public EntityFrameworkUsersRepository(VamBooruDbContext dbContext)
     : base(dbContext)
 {
 }
 protected override EntityFrameworkVotesRepository Create(VamBooruDbContext context)
 {
     _users = new EntityFrameworkUsersRepository(context);
     _posts = new EntityFrameworkPostsRepository(context, _users);
     return(new EntityFrameworkVotesRepository(context, _users));
 }
Ejemplo n.º 8
0
 private void CreateDbContext()
 {
     _context?.Dispose();
     _context = new TestsDbContextFactory().CreateDbContext(new string[0]);
     _storage = new EntityFrameworkStorage(_context);
 }
Ejemplo n.º 9
0
 public EntityFrameworkStorage(VamBooruDbContext context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
 protected override EntityFrameworkTagsRepository Create(VamBooruDbContext context)
 {
     _posts = new EntityFrameworkPostsRepository(context, new EntityFrameworkUsersRepository(context));
     return(new EntityFrameworkTagsRepository(context));
 }
Ejemplo n.º 11
0
 public EntityFrameworkPostCommentsRepository(VamBooruDbContext dbContext, IUsersRepository usersRepository)
     : base(dbContext)
 {
     _usersRepository = usersRepository ?? throw new ArgumentNullException(nameof(usersRepository));
 }
 protected override EntityFrameworkUsersRepository Create(VamBooruDbContext context) => new EntityFrameworkUsersRepository(context);
Ejemplo n.º 13
0
 public AdminController(IUsersRepository usersRepository, VamBooruDbContext dbContext)
 {
     _usersRepository = usersRepository ?? throw new ArgumentNullException(nameof(usersRepository));
     _dbContext       = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
 }
 protected EntityFrameworkRepositoryBase(VamBooruDbContext dbContext)
 {
     DbContext = dbContext;
 }
 public EntityFrameworkVotesRepository(VamBooruDbContext dbContext, IUsersRepository users)
     : base(dbContext)
 {
     _users = users ?? throw new ArgumentNullException(nameof(users));
 }
Ejemplo n.º 16
0
 public EntityFrameworkPostFilesRepository(VamBooruDbContext dbContext)
     : base(dbContext)
 {
 }