public ServiceInfosController(IServiceInfosRepository serviceInfoRepository, IMapper mapper, IPropertyMappingService propertyMapping, IPropertyValidationService propertyValidation)
 {
     _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _serviceInfoRepository = serviceInfoRepository ?? throw new ArgumentNullException(nameof(serviceInfoRepository));
     _propertyMapping       = propertyMapping ?? throw new ArgumentNullException(nameof(propertyMapping));
     _propertyValidation    = propertyValidation ?? throw new ArgumentNullException(nameof(propertyValidation));
 }
 public PostsController(IPostRepository postRepository, IMapper mapper, IPropertyMappingService propertyMapping, IPropertyValidationService propertyValidation)
 {
     _mapper             = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _postRepository     = postRepository ?? throw new ArgumentNullException(nameof(postRepository));
     _propertyMapping    = propertyMapping ?? throw new ArgumentNullException(nameof(propertyMapping));
     _propertyValidation = propertyValidation ?? throw new ArgumentNullException(nameof(propertyValidation));
 }
Esempio n. 3
0
 public BandsController(IBandAlbumRepository bandAlbumRepository, IMapper mapper, IPropertyMappingService propertyMappingService, IPropertyValidationService propertyValidationService) // there's no reference, how can we add mapper here?
 {
     _bandAlbumRepository = bandAlbumRepository ?? throw new ArgumentNullException(nameof(bandAlbumRepository));
     _mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _propertyMappingService    = propertyMappingService ?? throw new ArgumentNullException(nameof(propertyMappingService));
     _propertyValidationService = propertyValidationService ?? throw new ArgumentNullException(nameof(propertyValidationService));
 }
Esempio n. 4
0
 public BandsController(IBandAlbumRepository repository, IMapper mapper, IPropertyMappingService propertyMappingService, IPropertyValidationService propertyValidationService)
 {
     _repository                = repository ?? throw new ArgumentNullException(nameof(repository));
     _mapper                    = mapper ?? throw new ArgumentNullException(nameof(mapper));
     _propertyMappingService    = propertyMappingService ?? throw new ArgumentNullException(nameof(propertyMappingService));
     _propertyValidationService = propertyValidationService ?? throw new ArgumentNullException(nameof(propertyValidationService));
 }
 public BlockEditorValidator(
     IPropertyValidationService propertyValidationService,
     BlockEditorValues blockEditorValues,
     IContentTypeService contentTypeService)
     : base(propertyValidationService)
 {
     _blockEditorValues  = blockEditorValues;
     _contentTypeService = contentTypeService;
 }
 public CoachInfosController(ICoachInfosRepository coachInfosRepository,
                             IMapper mapper,
                             IPropertyMappingService propertyMapping,
                             IPropertyValidationService propertyValidation)
 {
     _coachInfosRepository = coachInfosRepository;
     _mapper             = mapper;
     _propertyMapping    = propertyMapping;
     _propertyValidation = propertyValidation;
 }
Esempio n. 7
0
 public MediaItemSaveValidationFilter(
     ILoggerFactory loggerFactory,
     IMediaService mediaService,
     IPropertyValidationService propertyValidationService,
     IAuthorizationService authorizationService)
 {
     _loggerFactory             = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     _mediaService              = mediaService ?? throw new ArgumentNullException(nameof(mediaService));
     _propertyValidationService = propertyValidationService ?? throw new ArgumentNullException(nameof(propertyValidationService));
     _authorizationService      = authorizationService ?? throw new ArgumentNullException(nameof(authorizationService));
 }
 public ContentSaveValidationFilter(
     ILoggerFactory loggerFactory,
     IContentService contentService,
     IPropertyValidationService propertyValidationService,
     IAuthorizationService authorizationService)
 {
     _loggerFactory             = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     _contentService            = contentService ?? throw new ArgumentNullException(nameof(contentService));
     _propertyValidationService = propertyValidationService ?? throw new ArgumentNullException(nameof(propertyValidationService));
     _authorizationService      = authorizationService;
 }
Esempio n. 9
0
 public UsersController(IUserRepository userRepository,
                        IMapper mapper,
                        IOptions <AppSettingsService> appSettings,
                        IPropertyMappingService propertyMapping,
                        IPropertyValidationService propertyValidation)
 {
     _userRepository     = userRepository;
     _mapper             = mapper;
     _appSettings        = appSettings.Value;
     _propertyMapping    = propertyMapping;
     _propertyValidation = propertyValidation;
 }
