예제 #1
0
        private async Task SeedBook(CakeItDbContext db)
        {
            var repo = new Repository <Book>(db);

            var service = new BookService(repo, this.Mapper, null);

            var modelA = new CreateBookViewModel
            {
                Author      = "Ema Tor",
                Title       = "Cook with pleasure",
                CoverUrl    = "https://res.cloudinary.com/cakeit/image/upload/v1546032585/DairyFreeRecipes.jpg",
                Description = "This book offers you an array of delicious dairy-free delights.",
                DownloadUrl = "https://res.cloudinary.com/cakeit/image/upload/v1545921235/50_Dairy-Free_Recipes.pdf",
                Pages       = 23
            };

            await service.CreateBook(modelA);

            var modelB = new CreateBookViewModel
            {
                Author      = "Various",
                Title       = "Holiday Baking Experimente",
                CoverUrl    = "https://res.cloudinary.com/cakeit/image/upload/v1546028277/HBE.pdf",
                Description = "This book offers you an array of delicious dairy-free delights.",
                DownloadUrl = "https://res.cloudinary.com/cakeit/image/upload/v1546032518/HoliayBakingExperiment.jpg",
                Pages       = 23
            };

            await service.CreateBook(modelB);
        }
예제 #2
0
        private async Task SeedCustomCakeImg(CakeItDbContext db)
        {
            var repo = new Repository <CustomCakeImg>(db);
            var mock = new Mock <ILogger <CustomCakeService> >();
            ILogger <CustomCakeService> logger = mock.Object;
            var service = new CustomCakeService(null, repo, this.Mapper, logger);

            CustomCakeImgViewModel model1 = new CustomCakeImgViewModel
            {
                Side = "White Cigarettes",
                Top  = "Habana",
                Name = "Habana" + " " + "White Cigarettes",
                Img  = "https://someurl.bg"
            };

            await service.AddCustomCakeImg(model1);

            CustomCakeImgViewModel model2 = new CustomCakeImgViewModel
            {
                Side = "Dark Cigarettes",
                Top  = "Meksiko",
                Name = "Meksiko" + " " + "Dark Cigarettes",
                Img  = "https://otherurl.bg"
            };

            await service.AddCustomCakeImg(model2);

            await repo.SaveChangesAsync();
        }
        private async Task SeedTutorials(CakeItDbContext db)
        {
            var repo = new Repository <Tutorial>(db);

            repo.Add(new Tutorial {
                Title = "Lotus Flower", Description = "Lotus Test Descripion", Url = "https://someurl.bg"
            });

            repo.Add(new Tutorial {
                Title = "Silver leaf", Description = "Silver leaf" +
                                                     " Test Descripion", Url = "https://someurl2.bg"
            });

            await repo.SaveChangesAsync();
        }
예제 #4
0
        private CakeItDbContext SetDb()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkInMemoryDatabase()
                                  .BuildServiceProvider();

            var builder = new DbContextOptionsBuilder <CakeItDbContext>();

            builder.UseInMemoryDatabase($"database{Guid.NewGuid()}")
            .UseInternalServiceProvider(serviceProvider);


            var Db = new CakeItDbContext(builder.Options);

            return(Db);
        }
예제 #5
0
        private async Task SeedCake(CakeItDbContext db, ILogger <CakeItDbContext> logger)
        {
            var product1 = new Product {
                CategoryId = 1, Name = "Choco Mint", Price = 23.20m, Description = "A chocolate sponge layered with a mint flavoured cream. Masked with icing cream, chocolate glaze drip and a range of yummy choc mint goodies on top.", Image = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRNPFKz7AZZjPSwn-e7_QwcGdDUVRI1z_fG_gQiSPI4u1wBQShmhA&s"
            };

            var product2 = new Product {
                CategoryId = 1, Name = "Cherry Blossom", Price = 55.00m, Description = "Chocolate sponge with matcha green tea buttercream. Decorated with 'cherry blossom' pink sea-salted candied popcorn and pink macarons.", Image = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRcSkgiYbXZlj8AmkDwlbE0BkCMsxKR9NlEHcbVKOL3D5WXvQQx6w&s"
            };

            try
            {
                await db.AddRangeAsync(new object[] { product1, product2 });

                await db.SaveChangesAsync();
            }
            catch (Exception e)
            {
                logger.LogDebug(e.Message);
            }
        }
