Esempio n. 1
0
        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());
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
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);
        }
            public void ShouldApplyDiscountToValidProducts(
                DiscountService sut)
            {
                // product1 is valid for discount, product2 is not.
                ProductFaker productFaker = new ProductFaker();
                IProduct     product1     = productFaker.Generate();
                IProduct     product2     = productFaker.Generate();

                Price            discountPrice = new Price(product2.Price * 0.5m);
                IProductDiscount discount      = new FakeProductDiscount(discountPrice, product2);

                sut.AddProductDiscount(discount);

                Price result = sut.ApplyDiscounts(new[] { product1, product2 });

                result.Should().Be(new Price(product1.Price + discountPrice));
            }
Esempio n. 5
0
        public async Task <IActionResult> Generate([FromForm] int count)
        {
            ProductFaker productFaker = new ProductFaker();
            IEnumerable <ProductWriteModel> generatedProducts = productFaker.Generate(count);

            await Task.WhenAll(
                generatedProducts.Select(this.productRepository.Create));

            return(this.RedirectToAction("Index"));
        }
        public void Configure(EntityTypeBuilder <Product> builder)
        {
            builder
            .Property(p => p.SerialNumber)
            .IsRequired()
            .HasMaxLength(10)
            .IsUnicode(false);

            builder
            .Property(p => p.Color)
            .HasMaxLength(20);


            //builder.HasData(
            //    new Product { Id = 1, Name = "Product 1", Color = "red", UnitPrice = 2.5m },
            //    new Product { Id = 1, Name = "Product 1", Color = "red", UnitPrice = 2.5m },
            //    new Product { Id = 1, Name = "Product 1", Color = "red", UnitPrice = 2.5m }
            //    );

            builder.HasData(productFaker.Generate(100));
        }
Esempio n. 7
0
        public static IEnumerable <Product> GetProducts(int count)
        {
            var productFaker = new ProductFaker();

            return(productFaker.Generate(count));
        }