public TypeOfIngredient Add(TypeOfIngredient item) { var newTypeOfIngredient = (TypeOfIngredient)item.Clone(); newTypeOfIngredient.Id = !_types.Any() ? 1 : _types.Max(rate => rate.Id) + 1; _types.Add(newTypeOfIngredient); return (TypeOfIngredient)newTypeOfIngredient.Clone(); }
public TypeOfIngredient Update(TypeOfIngredient item) { var existTypeOfIngredient = _types.SingleOrDefault(type => type.Id == item.Id); if (existTypeOfIngredient == null) { throw new NullReferenceException(); } existTypeOfIngredient.Name = item.Name; return (TypeOfIngredient)existTypeOfIngredient.Clone(); }
public void AddTest() { var name = Guid.NewGuid().ToString(); var newTypeOfIngredient = new TypeOfIngredient { Name = name }; var AddedTypeOfIngredient = service.Add(newTypeOfIngredient); Assert.IsNotNull(AddedTypeOfIngredient); Assert.IsTrue(AddedTypeOfIngredient.Id > 0); Assert.AreEqual(AddedTypeOfIngredient.Name, name); }