예제 #6
0
        private async Task SeedTag(CakeItDbContext db)
        {
            var repo = new Repository <Tag>(db);

            var service = new TagService(null, repo, this.Mapper);

            var modelA = new TagInputViewModel
            {
                Name = "Cakes",
            };

            await service.CreateTag(modelA);

            var modelB = new TagInputViewModel
            {
                Name = "Baking"
            };

            await service.CreateTag
                (modelB);
        }
예제 #7
0
        private async Task SeedCustomCakesImages(CakeItDbContext db, ILogger <CakeItDbContext> logger)
        {
            var product1 = new CustomCakeImg {
                Side = "White_Chocolate_Cigarettes", Top = "Habana", Img = "https://res.cloudinary.com/cakeit/image/upload/v1545083551/Top_Habana_WhiteCigarettes.png", Name = "Habana" + " " + "White Cigarettes"
            };

            var product2 = new CustomCakeImg {
                Side = "White_Chocolate_Cigarettes", Top = "Glaszed_Berries", Img = "https://res.cloudinary.com/cakeit/image/upload/v1545225696/Top_GlazedBerries_WhiteCigarettes.png", Name = "Glaszed Berries" + " " + "White Cigarettes"
            };

            try
            {
                await db.AddRangeAsync(new object[] { product1, product2 });

                await db.SaveChangesAsync();
            }
            catch (Exception e)
            {
                logger.LogDebug(e.Message);
            }
        }
예제 #8
0
        private async Task SeedProducts(CakeItDbContext db)
        {
            var repo = new Repository <Product>(db);

            var cakeModel1 = new CreateCakeViewModel {
                Name = "Chocolate Peanut Cake", CategoryId = 1, Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136591/Chocolate_and_Peanut_cake.jpg"
            };

            var cakeModel2 = new CreateCakeViewModel {
                Name = "Chocolate Drip Cake", CategoryId = 1, Price = 35.50m, Description = "This Chocolate and Peanut Butter Drip Cake is completely sinful.", Image = "https://res.cloudinary.com/cakeit/image/upload/ar_1:1,c_fill,g_auto,e_art:hokusai/v1544136590/Chocolate_Drip_cake.jpg"
            };

            var cakeService = new CakeService(null, repo, this.Mapper);

            await cakeService.AddCakeToDb(cakeModel1);

            await cakeService.AddCakeToDb(cakeModel2);

            await repo.SaveChangesAsync();

            //It works without SaveCanges()???
        }
예제 #9
0
        private async Task <IForumService> Setup(CakeItDbContext db)
        {
            var mockLogger = new Mock <ILogger <ForumService> >();

            this.logger      = mockLogger.Object;
            this.postRepo    = new Repository <Post>(db);
            this.commentRepo = new Repository <Comment>(db);
            this.userRepo    = new Repository <CakeItUser>(db);
            await SeedUsers(userRepo);

            this.tagRepo = new Repository <Tag>(db);
            await SeedTags(tagRepo);

            this.tagPostsRepo = new Repository <TagPosts>(db);
            var mockSanitizer = new Mock <HtmlSanitizerAdapter>();

            this.sanitizer = mockSanitizer.Object;

            var forumService = new ForumService(logger, postRepo, commentRepo, userRepo, tagRepo, tagPostsRepo, this.Mapper, sanitizer);

            return(forumService);
        }
        private async Task SeedCategories(CakeItDbContext db, IServiceProvider provider)
        {
            var logger = provider.GetService <ILogger <CakeItDbContext> >();

            var cake = new Category();

            cake.Type = (CategoryType)Enum.Parse(typeof(CategoryType), "Cake");
            await db.AddAsync(cake);

            var customCake = new Category();

            customCake.Type = (CategoryType)Enum.Parse(typeof(CategoryType), "CustomCake");
            await db.AddAsync(customCake);

            try
            {
                await db.SaveChangesAsync();
            }
            catch (Exception e)
            {
                logger.LogError(e.Message);
            }
        }
예제 #11
0
 public Repository(CakeItDbContext db)
 {
     this.db    = db;
     this.dbSet = db.Set <TEntity>();
 }
예제 #12
0
        private async Task SeedUser(CakeItDbContext db)
        {
            db.Users.Add(user);

            await db.SaveChangesAsync();
        }