/// <summary> /// Instantiates an <see cref="InitiateImprovementBusinessValidator" /> /// </summary> /// <param name="improvementExists">delegate that checks if an Improvement Exists</param> /// <param name="improvableExists">delegate that checks if an Improvable Exists</param> public InitiateImprovementBusinessValidator(ImprovementExists improvementExists, ImprovableExists improvableExists) { _improvableExists = improvableExists; _improvementExists = improvementExists; //TODO: should be validating that the BoundedContext exists RuleFor(_ => _.Improvement) .Must(NotBeAnExistingImprovement).WithMessage(_ => $"Improvement '{_.Improvement}' already exists"); RuleFor(_ => _.ForImprovable) .Must(BeAnExistingImprovable).WithMessage(_ => $"Improvable '{_.ForImprovable}' does not exist"); }
/// <summary> /// Validates the business rules associated with registering a new <see cref="Improvable" /> /// </summary> /// <param name="improvableExists">Indicates if an Improvable with the Id exists</param> /// <param name="improvableNameExists">Indicates if an Improvable with the name already exists</param> /// <param name="recipeExists">Indicates if the recipe type exists</param> /// <param name="repoExists"></param> public RegisterImprovableBusinessValidator(ImprovableExists improvableExists, ImprovableNameExists improvableNameExists, RecipeTypeExists recipeExists, RepositoryExists repoExists) { _improvableExists = improvableExists; _improvableNameExists = improvableNameExists; _recipeExists = recipeExists; _repoExists = repoExists; RuleFor(_ => _.Improvable) .Must(NotAlreadyBeRegistered) .WithMessage(_ => $"Cannot register an improvable ('{_.Improvable.Value}') that is already registered."); RuleFor(_ => _.Name) .Must(NotAlreadyBeInUse) .WithMessage(_ => $"An improvable with the name '{_.Name.Value}' is already registered."); RuleFor(_ => _.Recipe) .Must(BeAnExistingRecipe) .WithMessage(_ => $"No recipe for of type '{_.Recipe.Value}' exists."); RuleFor(_ => _.Repository) .Must(BeAnExistingRepository) .WithMessage(_ => $"No repository with this identifier '{_.Repository.Value}' exists."); }