Esempio n. 10
0
 public MemberSaveModelValidator(
     ILogger <MemberSaveModelValidator> logger,
     IBackOfficeSecurity?backofficeSecurity,
     IMemberTypeService memberTypeService,
     IMemberService memberService,
     IShortStringHelper shortStringHelper,
     IPropertyValidationService propertyValidationService)
     : base(logger, propertyValidationService)
 {
     _backofficeSecurity = backofficeSecurity;
     _memberTypeService  = memberTypeService ?? throw new ArgumentNullException(nameof(memberTypeService));
     _memberService      = memberService ?? throw new ArgumentNullException(nameof(memberService));
     _shortStringHelper  = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper));
 }
 public MemberSaveValidationFilter(
     ILoggerFactory loggerFactory,
     IBackOfficeSecurityAccessor backofficeSecurityAccessor,
     IMemberTypeService memberTypeService,
     IMemberService memberService,
     IShortStringHelper shortStringHelper,
     IPropertyValidationService propertyValidationService)
 {
     _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     _backofficeSecurityAccessor = backofficeSecurityAccessor ?? throw new ArgumentNullException(nameof(backofficeSecurityAccessor));
     _memberTypeService          = memberTypeService ?? throw new ArgumentNullException(nameof(memberTypeService));
     _memberService             = memberService ?? throw new ArgumentNullException(nameof(memberService));
     _shortStringHelper         = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper));
     _propertyValidationService = propertyValidationService ?? throw new ArgumentNullException(nameof(propertyValidationService));
 }
Esempio n. 12
0
 public NestedContentPropertyValueEditor(
     IDataTypeService dataTypeService,
     ILocalizedTextService localizedTextService,
     IContentTypeService contentTypeService,
     IShortStringHelper shortStringHelper,
     DataEditorAttribute attribute,
     PropertyEditorCollection propertyEditors,
     ILogger <NestedContentPropertyEditor> logger,
     IJsonSerializer jsonSerializer,
     IIOHelper ioHelper,
     IPropertyValidationService propertyValidationService)
     : base(localizedTextService, shortStringHelper, jsonSerializer, ioHelper, attribute)
 {
     _propertyEditors     = propertyEditors;
     _dataTypeService     = dataTypeService;
     _logger              = logger;
     _nestedContentValues = new NestedContentValues(contentTypeService);
     Validators.Add(new NestedContentValidator(propertyValidationService, _nestedContentValues, contentTypeService));
 }
            public BlockEditorPropertyValueEditor(
                DataEditorAttribute attribute,
                PropertyEditorCollection propertyEditors,
                IDataTypeService dataTypeService,
                IContentTypeService contentTypeService,
                ILocalizedTextService textService,
                ILogger <BlockEditorPropertyValueEditor> logger,
                IShortStringHelper shortStringHelper,
                IJsonSerializer jsonSerializer,
                IIOHelper ioHelper,
                IPropertyValidationService propertyValidationService)
                : base(textService, shortStringHelper, jsonSerializer, ioHelper, attribute)
            {
                _propertyEditors = propertyEditors;
                _dataTypeService = dataTypeService;
                _logger          = logger;

                _blockEditorValues = new BlockEditorValues(new BlockListEditorDataConverter(), contentTypeService, _logger);
                Validators.Add(new BlockEditorValidator(propertyValidationService, _blockEditorValues, contentTypeService));
                Validators.Add(new MinMaxValidator(_blockEditorValues, textService));
            }
Esempio n. 14
0
 public NestedContentValidator(IPropertyValidationService propertyValidationService, NestedContentValues nestedContentValues, IContentTypeService contentTypeService)
     : base(propertyValidationService)
 {
     _nestedContentValues = nestedContentValues;
     _contentTypeService  = contentTypeService;
 }
Esempio n. 15
0
 public MediaSaveModelValidator(
     ILogger <MediaSaveModelValidator> logger,
     IPropertyValidationService propertyValidationService)
     : base(logger, propertyValidationService)
 {
 }
