public async Task SeedAsync(TrainConnectedDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var logger = serviceProvider.GetService <ILoggerFactory>().CreateLogger(typeof(ApplicationDbContextSeeder));

            var seeders = new List <ISeeder>
            {
                new RolesSeeder(),
                new SettingsSeeder(),
                new AdminSeeder(),
            };

            foreach (var seeder in seeders)
            {
                await seeder.SeedAsync(dbContext, serviceProvider);

                await dbContext.SaveChangesAsync();

                logger.LogInformation($"Seeder {seeder.GetType().Name} done.");
            }
        }
        public async Task SeedAsync(TrainConnectedDbContext dbContext, IServiceProvider serviceProvider)
        {
            var roleManager = serviceProvider.GetRequiredService <RoleManager <ApplicationRole> >();

            await SeedRoleAsync(roleManager, GlobalConstants.AdministratorRoleName);
            await SeedRoleAsync(roleManager, GlobalConstants.CoachRoleName);
            await SeedRoleAsync(roleManager, GlobalConstants.TraineeRoleName);
        }
        public async Task SeedAsync(TrainConnectedDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext.Settings.Any())
            {
                return;
            }

            await dbContext.Settings.AddAsync(new Setting { Name = "Setting1", Value = "value1" });
        }
        public async Task SeedAsync(TrainConnectedDbContext dbContext, IServiceProvider serviceProvider)
        {
            var userManager = serviceProvider.GetRequiredService <UserManager <TrainConnectedUser> >();

            var adminUser = new TrainConnectedUser()
            {
                UserName    = GlobalConstants.AdministratorUserName,
                FirstName   = GlobalConstants.AdministratorFirstName,
                LastName    = GlobalConstants.AdministratorLastName,
                Email       = GlobalConstants.AdministratorEmail,
                PhoneNumber = GlobalConstants.AdministratorPhoneNumber,
            };

            await SeedAdminAsync(userManager, adminUser);
        }
Ejemplo n.º 5
0
        public PaymentMethodsServiceTests()
        {
            var options = new DbContextOptionsBuilder <TrainConnectedDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new TrainConnectedDbContext(options);

            AutoMapperConfig.RegisterMappings(new[]
            {
                typeof(ErrorViewModel).GetTypeInfo().Assembly,
                typeof(WorkoutActivityEditInputModel).GetTypeInfo().Assembly,
            });

            this.paymentMethodsRepository = new EfRepository <PaymentMethod>(dbContext);
            this.paymentMethodsService    = new PaymentMethodsService(this.paymentMethodsRepository);
        }
Ejemplo n.º 6
0
        public UsersServiceTests()
        {
            var options = new DbContextOptionsBuilder <TrainConnectedDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new TrainConnectedDbContext(options);

            AutoMapperConfig.RegisterMappings(new[]
            {
                typeof(ErrorViewModel).GetTypeInfo().Assembly,
                typeof(WorkoutActivityEditInputModel).GetTypeInfo().Assembly,
            });

            this.usersRepository      = new EfRepository <TrainConnectedUser>(dbContext);
            this.usersRolesRepository = new EfRepository <IdentityUserRole <string> >(dbContext);

            this.usersService = new UsersService(this.usersRepository, this.usersRolesRepository, this.roleManager, this.userManager);
        }
Ejemplo n.º 7
0
        public async Task GetCountShouldReturnCorrectNumberUsingDbContext()
        {
            var options = new DbContextOptionsBuilder <TrainConnectedDbContext>()
                          .UseInMemoryDatabase(databaseName: "Find_User_Database") // Give a Unique name to the DB
                          .Options;
            var dbContext = new TrainConnectedDbContext(options);

            dbContext.Settings.Add(new Setting());
            dbContext.Settings.Add(new Setting());
            dbContext.Settings.Add(new Setting());
            await dbContext.SaveChangesAsync();

            var repository = new EfDeletableEntityRepository <Setting>(dbContext);
            var service    = new SettingsService(repository);
            var count      = service.GetCount();

            Assert.Equal(3, count);
        }
Ejemplo n.º 8
0
        public CertificatesServiceTests()
        {
            var options = new DbContextOptionsBuilder <TrainConnectedDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new TrainConnectedDbContext(options);

            AutoMapperConfig.RegisterMappings(new[]
            {
                typeof(ErrorViewModel).GetTypeInfo().Assembly,
                typeof(WorkoutActivityEditInputModel).GetTypeInfo().Assembly,
            });

            this.certificatesRepository    = new EfRepository <Certificate>(dbContext);
            this.usersRepository           = new EfRepository <TrainConnectedUser>(dbContext);
            this.workoutActivityRepository = new EfRepository <WorkoutActivity>(dbContext);

            this.certificatesService = new CertificatesService(this.certificatesRepository, this.usersRepository, this.workoutActivityRepository);
        }
        public AchievementsServiceTests()
        {
            var options = new DbContextOptionsBuilder <TrainConnectedDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;
            var dbContext = new TrainConnectedDbContext(options);

            AutoMapperConfig.RegisterMappings(new[]
            {
                typeof(ErrorViewModel).GetTypeInfo().Assembly,
                typeof(WorkoutActivityEditInputModel).GetTypeInfo().Assembly,
            });

            this.achievementsRepository      = new EfRepository <Achievement>(dbContext);
            this.workoutsRepository          = new EfRepository <Workout>(dbContext);
            this.bookingsRepository          = new EfRepository <Booking>(dbContext);
            this.workoutActivitiesRepository = new EfRepository <WorkoutActivity>(dbContext);

            this.achievementsService = new AchievementsService(this.achievementsRepository, this.workoutsRepository, this.bookingsRepository, this.workoutActivitiesRepository);
        }
Ejemplo n.º 10
0
 public EfDeletableEntityRepository(TrainConnectedDbContext context)
     : base(context)
 {
 }
Ejemplo n.º 11
0
 public EfRepository(TrainConnectedDbContext context)
 {
     this.Context = context ?? throw new ArgumentNullException(nameof(context));
     this.DbSet   = this.Context.Set <TEntity>();
 }