public RecipeService(IFoodService foodService, IUnitOfWork unitOfWork, RecipeValidator validator, INotificator notificator, ILogger <RecipeService> logger, IStringLocalizer <SharedResources> localizer) : base(unitOfWork, validator, notificator, logger) { _foodService = foodService; _localizer = localizer; }
private void Validate_Accepts_ValidName(string name) { // Arrange _invalidRecipe.Name = name; // Act ValidationResult result = new RecipeValidator().Validate(_invalidRecipe); // Assert result.Errors.Should().NotContain(nameof(Recipe.Name)); }
private void Validate_Denies_InvalidRating(int?rating) { // Arrange _invalidRecipe.Rating = rating; // Act ValidationResult result = new RecipeValidator().Validate(_invalidRecipe); // Assert result.Errors .Should() .ContainSingle(failure => failure.PropertyName.Equals(nameof(Recipe.Rating))); }
private void EditAndGenerateNewRecipe(ObservableFolder <Recipe> folder) { tempFilePath = Path.GetTempFileName(); RecipeCreator newRecipe = new RecipeCreator(tempFilePath) { Name = "NewRecipe", }; newRecipe.Ingredients.Add(new Ingredient("", "")); newRecipe.IsDirty = false; newRecipe.ValidateProperty += (sender, propertyName) => ValidateRecipe(sender, folder.Files, propertyName); RecipeValidator.SetDefaultRepository(folder.Files); EditorForm.OpenItemEditor(newRecipe); }
public object UpdateRecipe(Recipe recipe) { RecipeValidator rv = RecipeValid(recipe); int result = 0; string errorMessage = ""; if (rv.isValid) { result = recipeData.UpdateRecipe(recipe); } else { errorMessage = rv.errorMessage; } return(new { success = rv.isValid && result == 1, errorMessage, data = recipe }); }
protected string ValidateRecipe(object sender, IEnumerable <Recipe> instances, string propertyName) => RecipeValidator.Validate((Recipe)sender, instances, propertyName).Error;