// GET: /Recipe/Display/ public ActionResult Display(int recipeId, double scaler = 1, bool?isCelsius = null) { string key = recipeId.ToString(); if (GlobalCachingProvider.Instance.IsCached(key)) { //This casting is bad should fix later on down the road currentRecipe = (Recipe)GlobalCachingProvider.Instance.GetItem(key); } else { IRecipeDBManager db = new RecipeContext(); currentRecipe = db.GetRecipeById(recipeId); GlobalCachingProvider.Instance.AddItem(key, currentRecipe); } RecipeViewModel viewModel; if (isCelsius == null) { viewModel = new RecipeViewModel(currentRecipe.ScaleRecipe(scaler), scaler); } else { viewModel = new RecipeViewModel(currentRecipe.ScaleRecipe(scaler), scaler, (bool)isCelsius); } return(View(viewModel)); }
public void TestGetRecipeById() { IRecipeDBManager db = new RecipeContext(); Recipe recipe = db.GetRecipeById(1); Assert.NotNull(recipe); Assert.NotNull(recipe.Ingredients); Assert.NotNull(recipe.Utensils); Assert.AreEqual(recipe.RecipeId, 1); Assert.AreEqual(recipe.Utensils.Count, 0); Assert.AreEqual(recipe.Ingredients.Count, 4); recipe = db.GetRecipeById(0); Assert.NotNull(recipe); Assert.NotNull(recipe.Ingredients); Assert.NotNull(recipe.Utensils); Assert.AreEqual(recipe.RecipeId, 0); Assert.AreEqual(recipe.Utensils.Count, 2); Assert.AreEqual(recipe.Ingredients.Count, 4); Recipe notARecipe = db.GetRecipeById(-1); Assert.IsNull(notARecipe); }