public ActionResult AddIngredient(int id) { var ingServ = new IngredientService(); var base_ = ingServ.GetAll(); var ingredients = base_.Ingredients; var measurements = base_.Measurements; var selectIng = new List <SelectListItem>(); var selectMea = new List <SelectListItem>(); foreach (var ing in ingredients) { selectIng.Add(new SelectListItem { Value = ing.IngredientName, Text = ing.IngredientId.ToString() }); } foreach (var mea in measurements) { selectMea.Add(new SelectListItem { Value = mea.MeasurementTypeName, Text = mea.MeasurementTypeId.ToString() }); } ViewBag.Ingredients = selectIng; ViewBag.Measurements = selectMea; ViewBag.Id = id; return(View()); }
public DishController(ApplicationDbContext context, ILogger <DishController> logger, IngredientService ingredientService, DishService dishService) { _context = context; _logger = logger; _ingredientService = ingredientService; _dishService = dishService; }
public ActionResult EditIngredient(int recipeId, string ingredient) { var ingServ = new IngredientService(); var base_ = ingServ.GetAll(); var ingredients = base_.Ingredients; var measurements = base_.Measurements; var selectIng = new List <SelectListItem>(); var selectMea = new List <SelectListItem>(); foreach (var ing in ingredients) { selectIng.Add(new SelectListItem { Value = ing.IngredientName, Text = ing.IngredientId.ToString() }); } foreach (var mea in measurements) { selectMea.Add(new SelectListItem { Value = mea.MeasurementTypeName, Text = mea.MeasurementTypeId.ToString() }); } ViewBag.Ingredients = selectIng; ViewBag.Measurements = selectMea; var ingredientId = ingServ.GetByName(ingredient); ViewBag.recipeId = recipeId; ViewBag.ingredientId = ingredientId; return(View(ingServ.GetRecipeIngredientById(recipeId, ingredientId))); }
public async Task Details_ReturnsDishDetail() { // Arrange var dishId = 1; var mockLogger = new Mock <ILogger <DishController> >(); var mockIngredientService = new IngredientService(_context); var mockDishService = new DishService(_context); var controller = new DishController(_context, mockLogger.Object, mockIngredientService, mockDishService); // Act var result = await controller.Details(dishId); // Assert var viewResult = Assert.IsType <ViewResult>(result); Assert.Null(viewResult.ViewName); Assert.NotNull(viewResult.ViewData); var viewModel = Assert.IsType <Dish>(viewResult.ViewData.Model); Assert.NotNull(viewModel.Category); var category = _context.Categories.SingleOrDefault(g => g.CategoryId == viewModel.CategoryId); Assert.NotNull(category); }
public DishController(WebshopDbContext context, AdminService adminService, CategoryService categoryService, IngredientService ingredientService) { _context = context; _adminService = adminService; _categoryService = categoryService; _ingredientService = ingredientService; }
public async Task ReturnIngredient_WhenFound() { //Arrange var mockDatetimeProvider = new Mock <IDateTimeProvider>(); var mockMapper = new Mock <IIngredientMapper>(); mockMapper.Setup(i => i.MapToIngredientDTO(It.IsAny <Ingredient>())) .Returns <Ingredient>(i => new IngredientDTO { Id = i.Id, Name = i.Name }); var mockCocktailMapper = new Mock <ICocktailMapper>(); var options = Utils.GetOptions(nameof(ReturnIngredient_WhenFound)); var expected = new IngredientDTO { Id = 1, Name = "Rum" }; Utils.GetInMemoryDataBase(options); //Act & Assert using (var assertContext = new CocktailMagicianContext(options)) { var sut = new IngredientService(mockDatetimeProvider.Object, mockMapper.Object, mockCocktailMapper.Object, assertContext); var result = await sut.GetIngredientAsync(1); Assert.AreEqual(expected.Id, result.Id); Assert.AreEqual(expected.Name, result.Name); } }
public async Task ReturnsIngredientN() { string ingredientName = "Ingredient"; byte type = 0; var options = TestUtilities.GetOptions(nameof(ReturnsIngredientN)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Ingredients.Add(new Ingredient() { Name = ingredientName, Primary = type }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(assertContext); var ing = await sut.GetIngredientByNameTypeAsync(ingredientName, type); Assert.IsNotNull(ing); Assert.AreEqual(type, ing.Primary); Assert.AreEqual(ingredientName.ToLower(), ing.Name.ToLower()); } }
public ActionResult UpdateRecipeWithIngredients(int id) { var iservice = new IngredientService(); List <Ingredient> ingredients = iservice.GetIngredientList().ToList(); var query = from i in ingredients select new SelectListItem() { Value = i.IngredientId.ToString(), Text = i.IngredientName }; ViewBag.IngredientId = query; var service = CreateRecipeService(); var detail = service.GetRecipeById(id); var model = new RecipeEdit { RecipeId = detail.RecipeId, RecipeName = detail.RecipeName, Ingredients = detail.Ingredients, }; return(View(model)); }
public async Task ReturnsNoCocktailIngredients() { int cocktailId = 1; byte secondary = 0; var options = TestUtilities.GetOptions(nameof(ReturnsNoCocktailIngredients)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Ingredients.Add(new Ingredient() { Name = "Se Taq", Primary = secondary }); arrangeContext.Ingredients.Add(new Ingredient() { Name = "Se Taq", Primary = secondary }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(assertContext); var ingredients = await sut.GetCocktailIngredientsByCocktailAsync(cocktailId); Assert.AreEqual(0, ingredients.Count); } }
public async Task ReturnsNoIngredientsN() { string ingredientName = "Ingredient"; string wrongName = "se taq"; byte type = 1; var options = TestUtilities.GetOptions(nameof(ReturnsNoIngredientsN)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Ingredients.Add(new Ingredient() { Name = ingredientName, Primary = type }); arrangeContext.Ingredients.Add(new Ingredient() { Name = ingredientName, Primary = type }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(assertContext); var ing = await sut.FindIngredientsByNameAsync(wrongName); Assert.AreEqual(0, ing.Count); } }
public async Task RemoveIngredient() { int ingId = 1; int ingId2 = 2; string ingredientName = "Ingredient"; byte type = 0; var options = TestUtilities.GetOptions(nameof(RemoveIngredient)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Ingredients.Add(new Ingredient() { Id = ingId, Name = ingredientName, Primary = type }); arrangeContext.Ingredients.Add(new Ingredient() { Id = ingId2, Name = ingredientName, Primary = type }); arrangeContext.SaveChanges(); } using (var actContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(actContext); await sut.RemoveIngredientAsync(ingId2); } using (var assertContext = new CocktailDatabaseContext(options)) { var ingredient = assertContext.Ingredients.FirstOrDefault(p => p.Id == ingId2); Assert.IsNull(ingredient); } }
public async Task ReturnFalse_WhenIdNotFound() { //Arrange var mockDatetimeProvider = new Mock <IDateTimeProvider>(); var mockMapper = new Mock <IIngredientMapper>(); mockMapper.Setup(i => i.MapToIngredientDTO(It.IsAny <Ingredient>())) .Returns <Ingredient>(i => new IngredientDTO { Name = i.Name }); var mockCocktailMapper = new Mock <ICocktailMapper>(); var options = Utils.GetOptions(nameof(ReturnFalse_WhenIdNotFound)); Utils.GetInMemoryDataBase(options); //Act & Assert using (var assertContext = new CocktailMagicianContext(options)) { var sut = new IngredientService(mockDatetimeProvider.Object, mockMapper.Object, mockCocktailMapper.Object, assertContext); var result = await sut.DeleteIngredientAsync(9); Assert.IsFalse(result); } }
public void Remove_BasicIngredient_From_Database() { //Arrange _options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: _databaseName) .Options; //Act using (var context = new ApplicationContext(_options)) { _ingredientRepository = new EntityFrameworkRepository <Ingredient>(context); var ingredientService = new IngredientService(_ingredientRepository); ingredientService.Delete(1); } //Assert //Use a separate instance of the context to verify correct data was saved to database using (var context = new ApplicationContext(_options)) { _ingredientRepository = new EntityFrameworkRepository <Ingredient>(context); var ingredientService = new IngredientService(_ingredientRepository); Assert.AreEqual(0, ingredientService.GetAll().Count()); Ingredient addedIngredient = ingredientService.GetAll().FirstOrDefault(); Assert.IsNull(addedIngredient); } }
public void Insert_BasicIngredient_Into_Database() { //Arrange _options = new DbContextOptionsBuilder <ApplicationContext>() .UseInMemoryDatabase(databaseName: _databaseName) .Options; //Act using (var context = new ApplicationContext(_options)) { _ingredientRepository = new EntityFrameworkRepository <Ingredient>(context); var ingredientService = new IngredientService(_ingredientRepository); ingredientService.Insert( Ingredient: new Ingredient() { Name = "Sauce", Amount = 1.0, Measurement = "Cup" } ); } //Assert //Use a separate instance of the context to verify correct data was saved to database using (var context = new ApplicationContext(_options)) { _ingredientRepository = new EntityFrameworkRepository <Ingredient>(context); var ingredientService = new IngredientService(_ingredientRepository); Assert.AreEqual(1, ingredientService.GetAll().Count()); Ingredient addedIngredient = ingredientService.GetAll().First(); Assert.AreEqual("Sauce", addedIngredient.Name); Assert.AreEqual(1.0, addedIngredient.Amount); Assert.AreEqual("Cup", addedIngredient.Measurement); } }
public async Task ReturnsEmptyList() { var keyword = "testName"; var pageSize = 5; var options = TestUtilities.GetOptions(nameof(ReturnsEmptyList)); using (var arrangeContext = new CocktailDatabaseContext(options)) { arrangeContext.Ingredients.Add(new Ingredient() { Id = 1, Name = "se taq" }); arrangeContext.Ingredients.Add(new Ingredient() { Id = 2, Name = "se taq" }); arrangeContext.SaveChanges(); } using (var assertContext = new CocktailDatabaseContext(options)) { var sut = new IngredientService(assertContext); var result = await sut.FindIngredientsForCatalogAsync(keyword, 1, pageSize); Assert.IsTrue(!result.Item1.Any()); } }
public async Task Create_Correct_Ingredient() { var options = Utils.GetOptions(nameof(Create_Correct_Ingredient)); using (var arrangeContext = new CMContext(options)) { var sut = new IngredientService(arrangeContext); var ingredientDTO = await sut.CreateIngredient( new IngredientDTO { Id = Guid.Parse("1b98e50e-8314-4b1e-82df-491c3c8d086f"), Name = "Gin", Abv = 40, Description = "Gin is a distilled alcoholic drink that derives its " + "predominant flavour from juniper berries (Juniperus communis). " + "Gin is one of the broadest categories of spirits, all of various origins, styles," + " and flavour profiles, that revolve around juniper as a common ingredient.", TypeId = Guid.Parse("24cd3f18-f0a8-4f66-bc5b-2108e099cf53"), }); } using (var assertContext = new CMContext(options)) { Assert.AreEqual("Gin", assertContext.Ingredients.First().Name); } }
public IHttpActionResult Get() { IngredientService ingredientService = CreateIngredientService(); var ingredients = ingredientService.GetIngredients(); return(Ok(ingredients)); }
public IngredientsController(IngredientRepository ingredientRepository, PubChemService pubChemService, IngredientService ingredientService) { _ingredientRepository = ingredientRepository; _ingredientService = ingredientService; _pubChemService = pubChemService; }
private void InitData(MealPlannerDbContext dbContext) { Name = "Food store"; Service = new IngredientService { Context = dbContext }; }
// GET: Ingredient public ActionResult Index() { var userId = Guid.Parse(User.Identity.GetUserId()); var service = new IngredientService(userId); var model = service.GetIngredients(); return(View(model)); }
public ActionResult DeleteIngredientFromRecipe(int recipeId, string ingredient) { var ingSrv = new IngredientService(); var ingredientId = ingSrv.GetByName(ingredient); service.DeleteIngredientFromRecipe(recipeId, ingredientId); return(RedirectToAction("Edit", new { id = recipeId })); }
public RecipeApplicationService(AuthorService authorService, RecipeService recipeService, IngredientService ingredientService) { _authorService = authorService; _recipeService = recipeService; _ingredientService = ingredientService; IngredientsService = ingredientService; }
public RecipeDetailsController(RecipeDetailsService recipeDetailsService, IngredientService ingredientService, UnitsService unitsService, StoresService storesService) { _recipeDetailsService = recipeDetailsService; _ingredientService = ingredientService; _unitsService = unitsService; _storesService = storesService; }
private void InsertIngredient_Load(object sender, EventArgs e) { IngredientService ingredientService = new IngredientService(); List <Ingredient> ingredients = ingredientService.GetAll(); dataGridView1.DataSource = ingredients; }
private void AllIngredientsBtn_Click(object sender, EventArgs e) { IngredientService ingredientService = new IngredientService(); List <Ingredient> ingredients = ingredientService.GetAll(); dataGridView1.DataSource = ingredients; }
public void GetAllIngredients() { using var context = new InMemoryDbContext(); var ingredientActionMock = new Mock <IIngredientAction>(); var testee = new IngredientService(ingredientActionMock.Object, context); testee.GetAllIngredients(); ingredientActionMock.Verify(x => x.GetAllIngredients(), Times.Once); }
public IngredientChoosePage() { InitializeComponent(); SetComponents(); ingredientService = new IngredientService(); IngredientList = ingredientService.GetIngredientList(); MyListView.ItemsSource = IngredientList; }
public RecipeController() { recipeService = new RecipeService(); categoryService = new CategoryService(); subcategoryService = new SubcategoryService(); ingredientService = new IngredientService(); instructionsService = new InstructionsService(); ratingService = new RatingService(); commentService = new CommentService(); }
public void GetIngredientTypeNameByIdWithoutData() { var ingredientTypeRepository = new Mock <IRepository <IngredientType> >(); var ingredientRepository = new Mock <IRepository <Ingredient> >(); var service = new IngredientService(ingredientTypeRepository.Object, ingredientRepository.Object); var actualResult = service.GetIngredientTypeNameById(1); Assert.True(actualResult == null, "Get Ingredient Type Name By Id without data should return true."); }
public async Task ReturnIngredientsSortedByNameDescending() { //Arrange var mockDateTimeProvider = new Mock <IDateTimeProvider>(); var mockCocktailMapper = new Mock <ICocktailMapper>(); var mockIngMapper = new Mock <IIngredientMapper>(); mockIngMapper.Setup(i => i.MapToIngredientDTO(It.IsAny <Ingredient>())) .Returns <Ingredient>(i => new IngredientDTO { Name = i.Name }); var options = Utils.GetOptions(nameof(ReturnIngredientsSortedByNameDescending)); var sort = "name"; var direction = "desc"; var expected = new List <IngredientDTO> { new IngredientDTO { Name = "Tonic" }, new IngredientDTO { Name = "Soda" }, new IngredientDTO { Name = "Rum" }, new IngredientDTO { Name = "Mineral Water" }, new IngredientDTO { Name = "Dry Gin" }, }; Utils.GetInMemoryDataBase(options); //Act & Assert using (var assertContext = new CocktailMagicianContext(options)) { var sut = new IngredientService(mockDateTimeProvider.Object, mockIngMapper.Object, mockCocktailMapper.Object, assertContext); var result = await sut.ListAllIngredientsAsync(0, 10, null, sort, direction); Assert.AreEqual(expected.Count, result.Count); for (int i = 0; i < expected.Count; i++) { Assert.AreEqual(expected[i].Name, result[i].Name); } } }