/// <summary> /// Called to map each property automatically /// </summary> /// <param name="property"></param> /// <returns></returns> protected override AbstractPropertyConfiguration AutoMapProperty(System.Reflection.PropertyInfo property) { string name = property.Name; UmbracoInfoType infoType; if (name.ToLowerInvariant() == "id") { UmbracoIdConfiguration idConfig = new UmbracoIdConfiguration(); idConfig.PropertyInfo = property; return(idConfig); } if (name.ToLowerInvariant() == "parent") { UmbracoParentConfiguration parentConfig = new UmbracoParentConfiguration(); parentConfig.PropertyInfo = property; return(parentConfig); } if (name.ToLowerInvariant() == "children") { UmbracoChildrenConfiguration childrenConfig = new UmbracoChildrenConfiguration(); childrenConfig.PropertyInfo = property; return(childrenConfig); } if (Enum.TryParse(name, true, out infoType)) { UmbracoInfoConfiguration infoConfig = new UmbracoInfoConfiguration(); infoConfig.PropertyInfo = property; infoConfig.Type = infoType; return(infoConfig); } UmbracoPropertyConfiguration fieldConfig = new UmbracoPropertyConfiguration(); fieldConfig.PropertyAlias = name; fieldConfig.PropertyInfo = property; return(fieldConfig); }
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> /// Called to map each property automatically /// </summary> /// <param name="property"></param> /// <returns></returns> protected override AbstractPropertyConfiguration AutoMapProperty(System.Reflection.PropertyInfo property) { string name = property.Name; UmbracoInfoType infoType; if (name.ToLowerInvariant() == "id") { UmbracoIdConfiguration idConfig = new UmbracoIdConfiguration(); idConfig.PropertyInfo = property; return idConfig; } if (name.ToLowerInvariant() == "parent") { UmbracoParentConfiguration parentConfig = new UmbracoParentConfiguration(); parentConfig.PropertyInfo = property; return parentConfig; } if (name.ToLowerInvariant() == "children") { UmbracoChildrenConfiguration childrenConfig = new UmbracoChildrenConfiguration(); childrenConfig.PropertyInfo = property; return childrenConfig; } if (Enum.TryParse(name, true, out infoType)) { UmbracoInfoConfiguration infoConfig = new UmbracoInfoConfiguration(); infoConfig.PropertyInfo = property; infoConfig.Type = infoType; return infoConfig; } UmbracoPropertyConfiguration fieldConfig = new UmbracoPropertyConfiguration(); fieldConfig.PropertyAlias = name; fieldConfig.PropertyInfo = property; return fieldConfig; }
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 }
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); }
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 CanHandle_ConfigurationIsUmbracoInfo_ReturnsFalse() { //Assign var config = new UmbracoInfoConfiguration(); var mapper = new UmbracoParentMapper(); //Act var result = mapper.CanHandle(config, null); //Assert Assert.IsFalse(result); }