public void TestStartup() { MapperConfig.ConfigureMapper(); _quantityTypeRepository = new FakeQuantityTypeRepository(); _repositoryManager = new FakeQuantityTypeRepositoryManager(); _controller = new QuantityTypeController(_repositoryManager, _quantityTypeRepository); var quantityType = new QuantityType {Name = "ts"}; _quantityTypeRepository.Create(quantityType); }
public HttpResponseMessage PostQuantityType(QuantityType quantityType) { if (ModelState.IsValid) { _repository.Add(quantityType); var response = Request.CreateResponse(HttpStatusCode.Created, quantityType); response.Headers.Location = new Uri(Url.Link("~/api/quantityType/", new { id = quantityType.Id })); return response; } return Request.CreateResponse(HttpStatusCode.BadRequest); }
public HttpResponseMessage PutQuantityType(int id, QuantityType quantityType) { if (ModelState.IsValid && id == quantityType.Id) { try { _repository.Update(id, quantityType); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK, quantityType); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
public static Meal CreateOatMeal() { var milk = new Ingredient { Carb = 4.7, Fat = 0.7, Protein = 3.3, Kcal = 38, Name = "Melk", Id = 4 }; var whey = new Ingredient { Carb = 0.4, Fat = 3, Protein = 86, Kcal = 360, Name = "Whey-100" }; var oatMeal = new Ingredient { Carb = 61, Fat = 7, Protein = 13, Kcal = 365, Name = "Havregryn" }; var meal = new Meal { Name = "HavreShake" }; var glass = new QuantityType { Name = "Glass", Id = 14 }; var mealIngredientMilk = new MealIngredient { Ingredient = milk, IngredientId = 4, Meal = meal, Quantity = 1.2, QuantityType = glass, QuantityTypeId = 14 }; var gram = new QuantityType { Name = "Gram", Id = 1 }; var mealIngredientWhey = new MealIngredient { Ingredient = whey, IngredientId = 5, Meal = meal, Quantity = 37, QuantityType = gram, QuantityTypeId = 1 }; var mealIngredientOatMeal = new MealIngredient { Ingredient = oatMeal, IngredientId = 6, Quantity = 40, QuantityType = gram, Meal = meal, QuantityTypeId = 1 }; meal.MealIngredients = new List<MealIngredient> { mealIngredientMilk, mealIngredientOatMeal, mealIngredientWhey }; return meal; }
public static MealIngredient CreateMealIngredients(Meal meal, Ingredient ingredient, QuantityType quantityType) { return new MealIngredient { MealId = meal.Id, IngredientId = ingredient.Id, Ingredient = ingredient, Meal = meal, Quantity = 3, Optional = false, QuantityType = quantityType, QuantityTypeId = quantityType.Id }; }