private void SeedDatabase()
        {
            var context = new GlovoDbContext(ContextOptions);

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            _users = new List <User>()
            {
                new User("u1", "*****@*****.**", "password-u1", new Location(0, 0), UserRole.Regular)
                {
                    Id = 1
                },
                new User("u2", "*****@*****.**", "password-u2", new Location(0, 0), UserRole.Regular)
                {
                    Id = 2
                },
                new User("a1", "*****@*****.**", "password-a1", new Location(0, 0), UserRole.Administrator)
                {
                    Id = 3
                }
            };

            context.AddRange(_users);
            context.SaveChanges();
        }
Example #2
0
        private void SeedDatabase()
        {
            var context = new GlovoDbContext(ContextOptions);

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            _restaurants = new List <Restaurant>()
            {
                new Restaurant("name-r1", "imgPath-u1", new Location(1, 0))
                {
                    Id = 1
                },
                new Restaurant("name-r2", "imgPath-u2", new Location(2, 0))
                {
                    Id = 2
                },
                new Restaurant("name-r3", "imgPath-u3", new Location(3, 0))
                {
                    Id = 3
                },
                new Restaurant("name-r4", "imgPath-u4", new Location(4, 0))
                {
                    Id = 4
                },
                new Restaurant("name-r5", "imgPath-u5", new Location(5, 0))
                {
                    Id = 5
                }
            };

            context.AddRange(_restaurants);
            context.SaveChanges();
        }
Example #3
0
        private void SeedDatabase()
        {
            var context = new GlovoDbContext(ContextOptions);

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            _restaurants = new List <Restaurant>()
            {
                new Restaurant("name-r1", "imgPath-u1", new Location(1, 0))
                {
                    Id = 1
                },
                new Restaurant("name-r2", "imgPath-u2", new Location(2, 0))
                {
                    Id = 2
                }
            };
            _products = new List <Product>()
            {
                new Product("name-p1", "imgPath-p1", "desc-p1", 10, 1, "Menu")
                {
                    Id = 1
                },
                new Product("name-p2", "imgPath-p2", "desc-p2", 20, 2, "Menu")
                {
                    Id = 2
                },
                new Product("name-p3", "imgPath-p3", "desc-p3", 5, 2, "Menu")
                {
                    Id = 3
                },
                new Product("name-p4", "imgPath-p4", "desc-p4", 15, 2, "Menu")
                {
                    Id = 4
                },
                new Product("name-p5", "imgPath-p5", "desc-p5", 12, 2, "Menu")
                {
                    Id = 5
                }
            };

            context.AddRange(_restaurants);
            context.SaveChanges();
            context.AddRange(_products);
            context.SaveChanges();
        }
        private UserAccountRecoveryController CreateFakeUserAccountRecoveryController(User loggedUser = null)
        {
            //Create fake DBContext
            var context = new GlovoDbContext(ContextOptions);

            //Create fake HttpContextAccessor
            var httpContext         = new DefaultHttpContext();
            var httpContextAccessor = new HttpContextAccessor {
                HttpContext = httpContext
            };

            //Add logged user to HttpContextAccessor in case it is needed
            if (loggedUser != null)
            {
                httpContextAccessor.HttpContext.Items["User"] = loggedUser;
            }

            //Create RestApiUsersService instance with fake DBContext and HttpContextAccessor
            _usersService = new RestApiUsersService(context, httpContextAccessor);

            //Create mapper with UsersProfile
            var mapper = new MapperConfiguration(cfg => {
                cfg.AddProfile <LocationsProfile>();
                cfg.AddProfile <OrdersProductsProfile>();
                cfg.AddProfile <OrdersProfile>();
                cfg.AddProfile <ProductsProfile>();
                cfg.AddProfile <RestaurantsProfile>();
                cfg.AddProfile <UsersProfile>();
            }).CreateMapper();

            //Create AppConfiguration options using fake secret string
            _testApiSecret = RandomString(1024);
            IOptions <AppConfiguration> appConfigOptions = new OptionsWrapper <AppConfiguration>(
                new AppConfiguration {
                Secret = _testApiSecret
            }
                );

            //Create UsersController instance with the RestApiUsersService instance, the mapper and the
            //fake AppConfiguration
            var usersController = new UserAccountRecoveryController(_usersService, mapper, appConfigOptions)
            {
                ControllerContext = { HttpContext = httpContext }
            };

            return(usersController);
        }
        private OrdersOfRestaurantController CreateFakeOrdersOfRestaurantController(User loggedUser = null)
        {
            //Create fake DBContext
            var context = new GlovoDbContext(ContextOptions);

            //Create fake HttpContextAccessor
            var httpContext         = new DefaultHttpContext();
            var httpContextAccessor = new HttpContextAccessor {
                HttpContext = httpContext
            };

            //Add logged user to HttpContextAccessor in case it is needed
            if (loggedUser != null)
            {
                httpContextAccessor.HttpContext.Items["User"] = loggedUser;
            }

            //Create RestApiRestaurantsService instance with fake DBContext and HttpContextAccessor
            _ordersService = new RestApiOrdersService(context, httpContextAccessor);

            //Create mapper with UsersProfile
            var mapper = new MapperConfiguration(cfg => {
                cfg.AddProfile <LocationsProfile>();
                cfg.AddProfile <OrdersProductsProfile>();
                cfg.AddProfile <OrdersProfile>();
                cfg.AddProfile <ProductsProfile>();
                cfg.AddProfile <RestaurantsProfile>();
                cfg.AddProfile <UsersProfile>();
            }).CreateMapper();

            //Create UsersController instance with the RestApiRestaurantsService instance and the mapper
            var ordersController = new OrdersOfRestaurantController(_ordersService, mapper)
            {
                ControllerContext = { HttpContext = httpContext }
            };

            return(ordersController);
        }
