Exemple #1
0
        public static void Initialize(ProductCatalogueContext context)
        {
            context.Database.EnsureCreated();

            // Look for any students.
            if (context.Products.Any())
            {
                return;   // DB has been seeded
            }

            var products = new List <Product>
            {
                new Product {
                    Name = "Wrench", Category = "Hand Tools", Price = 6.00m
                },
                new Product {
                    Name = "Claw Hammer", Category = "Hand Tools", Price = 4.00m
                },
                new Product {
                    Name = "Drill", Category = "Power Tools", Price = 40.00m
                },
                new Product {
                    Name = "Jigsaw", Category = "Power Tools", Price = 60.00m
                },
                new Product {
                    Name = "Padlock", Category = "Ironmongery", Price = 2.50m
                },
                new Product {
                    Name = "Silicone", Category = "Sealants", Price = 15.00m
                }
            };

            context.Products.AddRange(products);
            context.SaveChanges();
        }
        public CatalogueControllerTest()
        {
            /* _service.AddDbContext<ProductCatalogueContext>()
             * .AddEntityFrameworkInMemoryDatabase(); */

            _service.AddTransient(typeof(IRepository <>), typeof(Repository <>));
            _service.AddTransient(typeof(ICoreDbContext), _ => {
                var context = new  ProductCatalogueContext();

                if (!context.Products.Any())
                {
                    context.Products.Add(new Product()
                    {
                        Title = "Sample 1", ProductType = "Other"
                    });
                    context.Products.Add(new Product()
                    {
                        Title = "Sample 2", ProductType = "Other"
                    });
                    context.Products.Add(new Product()
                    {
                        Title = "Sample 3", ProductType = "Other"
                    });
                    context.Products.Add(new Product()
                    {
                        Title = "Sample 4", ProductType = "Other"
                    });

                    context.Products.Add(new Product()
                    {
                        Title = "Sample Book 1", ProductType = "Book"
                    });
                    context.Products.Add(new Product()
                    {
                        Title = "Sample Book 2", ProductType = "Book"
                    });
                    context.Products.Add(new Product()
                    {
                        Title = "Sample Book 3", ProductType = "Book"
                    });

                    context.Products.Add(new Product()
                    {
                        Title = "Sample Car 1", ProductType = "Car"
                    });
                    context.Products.Add(new Product()
                    {
                        Title = "Sample Car 2", ProductType = "Car"
                    });
                    context.SaveChanges();
                }

                return(context);
            });
            _service.AddTransient <UnitOfWork>();

            provider = _service.BuildServiceProvider();
        }
Exemple #3
0
        public ProductControllerTests()
        {
            _dbOptions = new DbContextOptionsBuilder <ProductCatalogueContext>()
                         .UseInMemoryDatabase(databaseName: "ProductCatalogueDb_InMemory").Options;

            using (var dbContext = new ProductCatalogueContext(_dbOptions))
            {
                dbContext.Products.AddRange(GetFakeProducts());
                dbContext.SaveChanges();
            }
        }
        public ProductController(ProductCatalogueContext context)
        {
            _context = context;

            if (_context.ProductCatalogue.Count() == 0)
            {
                _context.ProductCatalogue.Add(new ProductCatalogue {
                    Id = 001, Name = "Product1", productDescription = "event product 1"
                });
                _context.SaveChanges();
            }
        }
        public ProductController(ProductCatalogueContext context)
        {
            _context = context;

            if (_context.Products.Count() == 0)
            {
                _context.Products.Add(new Product {
                    Sku = "PRODUCT-A"
                });
                _context.SaveChanges();
            }
        }