public async Task SetUp() { var options = new DbContextOptionsBuilder <ShoplifyDbContext>() .UseInMemoryDatabase(databaseName: "comments") .Options; this.context = new ShoplifyDbContext(options); await context.Database.EnsureDeletedAsync(); await context.Database.EnsureCreatedAsync(); var store = new Mock <IUserStore <User> >(); var mgr = new Mock <UserManager <User> >(store.Object, null, null, null, null, null, null, null, null); mgr.Object.UserValidators.Add(new UserValidator <User>()); mgr.Object.PasswordValidators.Add(new PasswordValidator <User>()); List <User> ls = new List <User>(); mgr.Setup(x => x.DeleteAsync(It.IsAny <User>())).ReturnsAsync(IdentityResult.Success); mgr.Setup(x => x.CreateAsync(It.IsAny <User>(), It.IsAny <string>())).ReturnsAsync(IdentityResult.Success).Callback <User, string>((x, y) => ls.Add(x)); mgr.Setup(x => x.UpdateAsync(It.IsAny <User>())).ReturnsAsync(IdentityResult.Success); this.service = new CommentService(context, mgr.Object); }
public async Task <bool> SeedAsync(ShoplifyDbContext context, IServiceProvider serviceProvider) { if (context.Towns.Any()) { return(false); } var townNames = new List <string>() { "Sofia", "Varna", "Plovdiv", "Burgas", "Pernik", "Stara Zagora", "Veliko Tarnovo", "Shumen", "Montana", "Vidin", "Vratza" }; foreach (var name in townNames) { await context.Towns.AddAsync(new Town() { Name = name }); } await context.SaveChangesAsync(); return(true); }
public async Task <bool> SeedAsync(ShoplifyDbContext context, IServiceProvider serviceProvider) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } var seeders = new List <ISeeder>() { new UserRoleSeeder(), new CategorySeeder(), new SubCategorySeeder(), new TownSeeder(), }; foreach (var seeder in seeders) { await seeder.SeedAsync(context, serviceProvider); await context.SaveChangesAsync(); } return(true); }
public async Task SetUp() { var options = new DbContextOptionsBuilder <ShoplifyDbContext>() .UseInMemoryDatabase(databaseName: "notifications") .Options; this.context = new ShoplifyDbContext(options); await context.Database.EnsureDeletedAsync(); await context.Database.EnsureCreatedAsync(); this.service = new NotificationService(context); }
public async Task SetUp() { var options = new DbContextOptionsBuilder <ShoplifyDbContext>() .UseInMemoryDatabase(databaseName: "reports") .Options; this.context = new ShoplifyDbContext(options); await context.Database.EnsureDeletedAsync(); await context.Database.EnsureCreatedAsync(); var moqCloudinaryService = new Mock <ICloudinaryService>(); this.service = new ReportService(context, new AdvertisementService(context, moqCloudinaryService.Object)); }
public async Task <bool> SeedAsync(ShoplifyDbContext context, IServiceProvider serviceProvider) { if (context.Categories.Any()) { return(false); } var categoryService = serviceProvider.GetRequiredService <ICategoryService>(); var categoryNames = new List <string>() { "Real Estates", "Animals", "Gifts", "Vehicles", "Home", "Garden", "Services", "Electronics", "Sport", "Books", "Hobby", "Fashion" }; var categoryCssIcons = new List <string>() { "fas fa-home", "fas fa-paw", "fas fa-hand-holding-heart", "fas fa-car", "fas fa-couch", "fas fa-seedling", "fas fa-tools", "fas fa-mobile-alt", "far fa-futbol", "fas fa-book", "fas fa-gamepad", "fas fa-tshirt" }; await categoryService.CreateAllAsync(categoryNames, categoryCssIcons); var addedCategoriesCount = await context.SaveChangesAsync(); return(addedCategoriesCount > 0); }
public async Task <bool> SeedAsync(ShoplifyDbContext context, IServiceProvider serviceProvider) { if (context.Roles.Any()) { return(false); } await context.Roles.AddAsync(new IdentityRole { Name = GlobalConstants.AdministratorRoleName, NormalizedName = "ADMIN" }); await context.Roles.AddAsync(new IdentityRole { Name = "User", NormalizedName = "USER" }); var result = await context.SaveChangesAsync(); return(result > 0); }
public async Task SetUp() { var options = new DbContextOptionsBuilder <ShoplifyDbContext>() .UseInMemoryDatabase(databaseName: "wishlists") .Options; this.context = new ShoplifyDbContext(options); await context.Database.EnsureDeletedAsync(); await context.Database.EnsureCreatedAsync(); this.service = new UserAdWishlistService(context); var moqCloudinaryService = new Mock <ICloudinaryService>(); var moqIFormFile = new Mock <IFormFile>(); this.mockedFile = moqIFormFile.Object; moqCloudinaryService.Setup(x => x.UploadPictureAsync(moqIFormFile.Object, "FileName")) .ReturnsAsync("http://test.com"); this.adService = new AdvertisementService(context, moqCloudinaryService.Object); }
public TownService(ShoplifyDbContext context) { this.context = context; }
public ConversationService(ShoplifyDbContext context) { this.context = context; }
public AdvertisementService(ShoplifyDbContext context, ICloudinaryService cloudinaryService) { this.context = context; this.cloudinaryService = cloudinaryService; }
public ReportService(ShoplifyDbContext context, IAdvertisementService advertisementService) { this.context = context; this.advertisementService = advertisementService; }
public UserAdWishlistService(ShoplifyDbContext context) { this.context = context; }
public CategoryService(ShoplifyDbContext context) { this.context = context; }
public SubCategoryService(ShoplifyDbContext context, ICategoryService categoryService) { this.context = context; this.categoryService = categoryService; }
public UserService(ShoplifyDbContext context) { this.context = context; }
public async Task <bool> SeedAsync(ShoplifyDbContext context, IServiceProvider serviceProvider) { if (context.SubCategories.Any()) { return(false); } var categoryService = serviceProvider.GetRequiredService <ICategoryService>(); var subCategoryService = serviceProvider.GetRequiredService <ISubCategoryService>(); var categoriesWithSubCategories = new Dictionary <string, List <string> >() { { "Real Estates", new List <string>() { "Sales", "Rents", "Roommate" } }, { "Animals", new List <string>() { "Dogs", "Cats", "Fish", "Birds", "Goods", "Other" } }, { "Vehicles", new List <string>() { "Cars/Car Parts", "Motorbikes/Parts", "Tires", "ATMs", "Mopeds", "Other" } }, { "Home", new List <string>() { "Furniture", "Household", "Cleaning", "Other" } }, { "Garden", new List <string>() { "Plants", "Trees", "Tools", "Seeds", "Other" } }, { "Services", new List <string>() { "Business", "Beauty", "Courses", "Other" } }, { "Electronics", new List <string>() { "Computers", "Phones", "Photo", "Audio", "Tablets", "TVs", "Navigation", "Coolers", "Other" } }, { "Sport", new List <string>() { "Football", "Basketball", "Volleyball", "Swimming", "Other" } }, { "Books", new List <string>() { "Sci-Fi", "Technical", "SchoolBooks", "Other" } }, { "Hobby", new List <string>() { "Games", "Music", "Films", "Board games", "Playing Cards", "Other" } }, { "Fashion", new List <string>() { "Clothes", "Perfumes", "Jewelry", "Shoes", "Watches", "Other" } }, { "Gifts", new List <string>() { "Gifts" } }, }; foreach (var kvp in categoriesWithSubCategories) { var category = context.Categories.SingleOrDefault(c => c.Name == kvp.Key); await subCategoryService.CreateAllAsync(kvp.Value, category.Id); } var result = await context.SaveChangesAsync(); return(result > 0); }
public NotificationService(ShoplifyDbContext context) { this.context = context; }
public MessageService(ShoplifyDbContext context) { this.context = context; }
public CommentService(ShoplifyDbContext context, UserManager <User> userManager) { this.context = context; this.userManager = userManager; }