private void GetAllProductsOfRestaurantTest() { ProductsOfRestaurantController productsController = CreateFakeProductsOfRestaurantController(); //Retrieving all products of restaurant of first category var response = productsController.GetAllProductsOfRestaurant(_restaurants[0].Id); Assert.IsType <OkObjectResult>(response.Result); //Check same number of products with queried category var value = (IEnumerable <ProductGroupModel>)((OkObjectResult)response.Result).Value; Assert.Equal( _products.FindAll(p => p.RestaurantId == _restaurants[0].Id && p.Category == "Menu").Count, value.FirstOrDefault(pgm => pgm.Category == "Menu").Products.Count() ); }
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); }