예제 #1
0
        public async Task CategoySeederShouldWork()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "CategoySeederShouldWork").Options;
            var dbContext = new ApplicationDbContext(options);

            var categoriesRepository = new EfDeletableEntityRepository <Category>(dbContext);
            var imagesRepository     = new EfDeletableEntityRepository <Image>(dbContext);

            var serviceProvider = new Mock <IServiceProvider>();

            serviceProvider
            .Setup(x => x.GetService(typeof(ICategoriesService)))
            .Returns(new CategoriesService(categoriesRepository));

            var     imagesService         = new ImagesService(imagesRepository);
            Account cloudinaryCredentials = new Account(
                this.Configuration["Cloudinary:CloudName"],
                this.Configuration["Cloudinary:ApiKey"],
                this.Configuration["Cloudinary:ApiSecret"]);
            Cloudinary cloudinary = new Cloudinary(cloudinaryCredentials);

            serviceProvider
            .Setup(x => x.GetService(typeof(ICloudinaryService)))
            .Returns(new CloudinaryService(cloudinary, imagesService));

            var seeder = new CategorySeeder();
            await seeder.SeedAsync(dbContext, serviceProvider.Object);

            Assert.NotEmpty(dbContext.Categories);
        }
예제 #2
0
 public static void Seed(AppDbContext dbContext, RoleManager <Role> roleManager, UserManager <User> userManager)
 {
     CategorySeeder.CreateCategories(dbContext);
     CategorySeeder.CreateCities(dbContext);
     CategorySeeder.CategoryJob(dbContext);
     CreateUsers(dbContext, roleManager, userManager).GetAwaiter().GetResult();
     DbSeedUser.PopulateUser(dbContext, roleManager, userManager).GetAwaiter().GetResult();
     DbSeedUser.PopulateJobs(dbContext, roleManager, userManager).GetAwaiter().GetResult();
     dbContext.SaveChanges();
 }
예제 #3
0
        protected override void Seed(DsContext context)
        {
            RoleSeeder.SeedInitialRoles(context);

            FeatureTierSeeder.SeedInitialFeatureTiers(context);

            UserSeeder.SeedInitialUsers(context);

            var categories = CategorySeeder.SeedInitialCategories(context);

            var keywords = KeywordSeeder.SeedInitialKeywords(context);

            DocumentSeeder.AddTestDocuments(context, categories, keywords);
        }
        public static void EnsureSeedDataForContext(this EshopDbContext context)
        {
            // first, clear the database.  This ensures we can always start
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            RolesSeeder.Seed(context);
            UsersSeeder.Seed(context);

            VendorSeeder.Seed(context);

            CategorySeeder.Seed(context);

            ProductStateSeeder.Seed(context);
            ProductSeeder.Seed(context);

            OrderStateSeeder.Seed(context);
        }
예제 #5
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;

                var context = services.GetRequiredService <ApplicationDbContext>();
                AdminSeeder.SeedDatabase(context, services).Wait();
                CategorySeeder.SeedDatabase(context).Wait();
                ProductSeeder.SeedDatabase(context).Wait();
            }

            Directory.SetCurrentDirectory(AppContext.BaseDirectory);

            host.Run();
        }
예제 #6
0
        public async Task PostsSeederShouldWork()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "PostsSeederShouldWork").Options;
            var dbContext = new ApplicationDbContext(options);

            // Repos
            var postsRepository             = new EfDeletableEntityRepository <Post>(dbContext);
            var categoriesRepository        = new EfDeletableEntityRepository <Category>(dbContext);
            var vehicleCategoriesRepository = new EfDeletableEntityRepository <VehicleCategory>(dbContext);
            var colorsRepository            = new EfDeletableEntityRepository <Color>(dbContext);
            var makesRepository             = new EfDeletableEntityRepository <Make>(dbContext);
            var modelsRepository            = new EfDeletableEntityRepository <Model>(dbContext);
            var citiesRepository            = new EfDeletableEntityRepository <City>(dbContext);
            var imagesRepository            = new EfDeletableEntityRepository <Image>(dbContext);

            // Setups
            var serviceProvider = new Mock <IServiceProvider>();
            var makesService    = new MakesService(makesRepository);
            var imagesService   = new ImagesService(imagesRepository);

            var userManager = this.GetUserManager(dbContext);

            Account cloudinaryCredentials = new Account(
                this.Configuration["Cloudinary:CloudName"],
                this.Configuration["Cloudinary:ApiKey"],
                this.Configuration["Cloudinary:ApiSecret"]);
            Cloudinary cloudinary = new Cloudinary(cloudinaryCredentials);

            await userManager.CreateAsync(new ApplicationUser()
            {
                UserName = "******"
            });

            serviceProvider
            .Setup(x => x.GetService(typeof(ICloudinaryService)))
            .Returns(new CloudinaryService(cloudinary, imagesService));
            serviceProvider
            .Setup(x => x.GetService(typeof(IPostsService)))
            .Returns(new PostsService(postsRepository, makesService));
            serviceProvider
            .Setup(x => x.GetService(typeof(ICategoriesService)))
            .Returns(new CategoriesService(categoriesRepository));
            serviceProvider
            .Setup(x => x.GetService(typeof(IVehicleCategoriesService)))
            .Returns(new VehicleCategoriesService(vehicleCategoriesRepository));
            serviceProvider
            .Setup(x => x.GetService(typeof(IColorService)))
            .Returns(new ColorService(colorsRepository));
            serviceProvider
            .Setup(x => x.GetService(typeof(ICategoriesService)))
            .Returns(new CategoriesService(categoriesRepository));
            serviceProvider
            .Setup(x => x.GetService(typeof(IMakesService)))
            .Returns(makesService);
            serviceProvider
            .Setup(x => x.GetService(typeof(IModelsService)))
            .Returns(new ModelsService(modelsRepository));
            serviceProvider
            .Setup(x => x.GetService(typeof(ICitiesService)))
            .Returns(new CitiesService(citiesRepository));
            serviceProvider
            .Setup(x => x.GetService(typeof(IImagesService)))
            .Returns(imagesService);
            serviceProvider
            .Setup(x => x.GetService(typeof(UserManager <ApplicationUser>)))
            .Returns(userManager);

            // Categories
            var categoriesSeeder = new CategorySeeder();
            await categoriesSeeder.SeedAsync(dbContext, serviceProvider.Object);

            // Vehicle cateogories
            var vehicleCategoriesSeeder = new VehicleCategorySeeder();
            await vehicleCategoriesSeeder.SeedAsync(dbContext, serviceProvider.Object);

            // Colors
            var colorsSeeder = new ColorSeeder();
            await colorsSeeder.SeedAsync(dbContext, serviceProvider.Object);

            // Makes
            var makesSeeder = new MakesSeeder();
            await makesSeeder.SeedAsync(dbContext, serviceProvider.Object);

            // Models
            var modelsSeeder = new ModelsSeeder();
            await modelsSeeder.SeedAsync(dbContext, serviceProvider.Object);

            // Cities
            var citiesSeeder = new CitiesSeeder();
            await citiesSeeder.SeedAsync(dbContext, serviceProvider.Object);

            // Posts
            var postsSeeder = new PostsSeeder();
            await postsSeeder.SeedAsync(dbContext, serviceProvider.Object);

            Assert.NotEmpty(dbContext.Posts);
        }