コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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);
        }
コード例 #7
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);
        }
コード例 #8
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);
        }
コード例 #9
0
ファイル: TownService.cs プロジェクト: KostadinovK/Shoplify
 public TownService(ShoplifyDbContext context)
 {
     this.context = context;
 }
コード例 #10
0
 public ConversationService(ShoplifyDbContext context)
 {
     this.context = context;
 }
コード例 #11
0
 public AdvertisementService(ShoplifyDbContext context, ICloudinaryService cloudinaryService)
 {
     this.context           = context;
     this.cloudinaryService = cloudinaryService;
 }
コード例 #12
0
 public ReportService(ShoplifyDbContext context, IAdvertisementService advertisementService)
 {
     this.context = context;
     this.advertisementService = advertisementService;
 }
コード例 #13
0
 public UserAdWishlistService(ShoplifyDbContext context)
 {
     this.context = context;
 }
コード例 #14
0
 public CategoryService(ShoplifyDbContext context)
 {
     this.context = context;
 }
コード例 #15
0
 public SubCategoryService(ShoplifyDbContext context, ICategoryService categoryService)
 {
     this.context         = context;
     this.categoryService = categoryService;
 }
コード例 #16
0
ファイル: UserService.cs プロジェクト: KostadinovK/Shoplify
 public UserService(ShoplifyDbContext context)
 {
     this.context = context;
 }
コード例 #17
0
        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);
        }
コード例 #18
0
 public NotificationService(ShoplifyDbContext context)
 {
     this.context = context;
 }
コード例 #19
0
 public MessageService(ShoplifyDbContext context)
 {
     this.context = context;
 }
コード例 #20
0
 public CommentService(ShoplifyDbContext context, UserManager <User> userManager)
 {
     this.context     = context;
     this.userManager = userManager;
 }