public void SetupMapping() { Func <IEnumerable <Type> > typeProducer = Enumerable.Empty <Type>; var _propertyEditorResolver = new Mock <PropertyEditorResolver>( Mock.Of <IServiceProvider>(), Mock.Of <ILogger>(), typeProducer, (IRuntimeCacheProvider)CacheHelper.CreateDisabledCacheHelper().RuntimeCache ); editorResolver = _propertyEditorResolver.Object; var ctor = Type.GetType("Umbraco.Web.Models.Mapping.ContentTypeModelMapper, umbraco") .GetConstructor(new[] { typeof(Lazy <PropertyEditorResolver>) }); var entityctor = Type.GetType("Umbraco.Web.Models.Mapping.EntityModelMapper, umbraco") .GetConstructor(new Type[0]); Mapper.Initialize(configuration => { var mapper = (MapperConfiguration)ctor.Invoke(new[] { new Lazy <PropertyEditorResolver>(() => editorResolver) }); mapper.ConfigureMappings(configuration, Support.UmbracoContext.Application); var entityMapper = (MapperConfiguration)entityctor.Invoke(new object[0]); entityMapper.ConfigureMappings(configuration, Support.UmbracoContext.Application); }); Mock.Get(editorResolver).Setup(r => r.GetByAlias(It.IsAny <string>())).Returns(new TestablePropertyEditor()); Mock.Get(Support.ServiceContext.DataTypeService) .Setup(s => s.GetPreValuesCollectionByDataTypeId(It.IsAny <int>())) .Returns(new PreValueCollection(new Dictionary <string, PreValue>())); }
internal UmbracoDataTypeHelper(IDataTypeService dataTypeService, PropertyEditorResolver propertyEditorResolver, ICacheProvider cacheProvider) { _dataTypeService = dataTypeService; _propertyEditorResolver = propertyEditorResolver; _cacheProvider = cacheProvider; }
private Dictionary <string, IPublishedProperty> MapProperties(PropertyEditorResolver resolver, ServiceContext services) { var contentType = this.contentType.Value; var properties = this.content.Properties; var items = new Dictionary <string, IPublishedProperty>(StringComparer.InvariantCultureIgnoreCase); foreach (var propertyType in contentType.PropertyTypes) { var property = properties.FirstOrDefault(x => x.Alias.InvariantEquals(propertyType.PropertyTypeAlias)); var value = property?.Value; if (value != null) { var propertyEditor = resolver.GetByAlias(propertyType.PropertyEditorAlias); if (propertyEditor != null) { value = propertyEditor.ValueEditor.ConvertDbToString(property, property.PropertyType, services.DataTypeService); } } items.Add(propertyType.PropertyTypeAlias, new UnpublishedProperty(propertyType, value)); } return(items); }
public EmbeddedContentPropertyEditor( IContentTypeService contentTypeService, IDataTypeService dataTypeService, ICultureDictionary cultureDictionary, ProfilingLogger profilingLogger, PropertyEditorResolver propertyEditorResolver, Func <WebSecurity> securityFactory) { _contentTypeService = contentTypeService; _dataTypeService = dataTypeService; _cultureDictionary = cultureDictionary; _profilingLogger = profilingLogger; _propertyEditorResolver = propertyEditorResolver; _securityFactory = securityFactory; }
public EmbeddedContentValueEditor( PropertyValueEditor wrapped, IContentTypeService contentTypeService, IDataTypeService dataTypeService, ICultureDictionary cultureDictionary, ProfilingLogger profilingLogger, PropertyEditorResolver propertyEditorResolver, WebSecurity security) : base(wrapped) { _contentTypeService = contentTypeService; _dataTypeService = dataTypeService; _cultureDictionary = cultureDictionary; _profilingLogger = profilingLogger; _propertyEditorResolver = propertyEditorResolver; _security = security; Validators.Add(new EmbeddedContentValidator(contentTypeService, dataTypeService)); }
/// <summary> /// The map properties. /// </summary> /// <param name="propertyTypes"> /// The property types. /// </param> /// <param name="properties"> /// The properties. /// </param> /// <param name="map"> /// The map. /// </param> /// <returns> /// The <see cref="IEnumerable{T}"/>. /// </returns> internal static IEnumerable <IPublishedProperty> MapProperties( IEnumerable <PublishedPropertyType> propertyTypes, IEnumerable <Property> properties, Func <PublishedPropertyType, object, IPublishedProperty> map) { PropertyEditorResolver propertyEditorResolver = PropertyEditorResolver.Current; IDataTypeService dataTypeService = ApplicationContext.Current.Services.DataTypeService; return(propertyTypes.Select( x => { Property p = properties.SingleOrDefault(xx => xx.Alias == x.PropertyTypeAlias); object v = p?.Value; if (v == null) { return map(x, v); } PropertyEditor e = propertyEditorResolver.GetByAlias(x.PropertyEditorAlias); // We are converting to string, even for database values which are integer or // DateTime, which is not optimum. Doing differently would require that we have a way to tell // whether the conversion to XML string changes something or not... which we don't, and we // don't want to implement it as PropertyValueEditor.ConvertDbToXml/String should die anyway. // Don't think about improving the situation here: this is a corner case and the real // thing to do is to get rig of PropertyValueEditor.ConvertDbToXml/String. // Use ConvertDbToString to keep it simple, although everywhere we use ConvertDbToXml and // nothing ensures that the two methods are consistent. if (e != null) { v = e.ValueEditor.ConvertDbToString(p, p.PropertyType, dataTypeService); } return map(x, v); })); }