public ControllerTests() { var options = new DbContextOptionsBuilder <Context>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; _context = new Context(options); _roleManager = new RoleManager <AppRole>( new RoleStore <AppRole, Context, int>(_context), new List <RoleValidator <AppRole> > { new RoleValidator <AppRole>() }, null, null, new Mock <ILogger <RoleManager <AppRole> > >().Object ); _userManager = new UserManager <AppUser>( new UserStore <AppUser, AppRole, Context, int>(_context), null, new PasswordHasher <AppUser>(), new List <UserValidator <AppUser> > { new UserValidator <AppUser>() }, null, null, null, null, new Mock <ILogger <UserManager <AppUser> > >().Object ); DataFill.LoadData(_context); DataFill.LoadOglasi(_context); DataFill.AddUsers(_userManager, _context, _roleManager); }
public IActionResult FillDatabase() { if (DataFill.IsEmptyDB(context)) { if (DataFill.LoadData(context) && DataFill.LoadOglasi(context)) { return(Content("Baza uspjesno popunjena.")); } else { return(Content("Nemoguce popuniti tabele. Potrebno je obrisati čitavu bazu i ponovo uraditi migracije i update da bi mogli ponovo generisati podatke.")); } } return(Content("Baza je vec puna. Potrebno je obrisati citavu bazu pa ponovo generisati podatke.")); }
public static void Main(string[] args) { //CreateHostBuilder(args).Build().Run(); var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <Context>(); var userMgr = services.GetRequiredService <UserManager <AppUser> >(); var roleMgr = services.GetRequiredService <RoleManager <AppRole> >(); var signInMgr = services.GetRequiredService <SignInManager <AppUser> >(); context.Database.Migrate(); var controller = new AccountController(context, userMgr, signInMgr, roleMgr); var task = Task.Run(() => controller.CreateRolesOnce()); task.Wait(); Console.WriteLine("Users added"); if (!context.Proizvod.Any()) { if (DataFill.LoadData(context) && DataFill.LoadOglasi(context)) { Console.WriteLine("Data added"); } } } catch (Exception e) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(e, "Desila se greska prilikom ubacivanja podataka u bazu."); } } host.Run(); }