コード例 #1
0
 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;
 }
コード例 #2
0
        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));
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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
            });
        }
コード例 #6
0
 protected string ValidateRecipe(object sender, IEnumerable <Recipe> instances, string propertyName) => RecipeValidator.Validate((Recipe)sender, instances, propertyName).Error;