public void MapToProperty_ConfigurationSetupCorrectly_CallsCreateClassOnService() { //Assign using (Db database = new Db { new Sitecore.FakeDb.DbItem("TestItem") }) { var item = database.GetItem("/sitecore/content/TestItem"); var service = Substitute.For<ISitecoreService>(); var scContext = new SitecoreDataMappingContext(null, item, service); var config = new SitecoreParentConfiguration(); config.PropertyInfo = typeof(Stub).GetProperty("Property"); var mapper = new SitecoreParentMapper(); mapper.Setup(new DataMapperResolverArgs(null, config)); //Act var result = mapper.MapToProperty(scContext); //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<Item>(x => x.ID == item.Parent.ID), true, false, null); } }
/// <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; SitecoreInfoType infoType; if (name.Contains(".")) //explicit interface implementation { name = name.Split('.', StringSplitOptions.RemoveEmptyEntries).Last(); } if (name.ToLowerInvariant() == "id") { var idConfig = new SitecoreIdConfiguration(); idConfig.PropertyInfo = property; return(idConfig); } if (name.ToLowerInvariant() == "parent") { var parentConfig = new SitecoreParentConfiguration(); parentConfig.PropertyInfo = property; return(parentConfig); } if (name.ToLowerInvariant() == "children") { var childrenConfig = new SitecoreChildrenConfiguration(); childrenConfig.PropertyInfo = property; return(childrenConfig); } if (name.ToLowerInvariant() == "item" && property.PropertyType == typeof(Item)) { var itemConfig = new SitecoreItemConfiguration(); itemConfig.PropertyInfo = property; return(itemConfig); } if (Enum.TryParse(name, true, out infoType)) { SitecoreInfoConfiguration infoConfig = new SitecoreInfoConfiguration(); infoConfig.PropertyInfo = property; infoConfig.Type = infoType; return(infoConfig); } SitecoreFieldConfiguration fieldConfig = new SitecoreFieldConfiguration(); fieldConfig.FieldName = name; fieldConfig.PropertyInfo = property; return(fieldConfig); }
/// <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; SitecoreInfoType infoType; if (name.ToLowerInvariant() == "id") { var idConfig = new SitecoreIdConfiguration(); idConfig.PropertyInfo = property; return(idConfig); } if (name.ToLowerInvariant() == "parent") { var parentConfig = new SitecoreParentConfiguration(); parentConfig.PropertyInfo = property; return(parentConfig); } if (name.ToLowerInvariant() == "children") { var childrenConfig = new SitecoreChildrenConfiguration(); childrenConfig.PropertyInfo = property; return(childrenConfig); } if (name.ToLowerInvariant() == "item" && property.PropertyType == typeof(Item)) { var itemConfig = new SitecoreItemConfiguration(); itemConfig.PropertyInfo = property; return(itemConfig); } if (Enum.TryParse(name, true, out infoType)) { SitecoreInfoConfiguration infoConfig = new SitecoreInfoConfiguration(); infoConfig.PropertyInfo = property; infoConfig.Type = infoType; return(infoConfig); } SitecoreFieldConfiguration fieldConfig = new SitecoreFieldConfiguration(); fieldConfig.FieldName = name; fieldConfig.PropertyInfo = property; return(fieldConfig); }
public void MapToProperty_ConfigurationIsLazy_CallsCreateClassOnServiceWithIsLazy() { //Assign var db = Sitecore.Configuration.Factory.GetDatabase("master"); var item = db.GetItem("/sitecore/content/Tests/DataMappers/SitecoreParentMapperFixture/EmptyItem"); var service = Substitute.For<ISitecoreService>(); var scContext = new SitecoreDataMappingContext(null, item, service); var config = new SitecoreParentConfiguration(); config.PropertyInfo = typeof(Stub).GetProperty("Property"); config.IsLazy = true; var mapper = new SitecoreParentMapper(); mapper.Setup(new DataMapperResolverArgs(null,config)); //Act var result = mapper.MapToProperty(scContext); //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<Item>(x => x.ID == item.Parent.ID), true, false); }
public void CanHandle_ConfigurationIsSitecoreParent_ReturnsTrue() { //Assign var config = new SitecoreParentConfiguration(); var mapper = new SitecoreParentMapper(); //Act var result = mapper.CanHandle(config, null); //Assert Assert.IsTrue(result); }
protected override AbstractPropertyConfiguration AutoMapProperty(System.Reflection.PropertyInfo property) { string name = property.Name; SitecoreInfoType infoType; if (name.ToLowerInvariant() == "id") { SitecoreIdConfiguration idConfig = new SitecoreIdConfiguration(); idConfig.PropertyInfo = property; return idConfig; } if (name.ToLowerInvariant() == "parent") { SitecoreParentConfiguration parentConfig = new SitecoreParentConfiguration(); parentConfig.PropertyInfo = property; return parentConfig; } if (name.ToLowerInvariant() == "children") { SitecoreChildrenConfiguration childrenConfig = new SitecoreChildrenConfiguration(); childrenConfig.PropertyInfo = property; return childrenConfig; } if (Enum.TryParse(name, true, out infoType)) { SitecoreInfoConfiguration infoConfig = new SitecoreInfoConfiguration(); infoConfig.PropertyInfo = property; infoConfig.Type = infoType; return infoConfig; } SitecoreFieldConfiguration fieldConfig = new SitecoreFieldConfiguration(); fieldConfig.FieldName = name; fieldConfig.PropertyInfo = property; return fieldConfig; }
public void MapToProperty_ParentDoesNotHaveLanguageVersion_ReturnsNull() { //Assign var db = Sitecore.Configuration.Factory.GetDatabase("master"); var language = LanguageManager.GetLanguage("af-ZA"); var item = db.GetItem("/sitecore/content/Tests/DataMappers/SitecoreParentMapperFixture/EmptyItem", language); //parent mustn't have a version Assert.AreEqual(0, item.Parent.Versions.Count); var service = Substitute.For<ISitecoreService>(); var scContext = new SitecoreDataMappingContext(null, item, service); var config = new SitecoreParentConfiguration(); config.PropertyInfo = typeof(Stub).GetProperty("Property"); config.InferType = true; var mapper = new SitecoreParentMapper(); mapper.Setup(new DataMapperResolverArgs(null, config)); //Act var result = mapper.MapToProperty(scContext); //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<Item>(x => x.ID == item.Parent.ID), true, true, null); Assert.IsNull(result); }