protected override void Seed(Vavatech.WebApi.DbServices.WarehouseContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method
            //  to avoid creating duplicate seed data.

            ProductFaker  productFaker  = new ProductFaker();
            ServiceFaker  serviceFaker  = new ServiceFaker();
            CustomerFaker customerFaker = new CustomerFaker(new AddressFaker());

            Product[] products = productFaker.Generate(10).ToArray();

            context.Products.AddOrUpdate(p => p.Id, products);

            Service[] services = serviceFaker.Generate(20).ToArray();

            context.Services.AddOrUpdate(p => p.Id, services);

            context.Customers.AddOrUpdate(p => p.Id, customerFaker.Generate(50).ToArray());

            EmployeeFaker employeeFaker = new EmployeeFaker();

            context.Users.AddOrUpdate(p => p.Id, employeeFaker.Generate(10).ToArray());

            GuestFaker guestFaker = new GuestFaker();

            context.Users.AddOrUpdate(p => p.Id, guestFaker.Generate(10).ToArray());
        }
Example #2
0
        private static void AddRangeOrdersTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            ICustomerRepository customerRepository = new DbCustomerRepository(context);

            var customers = customerRepository.Get();

            ProductFaker productFaker = new ProductFaker();
            var          products     = productFaker.Generate(50);

            ServiceFaker serviceFaker = new ServiceFaker();
            var          services     = serviceFaker.Generate(10);

            // Union - suma zbiorów
            var items = products.OfType <Item>().Union(services);

            OrderFaker orderFaker = new OrderFaker(customers, new OrderDetailFaker(items));

            var orders = orderFaker.Generate(10);

            IOrderRepository orderRepository = new DbOrderRepository(context);

            orderRepository.AddRange(orders);
        }
Example #3
0
        public static void Generate()
        {
            var productFaker = new ProductFaker();
            var serviceFaker = new ServiceFaker();

            var products = productFaker.Generate(100);
            var services = serviceFaker.Generate(40);

            var customerFaker = new CustomerFaker();
            var customers     = customerFaker.Generate(50);

            //var items = products.OfType<Item>().Union(services).ToList();

            //var orderFaker = new OrderFaker(customers, items);
            //var orders = orderFaker.Generate(10);


            using (var context = new MyContext())
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                context.Products.AddRange(products);
                context.Services.AddRange(services);
                context.SaveChanges();


                context.Customers.AddRange(customers);
                context.SaveChanges();

                //context.Orders.AddRange(orders);
                //context.SaveChanges();
            }
        }
 public void Configure(EntityTypeBuilder <Service> builder)
 {
     builder.HasData(serviceFaker.Generate(50));
 }
Example #5
0
        public static IEnumerable <Service> GetServices(int count)
        {
            var serviceFaker = new ServiceFaker();

            return(serviceFaker.Generate(count));
        }