Esempio n. 16
0
        public void Validating_ContentItemSave()
        {
            ILogger <ContentSaveModelValidator> logger = Services.GetRequiredService <ILogger <ContentSaveModelValidator> >();
            IPropertyValidationService          propertyValidationService = Services.GetRequiredService <IPropertyValidationService>();
            IUmbracoMapper umbracoMapper = Services.GetRequiredService <IUmbracoMapper>();

            var validator = new ContentSaveModelValidator(logger, propertyValidationService);

            Content content = ContentBuilder.CreateTextpageContent(_contentType, "test", -1);

            var id1 = new Guid("c8df5136-d606-41f0-9134-dea6ae0c2fd9");
            var id2 = new Guid("f916104a-4082-48b2-a515-5c4bf2230f38");
            var id3 = new Guid("77E15DE9-1C79-47B2-BC60-4913BC4D4C6A");

            // TODO: Ok now test with a 4th level complex nested editor

            string complexValue = @"[{
                    ""key"": """     + id1.ToString() + @""",
                    ""name"": ""Hello world"",
                    ""ncContentTypeAlias"": """     + ContentTypeAlias + @""",
                    ""title"": ""Hello world"",
                     ""bodyText"": ""The world is round""
                }, {
                    ""key"": """     + id2.ToString() + @""",
                    ""name"": ""Super nested"",
                    ""ncContentTypeAlias"": """     + ContentTypeAlias + @""",
                    ""title"": ""Hi there!"",
                     ""bodyText"": ""Well hello there"",
                     ""complex"" : [{
                        ""key"": """     + id3.ToString() + @""",
                        ""name"": ""I am a sub nested content"",
                        ""ncContentTypeAlias"": """     + ContentTypeAlias + @""",
                        ""title"": ""Hello up there :)"",
                         ""bodyText"": ""Hello way up there on a different level""
                    }]
                }
             ]";

            content.SetValue("complex", complexValue);

            // map the persisted properties to a model representing properties to save
            // var saveProperties = content.Properties.Select(x => Mapper.Map<ContentPropertyBasic>(x)).ToList();
            var saveProperties = content.Properties.Select(x =>
            {
                return(new ContentPropertyBasic
                {
                    Alias = x.Alias,
                    Id = x.Id,
                    Value = x.GetValue()
                });
            }).ToList();

            var saveVariants = new List <ContentVariantSave>
            {
                new ContentVariantSave
                {
                    Culture    = string.Empty,
                    Segment    = string.Empty,
                    Name       = content.Name,
                    Save       = true,
                    Properties = saveProperties
                }
            };

            var save = new ContentItemSave
            {
                Id               = content.Id,
                Action           = ContentSaveAction.Save,
                ContentTypeAlias = _contentType.Alias,
                ParentId         = -1,
                PersistedContent = content,
                TemplateAlias    = null,
                Variants         = saveVariants
            };

            // This will map the ContentItemSave.Variants.PropertyCollectionDto and then map the values in the saved model
            // back onto the persisted IContent model.
            ContentItemBinder.BindModel(save, content, _modelBinderHelper, umbracoMapper);

            var  modelState = new ModelStateDictionary();
            bool isValid    = validator.ValidatePropertiesData(save, saveVariants[0], saveVariants[0].PropertyCollectionDto, modelState);

            // list results for debugging
            foreach (KeyValuePair <string, ModelStateEntry> state in modelState)
            {
                Console.WriteLine(state.Key);
                foreach (ModelError error in state.Value.Errors)
                {
                    Console.WriteLine("\t" + error.ErrorMessage);
                }
            }

            // assert
            Assert.IsFalse(isValid);
            Assert.AreEqual(11, modelState.Keys.Count());
            const string complexPropertyKey = "_Properties.complex.invariant.null";

            Assert.IsTrue(modelState.Keys.Contains(complexPropertyKey));
            foreach (KeyValuePair <string, ModelStateEntry> state in modelState.Where(x => x.Key != complexPropertyKey))
            {
                foreach (ModelError error in state.Value.Errors)
                {
                    Assert.IsFalse(error.ErrorMessage.DetectIsJson()); // non complex is just an error message
                }
            }

            ModelErrorCollection complexEditorErrors = modelState.Single(x => x.Key == complexPropertyKey).Value.Errors;

            Assert.AreEqual(1, complexEditorErrors.Count);
            ModelError nestedError = complexEditorErrors[0];
            JArray     jsonError   = JsonConvert.DeserializeObject <JArray>(nestedError.ErrorMessage);

            string[] modelStateKeys = new[] { "_Properties.title.invariant.null.innerFieldId", "_Properties.title.invariant.null.value", "_Properties.bodyText.invariant.null.innerFieldId", "_Properties.bodyText.invariant.null.value" };
            AssertNestedValidation(jsonError, 0, id1, modelStateKeys);
            AssertNestedValidation(jsonError, 1, id2, modelStateKeys.Concat(new[] { "_Properties.complex.invariant.null.innerFieldId", "_Properties.complex.invariant.null.value" }).ToArray());
            var nestedJsonError = jsonError.SelectToken("$[1].complex") as JArray;

            Assert.IsNotNull(nestedJsonError);
            AssertNestedValidation(nestedJsonError, 0, id3, modelStateKeys);
        }
 public ContentSaveModelValidator(
     ILogger <ContentSaveModelValidator> logger,
     IPropertyValidationService propertyValidationService)
     : base(logger, propertyValidationService)
 {
 }
 public ComplexEditorValidator(IPropertyValidationService propertyValidationService)
 {
     _propertyValidationService = propertyValidationService;
 }
Esempio n. 19
0
 protected ContentModelValidator(ILogger <ContentModelValidator> logger, IPropertyValidationService propertyValidationService)
 {
     Logger = logger ?? throw new ArgumentNullException(nameof(logger));
     PropertyValidationService = propertyValidationService ??
                                 throw new ArgumentNullException(nameof(propertyValidationService));
 }