Example #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);
        }
        public ActionResult CreateNewOrder()
        {
            IOrderRepository        orderRepo = new DbOrderRepository();
            CreateNewOrderViewModel orders    = orderRepo.GetData();

            return(View(orders));
        }
Example #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);
        }
Example #4
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))
            {
            }
        }
        //Load all orders obtained from the Interface to the page
        public ActionResult Orders()
        {
            IOrderRepository      orderRepo = new DbOrderRepository();
            List <OrderViewModel> orders    = orderRepo.GetAllOrders();

            return(View(orders));
        }
Example #6
0
        public OrderProductsController()
        {
            var db = new StoreContext();

            orderProductRepo = new DbOrderProductRepository(db);
            orderRepo        = new DbOrderRepository(db);
            productRepo      = new DbProductRepository(db);
        }
Example #7
0
        private static void CalculateOrdersTest()
        {
            ShopContextFactory shopContextFactory = new ShopContextFactory();
            ShopContext        context            = shopContextFactory.Create();

            IOrderRepository orderRepository = new DbOrderRepository(context);
            var orders = orderRepository.Calculate();
        }
Example #8
0
        public InvoiceController()
        {
            StoreContext db = new StoreContext();

            invoiceRepo   = new DbInvoiceDepository(db);
            orderRepo     = new DbOrderRepository(db);
            priceListRepo = new DbPriceListRepository(db);
        }
Example #9
0
 public JsonFileController(DbStoragePlaceRepository dbStoragePlaceRepository, DbOrderRepository dbOrderRepository, DbOrderProductRepository dbOrderProductRepository,
                           DbCustomerAddressRepository dbCustomerAddressRepository, DbProductRepository dbProductRepository)
 {
     storageRepo         = dbStoragePlaceRepository;
     orderRepo           = dbOrderRepository;
     orderProductRepo    = dbOrderProductRepository;
     customerAddressRepo = dbCustomerAddressRepository;
     productRepo         = dbProductRepository;
 }
Example #10
0
        public JsonFileController()
        {
            var db = new StoreContext();

            orderRepo           = new DbOrderRepository(db);
            orderProductRepo    = new DbOrderProductRepository(db);
            storageRepo         = new DbStoragePlaceRepository(db);
            customerAddressRepo = new DbCustomerAddressRepository();
            productRepo         = new DbProductRepository(db);
        }
 public ActionResult CreateNewOrder(int CustomerId, int ProductId, int Quantity, int ProductRating)
 {
     if (ModelState.IsValid)
     {
         IOrderRepository orderRepo = new DbOrderRepository();
         orderRepo.CreateNewOrder(CustomerId, ProductId, Quantity, ProductRating);
         return(RedirectToAction("Orders"));
     }
     return(View());
 }
