示例#1
0
        public void ShouldDeleteIngredient()
        {
            var ingredient = IngredientBuilder.BuildIngredient();

            _ingredientRepository.Add(ingredient);
            _ingredientRepository.Persist();

            _ingredientRepository.Delete(ingredient);
            _ingredientRepository.Persist();
            _ingredientRepository.Find(i => i != null).Count().ShouldEqual(0);

            using (var dataContext = GetNewDataContext())
            {
                var result = dataContext.GetTable <Ingredient>().ToList();
                result.Count.ShouldEqual(0);
            }
        }
示例#2
0
        /// <summary>
        /// Creates a new Ingredient and returns it. If an Ingredient or an AlternativeIngredientName with the same name already exist, null is returned.
        /// </summary>
        /// <param name="ingredientName"></param>
        /// <returns></returns>
        public Ingredient CreateIngredient(string ingredientName)
        {
            var alternativeNameRepostory =
                _repositoryFactory.Build <IRepository <AlternativeIngredientName>, AlternativeIngredientName>();

            if (string.IsNullOrEmpty(ingredientName) ||
                _ingredientRepository.Find(i => i.IngredientName == ingredientName).Any() ||
                alternativeNameRepostory.Find(ain => ain.AlternativeName == ingredientName).Any())
            {
                return(null);
            }
            var ingredient = new Ingredient {
                IngredientName = ingredientName
            };

            _ingredientRepository.Add(ingredient);
            _ingredientRepository.Persist();
            return(ingredient);
        }