private void Assert(RecipeIngredientDto item)
        {
            item.Should().NotBeNull();
            item.HasData.Should().BeTrue();

            item.RecipeIngredientId.Should().NotBeEmpty();
            item.RecipeId.Should().NotBeEmpty();
            item.Sequence.Should().BeGreaterThan(0);
            item.Ingredient.Should().NotBeNullOrWhiteSpace();
        }
        private void AssertEquality(RecipeIngredientDto item1, RecipeIngredientDto item2)
        {
            item1.Should().NotBeNull();
            item2.Should().NotBeNull();

            item1.HasData.Should().BeTrue();
            item2.HasData.Should().BeTrue();

            item1.ShouldBeEquivalentTo(item2, options => options.Excluding(x => x.ChangeDate).Excluding(x => x.CreateDate));
        }
Beispiel #3
0
        public RecipeIngredientDto GetIngredient(Guid recipeIngredientId)
        {
            var result = this.recipeIngredientDA.Load(recipeIngredientId);

            if (result?.DeleteDate.HasValue != false)
            {
                result = new RecipeIngredientDto()
                {
                    HasData = false
                };
            }

            return(result);
        }
Beispiel #4
0
        public Guid Save(RecipeIngredientDto item, Guid userId)
        {
            item.RecipeIngredientId = this.SetPrimaryKeyId(item.RecipeIngredientId);

            this.Execute("spRecipeIngredientSave", new
            {
                item.RecipeIngredientId,
                item.RecipeId,
                item.Sequence,
                item.Ingredient,
                userId
            });

            return(item.RecipeIngredientId);
        }
Beispiel #5
0
        public ResultDto Save(RecipeIngredientDto saveItem, Guid userId)
        {
            var result = this.Validate(saveItem);

            if (result.IsSuccess)
            {
                using (ITransactionScope scope = new TransactionScopeWrapper())
                {
                    result.Result = this.recipeIngredientDA.Save(saveItem, userId);
                    scope.Complete();
                }
            }

            return(result);
        }
Beispiel #6
0
        public RecipeIngredientDto BuildRecipeIngredient(Guid?recipeId = null)
        {
            if (!recipeId.HasValue)
            {
                recipeId = this.CreateRecipe().RecipeId;
            }

            var item = new RecipeIngredientDto
            {
                HasData    = true,
                RecipeId   = recipeId.Value,
                Sequence   = this.GetRandomNumber(),
                Ingredient = this.GetRandomString(250)
            };

            return(item);
        }
Beispiel #7
0
        /// <summary>
        /// Validates an item
        /// </summary>
        /// <param name="saveItem"></param>
        public ResultDto Validate(RecipeIngredientDto saveItem)
        {
            var errorMessages = new List <string>();

            if (saveItem != null)
            {
                errorMessages.AddRange(Validator.GuidCheck(saveItem.RecipeId, RecipeResources.Recipe, true));
                errorMessages.AddRange(Validator.FieldLengthCheck(saveItem.Sequence, RecipeResources.Sequence, 0, null, true));
                errorMessages.AddRange(Validator.FieldLengthCheck(saveItem.Ingredient, RecipeResources.Ingredient, 2000, true));
            }
            else
            {
                errorMessages.Add(RecipeResources.RecipeIsRequired);
            }

            return(new ResultDto(errorMessages));
        }
        public void Validate()
        {
            RecipeIngredientDto item = null;

            this.AssertFailure(this.recipeIngredientService.Validate(item));

            item = new RecipeIngredientDto();
            this.AssertFailure(this.recipeIngredientService.Validate(item));

            item = this.BuildRecipeIngredient();
            this.AssertSuccess(this.recipeIngredientService.Validate(item));


            item.RecipeId = Guid.Empty;
            this.AssertFailure(this.recipeIngredientService.Validate(item));

            item.RecipeId = Guid.NewGuid();
            this.AssertSuccess(this.recipeIngredientService.Validate(item));


            item.Sequence = -1;
            this.AssertFailure(this.recipeIngredientService.Validate(item));

            item.Sequence = 0;
            this.AssertSuccess(this.recipeIngredientService.Validate(item));

            item.Sequence = 1000;
            this.AssertSuccess(this.recipeIngredientService.Validate(item));


            item.Ingredient = null;
            this.AssertFailure(this.recipeIngredientService.Validate(item));

            item.Ingredient = string.Empty;
            this.AssertFailure(this.recipeIngredientService.Validate(item));

            item.Ingredient = " ";
            this.AssertFailure(this.recipeIngredientService.Validate(item));

            item.Ingredient = this.GetRandomString(2001);
            this.AssertFailure(this.recipeIngredientService.Validate(item));

            item.Ingredient = this.GetRandomString(2000);
            this.AssertSuccess(this.recipeIngredientService.Validate(item));
        }