public void MapToProperty_GetsValueByPropertyAlias_ReturnsPropertyValue() { //Assign var propertyValue = "test value set"; var propertyAlias = "Property"; var content = _contentService.GetById(new Guid("{D2517065-2818-4AF7-B851-493E46EA79D5}")); var config = new UmbracoPropertyConfiguration(); config.PropertyAlias = propertyAlias; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = propertyValue; var context = new UmbracoDataMappingContext(null, content, null, false); content.Properties[propertyAlias].Value = propertyValue; //Act var result = mapper.MapToProperty(context); //Assert Assert.AreEqual(propertyValue, result); }
/// <summary> /// Gets the property. /// </summary> /// <param name="property">The property.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetProperty(Umbraco.Core.Models.Property property, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (property == null || property.Value == null) return null; var mediaService = new MediaService(new RepositoryFactory()); int id; if (!int.TryParse(property.Value.ToString(), out id)) return null; var file = mediaService.GetById(id); if (file != null) { int bytes; int.TryParse(file.Properties["umbracoBytes"].Value.ToString(), out bytes); var img = new File { Id = file.Id, Name = file.Name, Src = file.Properties["umbracoFile"].Value.ToString(), Extension = file.Properties["umbracoExtension"].Value.ToString(), Size = bytes }; return img; } return null; }
public void MapToProperty_ContentHasNoChildren_NoObjectsCreated() { //Assign var content = _contentService.GetById(new Guid("{3F34475B-D744-40E9-BC30-5D33249FA9FE}")); var children = _contentService.GetChildren(content.Id); var service = Substitute.For <IUmbracoService>(); var predicate = Arg.Is <IContent>(x => children.Any(y => x.Id == y.Id)); var config = new UmbracoChildrenConfiguration(); config.InferType = false; config.IsLazy = false; config.PropertyInfo = typeof(Stub).GetProperty("Children"); var mapper = new UmbracoChildrenMapper(); //ME - Although this looks correct I am not sure it is service.CreateType(typeof(StubChild), predicate, false, false).ReturnsForAnyArgs(info => new StubChild { Id = info.Arg <IContent>().Id }); var context = new UmbracoDataMappingContext(null, content, service, false); mapper.Setup(new DataMapperResolverArgs(null, config)); //Act var result = mapper.MapToProperty(context) as IEnumerable <StubChild>; //Assert Assert.AreEqual(0, result.Count()); }
public void MapToCms_SetsValueByPropertyAlias_PropertyValueUpdated() { //Assign var propertyValue = "test value set"; var propertyAlias = "Property"; var content = _contentService.GetById(new Guid("{D2517065-2818-4AF7-B851-493E46EA79D5}")); var config = new UmbracoPropertyConfiguration(); config.PropertyAlias = propertyAlias; config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = propertyValue; var context = new UmbracoDataMappingContext(new Stub(), content, null, false); content.Properties[propertyAlias].Value = string.Empty; //Act mapper.MapToCms(context); //Assert Assert.AreEqual(propertyValue, mapper.Value); }
public void MapToProperty_ConfigurationIsLazy_CallsCreateClassOnServiceWithIsLazy() { //Assign var contentService = new ContentService(_unitOfWork, _repoFactory); var content = contentService.GetById(new Guid("{C382AE57-D325-4357-A32A-0A959BBD4101}")); var service = Substitute.For <IUmbracoService>(); service.ContentService.Returns(contentService); var context = new UmbracoDataMappingContext(null, content, service); var config = new UmbracoParentConfiguration(); config.PropertyInfo = typeof(Stub).GetProperty("Property"); config.IsLazy = true; var mapper = new UmbracoParentMapper(); mapper.Setup(new DataMapperResolverArgs(null, config)); //Act mapper.MapToProperty(context); //Assert //ME - I am not sure why I have to use the Arg.Is but just using item.Parent as the argument fails. service.Received().CreateType(config.PropertyInfo.PropertyType, Arg.Is <IContent>(x => x.Id == content.ParentId), true, false); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The property value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { Type type = config.PropertyInfo.PropertyType; //Get generic type Type pType = Utilities.GetGenericArgument(type); var list = Glass.Mapper.Utilities.CreateGenericType(typeof(List<>), new[] { pType }) as IList; if (propertyValue == null) return list; //The enumerator only works with piped lists IEnumerable<string> parts = propertyValue.ToString().Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries); IEnumerable<object> items = parts.Select(x => Mapper.GetPropertyValue(x, Mapper.Configuration as UmbracoPropertyConfiguration, context)).ToArray(); foreach (var item in items) { if (item != null) if (list != null) list.Add(item); } return list; }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { int id; if (!int.TryParse(propertyValue.ToString(), out id)) return null; var item = context.Service.ContentService.GetById(id); return context.Service.CreateType(config.PropertyInfo.PropertyType, item, IsLazy, InferType); }
/// <summary> /// Sets the property value. /// </summary> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> /// <exception cref="System.NullReferenceException">Could not find item to save value {0}</exception> public override object SetPropertyValue(object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (value == null) return string.Empty; var typeConfig = context.Service.GlassContext[value.GetType()] as UmbracoTypeConfiguration; var item = typeConfig.ResolveItem(value, context.Service.ContentService); if (item == null) throw new NullReferenceException("Could not find item to save value {0}"); return item.Id; }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The property value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { Type enumType = config.PropertyInfo.PropertyType; int intValue; if (int.TryParse(propertyValue.ToString(), out intValue)) return Enum.ToObject(enumType, intValue); if (Enum.IsDefined(enumType, propertyValue)) return Enum.Parse(enumType, propertyValue.ToString(), true); throw new MapperException("Can not convert value {0} to enum type {1}".Formatted(propertyValue, enumType.FullName)); }
/// <summary> /// Sets the property. /// </summary> /// <param name="property">The property.</param> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> public override void SetProperty(Umbraco.Core.Models.Property property, object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { throw new NotImplementedException(); /* Image img = value as Image; var item = field.Item; if (field == null) return; ImageField scImg = new ImageField(field); if (img == null) { scImg.Clear(); return; } if (scImg.MediaID.Guid != img.MediaId) { //this only handles empty guids, but do we need to remove the link before adding a new one? if (img.MediaId == Guid.Empty) { ItemLink link = new ItemLink(item.Database.Name, item.ID, scImg.InnerField.ID, scImg.MediaItem.Database.Name, scImg.MediaID, scImg.MediaItem.Paths.Path); scImg.RemoveLink(link); } else { ID newId = new ID(img.MediaId); Item target = item.Database.GetItem(newId); if (target != null) { scImg.MediaID = newId; ItemLink link = new ItemLink(item.Database.Name, item.ID, scImg.InnerField.ID, target.Database.Name, target.ID, target.Paths.FullPath); scImg.UpdateLink(link); } else throw new MapperException("No item with ID {0}. Can not update Media Item field".Formatted(newId)); } } scImg.Height = img.Height.ToString(); scImg.Width = img.Width.ToString(); scImg.HSpace = img.HSpace.ToString(); scImg.VSpace = img.VSpace.ToString(); scImg.Alt = img.Alt; scImg.Border = img.Border; scImg.Class = img.Class;*/ }
public void MapToCms_SavingName_UpdatesTheItemName() { //Assign var type = UmbracoInfoType.Name; var expected = "new name"; var mapper = new UmbracoInfoMapper(); var config = new UmbracoInfoConfiguration(); config.Type = type; mapper.Setup(new DataMapperResolverArgs(null, config)); var contentService = new ContentService(_unitOfWork, _repoFactory); var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}")); var oldName = content.Name; Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists"); var resolver = DependencyResolver.CreateStandardResolver(); resolver.Container.Register( Component.For <Mapper.Config>().Instance(new Mapper.Config()) ); var context = Context.Create(resolver); var dataContext = new UmbracoDataMappingContext(null, content, new UmbracoService(contentService, context), false); dataContext.PropertyValue = expected; string actual = string.Empty; //Act mapper.MapToCms(dataContext); content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}")); actual = content.Name; //Assert Assert.AreEqual(expected, actual); content.Name = oldName; contentService.Save(content); }
/// <summary> /// Maps data from the CMS value to the .Net property value /// </summary> /// <param name="mappingContext"></param> /// <returns></returns> /// <exception cref="System.NotSupportedException">The type {0} on {0}.{1} is not supported by UmbracoIdMapper.Formatted /// (umbConfig.PropertyInfo.ReflectedType.FullName, /// umbConfig.PropertyInfo.Name)</exception> public override object MapToProperty(AbstractDataMappingContext mappingContext) { UmbracoDataMappingContext context = mappingContext as UmbracoDataMappingContext; var node = context.Content; var umbConfig = Configuration as UmbracoIdConfiguration; if (umbConfig.PropertyInfo.PropertyType == typeof(int)) { return(node.Id); } if (umbConfig.PropertyInfo.PropertyType == typeof(Guid)) { return(node.Key); } throw new NotSupportedException("The type {0} on {0}.{1} is not supported by UmbracoIdMapper".Formatted (umbConfig.PropertyInfo.ReflectedType.FullName, umbConfig.PropertyInfo.Name)); }
public void MapToProperty_ConfigurationSetupCorrectly_CallsCreateClassOnService() { //Assign var contentService = new ContentService(_unitOfWork, _repoFactory); var content = contentService.GetById(new Guid("{C382AE57-D325-4357-A32A-0A959BBD4101}")); var service = Substitute.For<IUmbracoService>(); service.ContentService.Returns(contentService); var context = new UmbracoDataMappingContext(null, content, service); var config = new UmbracoParentConfiguration(); config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new UmbracoParentMapper(); mapper.Setup(new DataMapperResolverArgs(null, config)); //Act mapper.MapToProperty(context); //Assert //ME - I am not sure why I have to use the Arg.Is but just using item.Parent as the argument fails. service.Received().CreateType(config.PropertyInfo.PropertyType, Arg.Is<IContent>(x => x.Id == content.ParentId), false, false); }
public void MapToProperty_ContentHasChildren_ChildrenObjectsAreCreated() { //Assign var content = _contentService.GetById(new Guid("{373D1D1C-BD0D-4A8C-9A67-1D513815FE10}")); var children = _contentService.GetChildren(content.Id); var service = Substitute.For <IUmbracoService>(); var predicate = Arg.Is <IContent>(x => children.Any(y => x.Id == y.Id)); var config = new UmbracoChildrenConfiguration(); config.InferType = false; config.IsLazy = false; config.PropertyInfo = typeof(Stub).GetProperty("Children"); var mapper = new UmbracoChildrenMapper(); //ME - Although this looks correct I am not sure it is service.ContentService.Returns(_contentService); service.CreateType(typeof(StubChild), predicate, false, false).ReturnsForAnyArgs(info => new StubChild { Id = info.Arg <IContent>().Id }); var context = new UmbracoDataMappingContext(null, content, service, false); mapper.Setup(new DataMapperResolverArgs(null, config)); //Act var result = mapper.MapToProperty(context) as IEnumerable <StubChild>; //Assert Assert.AreEqual(1, children.Count()); Assert.AreEqual(children.Count(), result.Count()); foreach (IContent child in children) { Assert.IsTrue(result.Any(x => x.Id == child.Id)); } }
public void MapToProperty_UmbracoInfoType_GetsExpectedValueFromUmbraco( [Values( //UmbracoInfoType.Url, UmbracoInfoType.ContentTypeAlias, UmbracoInfoType.ContentTypeName, UmbracoInfoType.Name, UmbracoInfoType.Creator )] UmbracoInfoType type, [Values( //"target", //Url "TestType", //ContentTypeAlias "Test Type", //ContentTypeName "Target", //Name "admin" //Creator )] object expected ) { //Assign var mapper = new UmbracoInfoMapper(); var config = new UmbracoInfoConfiguration(); config.Type = type; mapper.Setup(new DataMapperResolverArgs(null, config)); var contentService = new ContentService(_unitOfWork, _repoFactory); var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}")); Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists"); var dataContext = new UmbracoDataMappingContext(null, content, null); //Act var value = mapper.MapToProperty(dataContext); Console.WriteLine(type); //Assert Assert.AreEqual(expected, value); }
/// <summary> /// Sets the Property value. /// </summary> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns>System.String.</returns> public override object SetPropertyValue(object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { var list = value as IEnumerable; if (list == null) { return string.Empty; } var sList = new List<string>(); foreach (object obj in list) { string result = Mapper.SetPropertyValue(obj, config, context).ToString(); if (!result.IsNullOrEmpty()) sList.Add(result); } if (sList.Any()) return sList.Aggregate((x, y) => x + "," + y); return string.Empty; }
public void MapToProperty_UmbracoInfoTypeNotSet_ThrowsException() { //Assign UmbracoInfoType type = UmbracoInfoType.NotSet; var mapper = new UmbracoInfoMapper(); var config = new UmbracoInfoConfiguration(); config.Type = type; mapper.Setup(new DataMapperResolverArgs(null, config)); var contentService = new ContentService(_unitOfWork, _repoFactory); var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}")); Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists"); var dataContext = new UmbracoDataMappingContext(null, content, null); //Act var value = mapper.MapToProperty(dataContext); //Assert //No asserts expect exception }
/// <summary> /// Gets the property. /// </summary> /// <param name="property">The property.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetProperty(Umbraco.Core.Models.Property property, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (property == null) return null; var mediaService = new MediaService(new RepositoryFactory()); int id; if (!int.TryParse(property.Value.ToString(), out id)) return null; var image = mediaService.GetById(id); if (image != null) { int width; int.TryParse(image.Properties["umbracoWidth"].Value.ToString(), out width); int height; int.TryParse(image.Properties["umbracoHeight"].Value.ToString(), out height); int bytes; int.TryParse(image.Properties["umbracoBytes"].Value.ToString(), out bytes); var img = new Image { Id = image.Id, Alt = image.Name, Src = image.Properties["umbracoFile"].Value.ToString(), Width = width, Height = height, Extension = image.Properties["umbracoExtension"].Value.ToString(), Size = bytes }; return img; } return null; }
public void MapToProperty_ContentHasChildren_ChildrenObjectsAreCreated() { //Assign var content = _contentService.GetById(new Guid("{373D1D1C-BD0D-4A8C-9A67-1D513815FE10}")); var children = _contentService.GetChildren(content.Id); var service = Substitute.For<IUmbracoService>(); var predicate = Arg.Is<IContent>(x => children.Any(y => x.Id == y.Id)); var config = new UmbracoChildrenConfiguration(); config.InferType = false; config.IsLazy = false; config.PropertyInfo = typeof(Stub).GetProperty("Children"); var mapper = new UmbracoChildrenMapper(); //ME - Although this looks correct I am not sure it is service.ContentService.Returns(_contentService); service.CreateType(typeof(StubChild), predicate, false, false).ReturnsForAnyArgs(info => new StubChild { Id = info.Arg<IContent>().Id }); var context = new UmbracoDataMappingContext(null, content, service); mapper.Setup(new DataMapperResolverArgs(null, config)); //Act var result = mapper.MapToProperty(context) as IEnumerable<StubChild>; //Assert Assert.AreEqual(1, children.Count()); Assert.AreEqual(children.Count(), result.Count()); foreach (IContent child in children) { Assert.IsTrue(result.Any(x => x.Id == child.Id)); } }
public void MapToProperty_ContentIdAsInt_ReturnsIdAsInt() { var content = _contentService.GetById(new Guid("{263768E1-E958-4B00-BB00-191CC33A3F48}")); //Assign var mapper = new UmbracoIdMapper(); var config = new UmbracoIdConfiguration(); var property = typeof(Stub).GetProperty("Id"); Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists"); config.PropertyInfo = property; mapper.Setup(new DataMapperResolverArgs(null, config)); var dataContext = new UmbracoDataMappingContext(null, content, null); var expected = content.Id; //Act var value = mapper.MapToProperty(dataContext); //Assert Assert.AreEqual(expected, value); }
public void MapToProperty_UmbracoInfoTypeUpdateDate_ReturnsUpdateDateAsDateTime() { //Assign var type = UmbracoInfoType.UpdateDate; var mapper = new UmbracoInfoMapper(); var config = new UmbracoInfoConfiguration(); config.Type = type; mapper.Setup(new DataMapperResolverArgs(null, config)); var contentService = new ContentService(_unitOfWork, _repoFactory); var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}")); var expected = content.UpdateDate; Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists"); var dataContext = new UmbracoDataMappingContext(null, content, null); //Act var value = mapper.MapToProperty(dataContext); //Assert Assert.AreEqual(expected, value); }
public void MapToProperty_ContentIdAsGuid_ReturnsIdAsGuid() { var content = _contentService.GetById(new Guid("{263768E1-E958-4B00-BB00-191CC33A3F48}")); //Assign var mapper = new UmbracoIdMapper(); var config = new UmbracoIdConfiguration(); var property = typeof(Stub).GetProperty("Key"); Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists"); config.PropertyInfo = property; mapper.Setup(new DataMapperResolverArgs(null, config)); var dataContext = new UmbracoDataMappingContext(null, content, null); var expected = content.Key; //Act var value = mapper.MapToProperty(dataContext); //Assert Assert.AreEqual(expected, value); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The property value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { return propertyValue is DateTime ? (DateTime)propertyValue : new DateTime(); }
public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { return(Value); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The property value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (propertyValue != null && propertyValue.ToString() == "1") return true; return false; }
public void MapToProperty_ContentHasNoChildren_NoObjectsCreated() { //Assign var content = _contentService.GetById(new Guid("{3F34475B-D744-40E9-BC30-5D33249FA9FE}")); var children = _contentService.GetChildren(content.Id); var service = Substitute.For<IUmbracoService>(); var predicate = Arg.Is<IContent>(x => children.Any(y => x.Id == y.Id)); var config = new UmbracoChildrenConfiguration(); config.InferType = false; config.IsLazy = false; config.PropertyInfo = typeof(Stub).GetProperty("Children"); var mapper = new UmbracoChildrenMapper(); //ME - Although this looks correct I am not sure it is service.CreateType(typeof(StubChild), predicate, false, false).ReturnsForAnyArgs(info => new StubChild { Id = info.Arg<IContent>().Id }); var context = new UmbracoDataMappingContext(null, content, service); mapper.Setup(new DataMapperResolverArgs(null, config)); //Act var result = mapper.MapToProperty(context) as IEnumerable<StubChild>; //Assert Assert.AreEqual(0, result.Count()); }
/// <summary> /// Sets the property. /// </summary> /// <param name="property">The property.</param> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> public override void SetProperty(Umbraco.Core.Models.Property property, object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { throw new NotImplementedException(); /* Image img = value as Image; * var item = field.Item; * * if (field == null) return; * * ImageField scImg = new ImageField(field); * * if (img == null) * { * scImg.Clear(); * return; * } * * if (scImg.MediaID.Guid != img.MediaId) * { * //this only handles empty guids, but do we need to remove the link before adding a new one? * if (img.MediaId == Guid.Empty) * { * ItemLink link = new ItemLink(item.Database.Name, item.ID, scImg.InnerField.ID, scImg.MediaItem.Database.Name, scImg.MediaID, scImg.MediaItem.Paths.Path); * scImg.RemoveLink(link); * } * else * { * ID newId = new ID(img.MediaId); * Item target = item.Database.GetItem(newId); * if (target != null) * { * scImg.MediaID = newId; * ItemLink link = new ItemLink(item.Database.Name, item.ID, scImg.InnerField.ID, target.Database.Name, target.ID, target.Paths.FullPath); * scImg.UpdateLink(link); * } * else throw new MapperException("No item with ID {0}. Can not update Media Item field".Formatted(newId)); * } * } * * scImg.Height = img.Height.ToString(); * scImg.Width = img.Width.ToString(); * scImg.HSpace = img.HSpace.ToString(); * scImg.VSpace = img.VSpace.ToString(); * scImg.Alt = img.Alt; * scImg.Border = img.Border; * scImg.Class = img.Class;*/ }
/// <summary> /// Gets the property. /// </summary> /// <param name="property">The property.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetProperty(Umbraco.Core.Models.Property property, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (property == null) { return(null); } var mediaService = new MediaService(new RepositoryFactory()); int id; if (!int.TryParse(property.Value.ToString(), out id)) { return(null); } var file = mediaService.GetById(id); if (file != null) { int bytes; int.TryParse(file.Properties["umbracoBytes"].Value.ToString(), out bytes); var img = new File { Id = file.Id, Name = file.Name, Src = file.Properties["umbracoFile"].Value.ToString(), Extension = file.Properties["umbracoExtension"].Value.ToString(), Size = bytes }; return(img); } return(null); }
/// <summary> /// Sets the property value. /// </summary> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object SetPropertyValue(object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { return value; }
private string GetDelegatedValue(UmbracoDataMappingContext arg) { return "happy"; }
/// <summary> /// Sets the Property. /// </summary> /// <param name="property">The Property.</param> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> public override void SetProperty(Property property, object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (value == null) { property.Value = null; return; } _baseMapper.SetProperty(property, (T)value, config, context); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The property value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { return propertyValue as string; }
/// <summary> /// Sets the property value. /// </summary> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> /// <exception cref="System.NullReferenceException">Could not find item to save value {0}</exception> public override object SetPropertyValue(object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (value == null) { return(string.Empty); } var typeConfig = context.Service.GlassContext[value.GetType()] as UmbracoTypeConfiguration; var item = typeConfig.ResolveItem(value, context.Service.ContentService); if (item == null) { throw new NullReferenceException("Could not find item to save value {0}"); } return(item.Id); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { int id; if (propertyValue == null || !int.TryParse(propertyValue.ToString(), out id)) { return(null); } var item = context.PublishedOnly ? context.Service.ContentService.GetPublishedVersion(id) : context.Service.ContentService.GetById(id); return(context.Service.CreateType(config.PropertyInfo.PropertyType, item, IsLazy, InferType)); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The property value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (propertyValue != null && propertyValue.ToString() == "1") { return(true); } return(false); }
/// <summary> /// Sets the property value. /// </summary> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object SetPropertyValue(object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (value is bool && (bool)value) { return("1"); } return("0"); }
public void MapToCms_SavingName_UpdatesTheItemName() { //Assign var type = UmbracoInfoType.Name; var expected = "new name"; var mapper = new UmbracoInfoMapper(); var config = new UmbracoInfoConfiguration(); config.Type = type; mapper.Setup(new DataMapperResolverArgs(null, config)); var contentService = new ContentService(_unitOfWork, _repoFactory); var content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}")); var oldName = content.Name; Assert.IsNotNull(content, "Content is null, check in Umbraco that item exists"); var context = Context.Create(DependencyResolver.CreateStandardResolver()); var dataContext = new UmbracoDataMappingContext(null, content, new UmbracoService(contentService, context)); dataContext.PropertyValue = expected; string actual = string.Empty; //Act mapper.MapToCms(dataContext); content = contentService.GetById(new Guid("{FB6A8073-48B4-4B85-B80C-09CBDECC27C9}")); actual = content.Name; //Assert Assert.AreEqual(expected, actual); content.Name = oldName; contentService.Save(content); }
private string GetDelegatedValue(UmbracoDataMappingContext arg) { return("happy"); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The property value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { return propertyValue is Guid ? (Guid)propertyValue : new Guid(); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The property value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { return(propertyValue is Guid ? (Guid)propertyValue : new Guid()); }
/// <summary> /// Gets the property. /// </summary> /// <param name="property">The property.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetProperty(Umbraco.Core.Models.Property property, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (property == null) { return(null); } var mediaService = new MediaService(new RepositoryFactory()); int id; if (!int.TryParse(property.Value.ToString(), out id)) { return(null); } var image = mediaService.GetById(id); if (image != null) { int width; int.TryParse(image.Properties["umbracoWidth"].Value.ToString(), out width); int height; int.TryParse(image.Properties["umbracoHeight"].Value.ToString(), out height); int bytes; int.TryParse(image.Properties["umbracoBytes"].Value.ToString(), out bytes); var img = new Image { Id = image.Id, Alt = image.Name, Src = image.Properties["umbracoFile"].Value.ToString(), Width = width, Height = height, Extension = image.Properties["umbracoExtension"].Value.ToString(), Size = bytes }; return(img); } return(null); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The property value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { Type type = config.PropertyInfo.PropertyType; //Get generic type Type pType = Utilities.GetGenericArgument(type); var list = Glass.Mapper.Utilities.CreateGenericType(typeof(List <>), new[] { pType }) as IList; if (propertyValue == null) { return(list); } //The enumerator only works with piped lists IEnumerable <string> parts = propertyValue.ToString().Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries); IEnumerable <object> items = parts.Select(x => Mapper.GetPropertyValue(x, Mapper.Configuration as UmbracoPropertyConfiguration, context)).ToArray(); foreach (var item in items) { if (item != null) { if (list != null) { list.Add(item); } } } return(list); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The property value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { throw new NotImplementedException(); }
/// <summary> /// Sets the Property value. /// </summary> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns>System.String.</returns> public override object SetPropertyValue(object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { var list = value as IEnumerable; if (list == null) { return(string.Empty); } var sList = new List <string>(); foreach (object obj in list) { string result = Mapper.SetPropertyValue(obj, config, context).ToString(); if (!result.IsNullOrEmpty()) { sList.Add(result); } } if (sList.Any()) { return(sList.Aggregate((x, y) => x + "," + y)); } return(string.Empty); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The property value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { return propertyValue is decimal ? (decimal)propertyValue : 0; }
public override void SetProperty(Property property, object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { property.Value = Value; }
/// <summary> /// Sets the property value. /// </summary> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object SetPropertyValue(object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { return Enum.GetName(config.PropertyInfo.PropertyType, value); }
/// <summary> /// Sets the property value. /// </summary> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object SetPropertyValue(object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (value is bool && (bool)value) return "1"; return "0"; }
/// <summary> /// Sets the property. /// </summary> /// <param name="property">The property.</param> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> public virtual void SetProperty(Property property, object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { property.Value = SetPropertyValue(value, config, context); }
/// <summary> /// Gets the property value. /// </summary> /// <param name="propertyValue">The property value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public override object GetPropertyValue(object propertyValue, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { return(propertyValue is decimal ? (decimal)propertyValue : 0); }
public void MapToProperty_GetsValueByPropertyAlias_ReturnsPropertyValue() { //Assign var propertyValue = "test value set"; var propertyAlias = "Property"; var content = _contentService.GetById(new Guid("{D2517065-2818-4AF7-B851-493E46EA79D5}")); var config = new UmbracoPropertyConfiguration(); config.PropertyAlias = propertyAlias; var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null,config)); mapper.Value = propertyValue; var context = new UmbracoDataMappingContext(null, content, null); content.Properties[propertyAlias].Value = propertyValue; //Act var result = mapper.MapToProperty(context); //Assert Assert.AreEqual(propertyValue, result); }
/// <summary> /// Gets the property. /// </summary> /// <param name="property">The property.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns></returns> public virtual object GetProperty(Property property, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { var propertyValue = property.Value; return(GetPropertyValue(propertyValue, config, context)); }
/// <summary> /// Gets the Property. /// </summary> /// <param name="property">The Property.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns> /// System.Object. /// </returns> public override object GetProperty(Property property, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { if (property.Value != null) { return(null); } return(_baseMapper.GetProperty(property, config, context)); }
public void MapToCms_SetsValueByPropertyAlias_PropertyValueUpdated() { //Assign var propertyValue = "test value set"; var propertyAlias = "Property"; var content = _contentService.GetById(new Guid("{D2517065-2818-4AF7-B851-493E46EA79D5}")); var config = new UmbracoPropertyConfiguration(); config.PropertyAlias = propertyAlias; config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new StubMapper(null); mapper.Setup(new DataMapperResolverArgs(null, config)); mapper.Value = propertyValue; var context = new UmbracoDataMappingContext(new Stub(), content, null); content.Properties[propertyAlias].Value = string.Empty; //Act mapper.MapToCms(context); //Assert Assert.AreEqual(propertyValue, mapper.Value); }
/// <summary> /// Sets the Property value. /// </summary> /// <param name="value">The value.</param> /// <param name="config">The config.</param> /// <param name="context">The context.</param> /// <returns>System.String.</returns> /// <exception cref="System.NotImplementedException"></exception> public override object SetPropertyValue(object value, UmbracoPropertyConfiguration config, UmbracoDataMappingContext context) { throw new NotImplementedException(); }