public void Throw_WhenThePassedRecipeIsNull() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); var ingredientsServiceMock = new Mock <IIngredientsService>(); RecipesService recipesService = new RecipesService(dataMock.Object, ingredientsServiceMock.Object); Recipe recipe = null; //Act & Assert Assert.Throws <ArgumentNullException>(() => recipesService.EditRecipe(recipe)); }
public void InvokeDataCommitOnce_WhenThePassedArgumentsAreValid() { //Arrange var dataMock = new Mock <IHomeMadeFoodData>(); var ingredientsServiceMock = new Mock <IIngredientsService>(); RecipesService recipesService = new RecipesService(dataMock.Object, ingredientsServiceMock.Object); List <string> ingredientNames = new List <string>() { "Tomato" }; List <double> ingredientQuantities = new List <double>() { 1.200 }; List <decimal> ingredientPrices = new List <decimal>() { 4.80m }; List <Guid> foodCategories = new List <Guid>() { Guid.NewGuid() }; Guid recipeId = Guid.NewGuid(); Recipe recipe = new Recipe() { Id = recipeId, Title = "Title Of A New Recipe", Describtion = "This is a decsribtion", Instruction = "Instructions of the recipe", DishType = DishType.MainDish, Ingredients = new List <Ingredient>() { new Ingredient() { Id = Guid.NewGuid(), Name = ingredientNames[0], FoodCategoryId = foodCategories[0], RecipeId = recipeId, QuantityInMeasuringUnit = ingredientQuantities[0], PricePerMeasuringUnit = ingredientPrices[0] } } }; dataMock.Setup(x => x.Recipes.Update(It.IsAny <Recipe>())); //Act recipesService.EditRecipe(recipe); //Assert dataMock.Verify(x => x.SaveChanges(), Times.Once); }
public async Task EditShouldChangeRecipe() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; AutoMapperConfig.RegisterMappings(Assembly.Load("CookingBook.Web.ViewModels")); var dbContext = new ApplicationDbContext(options); var recipeRepo = new EfDeletableEntityRepository <Recipe>(dbContext); var nutritionRepo = new EfDeletableEntityRepository <NutritionValue>(dbContext); var productRepo = new EfDeletableEntityRepository <Product>(dbContext); var userRepo = new EfDeletableEntityRepository <ApplicationUser>(dbContext); var service = new RecipesService(recipeRepo, nutritionRepo, productRepo, userRepo); var category = new Category(); var nutrValue = new NutritionValue(); var user = new ApplicationUser(); var prod = new Collection <RecipeByIdProductsViewModel>(); var recipeCreateViewModel = new RecipeCreateViewModel { CategoryId = 1, CookProcedure = "cookProc", Photo = "photo", Serving = 1, Title = "addNew", CookTime = 2, NutritionValue = new RecipeCreateNutritionValuesViewModel { Calories = 1, Carbohydrates = 1, Fats = 1, Fiber = 1, Protein = 1, Salt = 1, Sugar = 1 }, Products = new List <RecipeCreateProductsViewModel>(), }; string userId = "trayan"; StringValues sv = new StringValues("one"); StringValues sk = new StringValues("1"); var recipeResult = await service.CreateAsync(recipeCreateViewModel, userId, sv, sk); var model = new RecipeEditViewModel { Id = recipeResult, CategoryId = 5, CookProcedure = "five", CookTime = 5, Photo = "fifthPhoto", Serving = 5, Title = "fifthEdit", }; await service.EditRecipe(model, userId); Assert.Equal(5, dbContext.Recipes.FirstOrDefault(x => x.Id == recipeResult).CategoryId); }