private void Seed()
        {
            lock (_lock)
            {
                if (!_databaseInitialized)
                {
                    using (var context = new BudBudgetContext(ContextOptions))
                    {
                        context.Database.EnsureDeleted();
                        context.Database.EnsureCreated();

                        // Password: test
                        var user1 = new User()
                        {
                            Id = 1, Username = "******", PasswordHash = "EE26B0DD4AF7E749AA1A8EE3C10AE9923F618980772E473F8819A5D4940E0DB27AC185F8A0E1D5F84F88BC887FD67B143732C304CC5FA9AD8E6F57F50028A8FF"
                        };

                        // Password: test
                        var user2 = new User()
                        {
                            Id = 2, Username = "******", PasswordHash = "EE26B0DD4AF7E749AA1A8EE3C10AE9923F618980772E473F8819A5D4940E0DB27AC185F8A0E1D5F84F88BC887FD67B143732C304CC5FA9AD8E6F57F50028A8FF"
                        };
                        context.Add(user1);
                        context.Add(user2);

                        context.AddRange(defaultCategories);
                        context.AddRange(defaultEntries);

                        context.SaveChanges();
                    }

                    _databaseInitialized = true;
                }
            }
        }
Exemple #2
0
        private EntriesController CreateEntriesController(BudBudgetContext context, int userId = 0)
        {
            var entriesController = new EntriesController(context, Fixture.mapper);

            var claims = new List <Claim>
            {
                new Claim("UserId", userId.ToString())
            };
            var claimsIdentity = new ClaimsIdentity(claims);

            entriesController.ControllerContext             = new ControllerContext();
            entriesController.ControllerContext.HttpContext = new DefaultHttpContext {
                User = new ClaimsPrincipal(claimsIdentity)
            };

            return(entriesController);
        }
        public BudBudgetContext CreateContext(SqliteTransaction transaction = null)
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new AutoMapperProfile());
            });

            this.mapper = config.CreateMapper();

            var context = new BudBudgetContext(ContextOptions);

            if (transaction != null)
            {
                context.Database.UseTransaction(transaction);
            }

            return(context);
        }
 public EntriesController(BudBudgetContext context, IMapper mapper)
     : base(context, mapper)
 {
 }
Exemple #5
0
 public DbSessionHandler(IOptionsMonitor <DbSessionOption> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock, BudBudgetContext dataContext, IConfiguration configuration) : base(options, logger, encoder, clock)
 {
     // store custom services here...
     this.dataContext   = dataContext;
     this.configuration = configuration;
 }
 public AuthController(BudBudgetContext context, IMapper mapper)
     : base(context, mapper)
 {
 }