Example #6
0
        private ProductsOfRestaurantController CreateFakeProductsOfRestaurantController()
        {
            //Create fake DBContext
            var context = new GlovoDbContext(ContextOptions);

            //Create RestApiRestaurantsService instance with fake DBContext
            _productsService = new RestApiProductsService(context);

            //Create mapper with UsersProfile
            var mapper = new MapperConfiguration(cfg => {
                cfg.AddProfile <LocationsProfile>();
                cfg.AddProfile <OrdersProductsProfile>();
                cfg.AddProfile <OrdersProfile>();
                cfg.AddProfile <ProductsProfile>();
                cfg.AddProfile <RestaurantsProfile>();
                cfg.AddProfile <UsersProfile>();
            }).CreateMapper();

            //Create UsersController instance with the RestApiRestaurantsService instance and the mapper
            var productsController = new ProductsOfRestaurantController(_productsService, mapper);

            return(productsController);
        }
 public RestApiRestaurantsService(GlovoDbContext context)
 {
     _context = context;
 }
        private void SeedDatabase()
        {
            var context = new GlovoDbContext(ContextOptions);

            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            _restaurants = new List <Restaurant>()
            {
                new Restaurant("name-r1", "imgPath-u1", new Location(1, 0))
                {
                    Id = 1
                },
                new Restaurant("name-r2", "imgPath-u2", new Location(2, 0))
                {
                    Id = 2
                }
            };
            _products = new List <Product>()
            {
                new Product("name-p1", "imgPath-p1", "desc-p1", 10, 1, "Menu")
                {
                    Id = 1
                },
                new Product("name-p2", "imgPath-p2", "desc-p2", 20, 2, "Menu")
                {
                    Id = 2
                },
                new Product("name-p3", "imgPath-p3", "desc-p3", 5, 2, "Menu")
                {
                    Id = 3
                },
                new Product("name-p4", "imgPath-p4", "desc-p4", 15, 2, "Menu")
                {
                    Id = 4
                },
                new Product("name-p5", "imgPath-p5", "desc-p5", 12, 2, "Menu")
                {
                    Id = 5
                }
            };
            _users = new List <User>()
            {
                new User("u1", "*****@*****.**", "password-u1", new Location(0, 0), UserRole.Regular)
                {
                    Id = 1
                },
                new User("u2", "*****@*****.**", "password-u2", new Location(0, 0), UserRole.Regular)
                {
                    Id = 2
                },
                new User("a1", "*****@*****.**", "password-a1", new Location(0, 0), UserRole.Administrator)
                {
                    Id = 3
                }
            };
            _orders = new List <Order>()
            {
                new Order(DateTime.Parse("2020-01-01 12:00:00"), 1, 1)
                {
                    Id = 1
                },
                new Order(DateTime.Parse("2020-01-02 12:00:00"), 1, 2)
                {
                    Id = 2
                },
                new Order(DateTime.Parse("2020-01-03 12:00:00"), 2, 2)
                {
                    Id = 3
                }
            };
            _orderProducts = new List <OrderProduct>()
            {
                new OrderProduct(1, 1, 5),
                new OrderProduct(2, 2, 5),
                new OrderProduct(3, 2, 2),
                new OrderProduct(3, 3, 3),
                new OrderProduct(3, 4, 4),
                new OrderProduct(3, 5, 5)
            };

            context.AddRange(_restaurants);
            context.SaveChanges();
            context.AddRange(_products);
            context.SaveChanges();
            context.AddRange(_users);
            context.SaveChanges();
            context.AddRange(_orders);
            context.SaveChanges();
            context.AddRange(_orderProducts);
            context.SaveChanges();
        }
Example #9
0
 public RestApiOrdersService(GlovoDbContext context, IHttpContextAccessor httpContextAccessor)
 {
     _context             = context;
     _httpContextAccessor = httpContextAccessor;
 }
Example #10
0
 public RestApiProductsService(GlovoDbContext context)
 {
     _context = context;
 }