コード例 #1
0
        public CreateRecipeCommandValidator()
        {
            RuleFor(x => x.Id)
            .NotNull()
            .WithMessage(ValidationMessages.NotNull(nameof(CreateRecipeCommand.Id)));

            RuleFor(x => x.Name)
            .NotNull()
            .WithMessage(ValidationMessages.NotNull(nameof(CreateRecipeCommand.Name)));

            RuleFor(x => x.Description)
            .NotNull()
            .WithMessage(ValidationMessages.NotNull(nameof(CreateRecipeCommand.Description)));

            RuleFor(x => x.RecipeInfo)
            .NotNull()
            .WithMessage(ValidationMessages.NotNull(nameof(CreateRecipeCommand.RecipeInfo)));

            RuleFor(x => x.RecipeIngredients)
            .NotEmpty()
            .WithMessage(ValidationMessages.NotEmpty(nameof(CreateRecipeCommand.RecipeIngredients)));

            RuleFor(x => x.RecipeInfo)
            .SetValidator(new RecipeDetailsValidator());

            RuleForEach(x => x.RecipeIngredients)
            .SetValidator(new RecipeIngredientValidator());
        }
コード例 #2
0
        public RecipeIngredientValidator()
        {
            RuleFor(x => x.Grams)
            .GreaterThanOrEqualTo(1)
            .WithMessage(ValidationMessages.GreaterThanOrEqualTo(nameof(RecipeIngredient.Grams), 0));

            RuleFor(x => x.IngredientId)
            .NotNull()
            .WithMessage(ValidationMessages.NotNull(nameof(RecipeIngredient.IngredientId)));
        }
コード例 #3
0
        public CreateIngredientCommandValidator()
        {
            RuleFor(x => x.Id)
            .NotNull()
            .WithMessage(ValidationMessages.NotNull(nameof(CreateIngredientCommand.Id)));

            RuleFor(x => x.Name)
            .NotNull()
            .WithMessage(ValidationMessages.NotNull(nameof(CreateIngredientCommand.Name)));

            RuleFor(x => x.Shares)
            .NotEmpty()
            .WithMessage(ValidationMessages.NotEmpty(nameof(CreateIngredientCommand.Shares)));

            RuleForEach(x => x.Shares)
            .SetValidator(new MacroNutrientsSharesValidator());
        }
コード例 #4
0
 public GetIngredientQueryValidator()
 {
     RuleFor(x => x.IngredientId)
     .NotNull()
     .WithMessage(ValidationMessages.NotNull(nameof(GetIngredientQuery.IngredientId)));
 }
コード例 #5
0
 public DeleteRecipeCommandValidator()
 {
     RuleFor(x => x.Id)
     .NotNull()
     .WithMessage(ValidationMessages.NotNull(nameof(DeleteRecipeCommand.Id)));
 }
コード例 #6
0
 public GetRecipeQueryValidator()
 {
     RuleFor(x => x.Id)
     .NotNull()
     .WithMessage(ValidationMessages.NotNull(nameof(GetByIdQuery.Id)));
 }