示例#1
0
        private static void AddOrderTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            ICustomerRepository customerRepository = new DbCustomerRepository(context);
            IOrderRepository    orderRepository    = new DbOrderRepository(context);

            Customer customer = customerRepository.Get(4);

            Order order = new Order
            {
                Customer    = customer,
                OrderNumber = "ZAM 001/2021"
            };

            Product product = new Product {
                Name = "EF6 in Action", BarCode = "54543534534", Color = "Black", UnitPrice = 199.99m
            };

            order.Details.Add(new OrderDetail {
                Item = product, Quantity = 5, UnitPrice = product.UnitPrice
            });

            orderRepository.Add(order);
        }
示例#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);
        }
示例#3
0
        private static void GetOrdersTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            IOrderRepository orderRepository = new DbOrderRepository(context);
            var orders = orderRepository.Get();

            if (orders.Any())
            {
            }
            else
            {
                Console.WriteLine("Brak zamówień");
            }


            if (orders.Any(c => c.Customer.Gender == Gender.Female))
            {
            }

            if (orders.All(c => c.Customer.Gender == Gender.Male))
            {
            }
        }
示例#4
0
        private static void CalculateOrdersTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            IOrderRepository orderRepository = new DbOrderRepository(context);
            var orders = orderRepository.Calculate();
        }
示例#5
0
        private static async Task GetServiceAsyncTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();
            IServiceRepository serviceRepository  = new DbServiceRepository(context);

            var services = await serviceRepository.GetAsync();
        }
示例#6
0
        private static void RemoveCustomerTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            ICustomerRepository customerRepository = new DbCustomerRepository(context);

            customerRepository.Remove(247);
        }
示例#7
0
        private static void GetCustomersByGenderTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();


            ICustomerRepository customerRepository = new DbCustomerRepository(context);

            var customersByGender = customerRepository.GetByGenders();
        }
示例#8
0
        private static void GetProductByColorTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            IProductRepository productRepository = new DbProductRepository(context);

            string color = "red' OR 1=1 --";

            var products = productRepository.GetByColor(color);
        }
示例#9
0
        private static void AddRangeCustomersTest()
        {
            CustomerFaker customerFaker = new CustomerFaker(new AddressFaker());

            var customers = customerFaker.Generate(100);

            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            ICustomerRepository customerRepository = new DbCustomerRepository(context);

            customerRepository.AddRange(customers);
        }
示例#10
0
        private static void GetProductByBarCodeTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            IProductRepository productRepository = new DbProductRepository(context);

            string barcode = "3845437691226;DROP VIEW CustomersByGender";

            Product product = productRepository.GetByBarCode(barcode);

            Console.WriteLine(product.Name);
        }
示例#11
0
        private static void GetOrderSearchCriteriaTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            OrderSearchCriteria searchCriteria = new OrderSearchCriteria
            {
                From = DateTime.Parse("2021-01-01"),
                To   = DateTime.Parse("2021-05-01"),
            };

            IOrderRepository orderRepository = new DbOrderRepository(context);

            var orders = orderRepository.Get(searchCriteria);
        }
示例#12
0
        private static void UpdateCustomerTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            ICustomerRepository customerRepository = new DbCustomerRepository(context);


            Console.WriteLine("Type firstname: ");
            string firstname = Console.ReadLine();

            Customer customer = new Customer {
                Id = 225, FirstName = firstname, LastName = "Smith", Gender = Gender.Female
            };

            Console.WriteLine(customer.FirstName);


            customerRepository.Update(customer);
        }
示例#13
0
        private static void AddCustomerTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            Customer customer = new Customer
            {
                FirstName   = "John",
                LastName    = "Smith",
                Gender      = Gender.Male,
                ShipAddress = new Address {
                    City = "Warsaw", Country = "Poland", Street = "Towarowa", PostCode = "00-111"
                },
                InvoiceAddress = new Address {
                    City = "Opole", Country = "Poland", Street = "Dworcowa", PostCode = "99-200"
                },
            };


            ICustomerRepository customerRepository = new DbCustomerRepository(context);

            customerRepository.Add(customer);
        }
示例#14
0
        private static void DocumentationTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            var metadata = context.ObjectContext.MetadataWorkspace;

            // Storage
            Console.WriteLine("######## Storage ########");
            var items = metadata.GetItems <EntityType>(DataSpace.SSpace);

            foreach (var item in items)
            {
                Console.WriteLine("----------------------------");
                Console.WriteLine($"Table name {item.Name}");
                Console.WriteLine("----------------------------");

                Console.WriteLine("Keys");

                foreach (var key in item.KeyMembers)
                {
                    Console.WriteLine($"{key.Name} {key.TypeUsage.EdmType.FullName}");
                }

                Console.WriteLine("Properties");
                foreach (var property in item.Properties)
                {
                    Console.WriteLine($"{property.Name} {property.TypeUsage.EdmType.FullName}");
                }
            }

            // Conceptual
            Console.WriteLine("######## Conceptual ########");
            var entities = metadata.GetItems <EntityType>(DataSpace.CSpace);

            foreach (var entity in entities)
            {
                Console.WriteLine("----------------------------");
                Console.WriteLine($"Entity name {entity.Name}");
                Console.WriteLine("----------------------------");

                Console.WriteLine("Keys");

                foreach (var key in entity.KeyMembers)
                {
                    Console.WriteLine($"{key.Name} {key.TypeUsage.EdmType.FullName}");
                }

                Console.WriteLine("Properties");
                foreach (var property in entity.Properties)
                {
                    Console.WriteLine($"{property.Name} {property.TypeUsage.EdmType.FullName}");
                }

                Console.WriteLine("Navigation Properties");
                foreach (var property in entity.NavigationProperties)
                {
                    Console.WriteLine($"{property.Name} {property.TypeUsage.EdmType.FullName}");
                }
            }
        }