public async Task CitiesSeederShouldWork() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "CitiesSeederShouldWork").Options; var dbContext = new ApplicationDbContext(options); var citiesRepository = new EfDeletableEntityRepository <City>(dbContext); var serviceProvider = new Mock <IServiceProvider>(); serviceProvider .Setup(x => x.GetService(typeof(ICitiesService))) .Returns(new CitiesService(citiesRepository)); var seeder = new CitiesSeeder(); await seeder.SeedAsync(dbContext, serviceProvider.Object); Assert.NotEmpty(dbContext.Cities); }
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); }