Example #12
0
        public void Initializer()
        {
            //New up everytime the test runs
            _mockContext            = new Mock <StoreContext>();
            _mockSetStoragePlace    = new Mock <DbSet <StoragePlace> >();
            _mockSetOrder           = new Mock <DbSet <Order> >();
            _mockSetCustomerAddress = new Mock <DbSet <CustomerAddress> >();
            _mockSetOrderProduct    = new Mock <DbSet <OrderProduct> >();
            _mockSetCustomer        = new Mock <DbSet <Customer> >();
            _mockSetAddress         = new Mock <DbSet <Address> >();

            //Add data
            var dataStoragePlace    = ResourceData.StoragePlaces.AsQueryable();
            var dataOrder           = ResourceData.Orders.AsQueryable();
            var dataCustomerAddress = ResourceData.CustomerAddresses.AsQueryable();
            var dataProduct         = ResourceData.OrderProducts.AsQueryable();
            var dataCustomer        = ResourceData.Customers.AsQueryable();
            var dataAddress         = ResourceData.Addresses.AsQueryable();

            //Setup behavior
            var setupDbSp = Helper.SetupDb(_mockSetStoragePlace, dataStoragePlace);
            var setupDbOr = Helper.SetupDb(_mockSetOrder, dataOrder);
            var setupDbCA = Helper.SetupDb(_mockSetCustomerAddress, dataCustomerAddress);
            var setupDbOP = Helper.SetupDb(_mockSetOrderProduct, dataProduct);
            var setupDbCu = Helper.SetupDb(_mockSetCustomer, dataCustomer);
            var setupDbAd = Helper.SetupDb(_mockSetAddress, dataAddress);


            _mockContext.Setup(x => x.StoragePlaces).Returns(setupDbSp.Object);
            _mockContext.Setup(x => x.Orders).Returns(setupDbOr.Object);
            _mockContext.Setup(x => x.CustomerAddresses).Returns(setupDbCA.Object);
            _mockContext.Setup(x => x.OrderProducts).Returns(setupDbOP.Object);
            _mockContext.Setup(x => x.Customers).Returns(setupDbCu.Object);
            _mockContext.Setup(x => x.Addresses).Returns(setupDbAd.Object);

            //This will make the mock version of the db approve any string given to the include method.
            //Without this you will get null reference exception when calling include.
            _mockSetStoragePlace.Setup(x => x.Include(It.IsAny <string>())).Returns(_mockSetStoragePlace.Object);
            _mockSetOrder.Setup(x => x.Include(It.IsAny <string>())).Returns(_mockSetOrder.Object);
            _mockSetCustomerAddress.Setup(x => x.Include(It.IsAny <string>())).Returns(_mockSetCustomerAddress.Object);
            _mockSetOrderProduct.Setup(x => x.Include(It.IsAny <string>())).Returns(_mockSetOrderProduct.Object);
            _mockSetCustomer.Setup(x => x.Include(It.IsAny <string>())).Returns(_mockSetCustomer.Object);
            _mockSetAddress.Setup(x => x.Include(It.IsAny <string>())).Returns(_mockSetAddress.Object);

            //Inject mock data via overload constructor
            var dbStoragePlaceRepository    = new DbStoragePlaceRepository(_mockContext.Object);
            var dbOrderRepository           = new DbOrderRepository(_mockContext.Object);
            var dbOrderProductRepository    = new DbOrderProductRepository(_mockContext.Object);
            var dbCustomerAddressRepository = new DbCustomerAddressRepository(_mockContext.Object);
            var dbProductRepository         = new DbProductRepository(_mockContext.Object);

            //Setup fakerepo via overloaded constructor
            _jsonFileController = new JsonFileController(dbStoragePlaceRepository, dbOrderRepository, dbOrderProductRepository, dbCustomerAddressRepository, dbProductRepository);
        }
Example #13
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);
        }
Example #14
0
        public OrdersController(DbOrderRepository dbOrderRepo, DbAddressRepository dbAddressRepo,
                                DbStoragePlaceRepository dbStorageRepo, DbOrderProductRepository dbOrderProductRepo,
                                DbCustomerRepository dbCustomerRepo, DbPickingOrderRepository dbPickingOrderRepo,
                                DbAlcoholLicenseRepository dbLicenseRepo)
        {
            // TODO: update input for test.
            orderRepo        = dbOrderRepo;
            storageRepo      = dbStorageRepo;
            orderProductRepo = dbOrderProductRepo;
            pickingOrderRepo = dbPickingOrderRepo;

            addressRepo  = dbAddressRepo;
            customerRepo = dbCustomerRepo;
            licenseRepo  = dbLicenseRepo;
        }
Example #15
0
        public OrdersController()
        {
            StoreContext db = new StoreContext();

            orderRepo        = new DbOrderRepository(db);
            storageRepo      = new DbStoragePlaceRepository(db);
            orderProductRepo = new DbOrderProductRepository(db);
            pickingOrderRepo = new DbPickingOrderRepository(db);

            addressRepo         = new DbAddressRepository(db);
            customerRepo        = new DbCustomerRepository(db);
            licenseRepo         = new DbAlcoholLicenseRepository(db);
            productRepository   = new DbProductRepository(db);
            priceListRepository = new DbPriceListRepository(db);
        }
Example #16
0
 public OrderProductsController(DbOrderProductRepository dbOrderProductRepository, DbOrderRepository dbOrderRepository, DbProductRepository dbProductRepository)
 {
     orderProductRepo = dbOrderProductRepository;
     orderRepo        = dbOrderRepository;
     productRepo      = dbProductRepository;
 }