public void MapToProperty_ConfigurationIsLazy_CallsCreateClassOnServiceWithIsLazy() { //Assign using (Db database = new Db { new Sitecore.FakeDb.DbItem("TestItem") }) { var item = database.GetItem("/sitecore/content/TestItem"); var service = Substitute.For <ISitecoreService>(); var options = new GetItemOptionsParams(); options.Lazy = LazyLoading.Enabled; var scContext = new SitecoreDataMappingContext(null, item, service, options); 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 service.Received() .GetItem(Arg.Is <GetItemByItemOptions>(x => x.Item.Uri == item.Parent.Uri && x.Lazy == LazyLoading.Enabled)); } }
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, null); }
/// <summary> /// Configures the specified property info. /// </summary> /// <param name="propertyInfo">The property info.</param> /// <returns>AbstractPropertyConfiguration.</returns> public override Mapper.Configuration.AbstractPropertyConfiguration Configure(System.Reflection.PropertyInfo propertyInfo) { var config = new SitecoreParentConfiguration(); Configure(propertyInfo, config); return(config); }
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); } }
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); }
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); }
/// <summary> /// Configures the specified property info. /// </summary> /// <param name="propertyInfo">The property info.</param> /// <returns>AbstractPropertyConfiguration.</returns> public override Mapper.Configuration.AbstractPropertyConfiguration Configure(System.Reflection.PropertyInfo propertyInfo) { var config = new SitecoreParentConfiguration(); if (TemplateId.HasValue()) { config.TemplateId = new ID(TemplateId); } config.EnforceTemplate = EnforceTemplate; Configure(propertyInfo, config); return(config); }
public void MapToProperty_EnforceTemplate_ReturnsParentItem() { //Assign ID templateId = ID.NewID; ID parentID = ID.NewID; using (Db database = new Db { new Sitecore.FakeDb.DbItem("Parent", parentID, templateId) { new Sitecore.FakeDb.DbItem("TestItem") } }) { var item = database.GetItem("/sitecore/content/Parent/TestItem"); var context = Context.Create(Utilities.CreateStandardResolver()); var service = new SitecoreService(database.Database, context); var options = new GetItemOptionsParams(); options.Lazy = LazyLoading.Enabled; var scContext = new SitecoreDataMappingContext(null, item, service, options); var config = new SitecoreParentConfiguration(); config.PropertyInfo = typeof(Stub).GetProperty("Property"); config.TemplateId = templateId; config.EnforceTemplate = SitecoreEnforceTemplate.TemplateAndBase; var mapper = new SitecoreParentMapper(); mapper.Setup(new DataMapperResolverArgs(null, config)); //Act var result = mapper.MapToProperty(scContext) as Stub; //Assert Assert.NotNull(result); Assert.AreEqual(parentID, result.Id); } }
/// <summary> /// Configures the specified property info. /// </summary> /// <param name="propertyInfo">The property info.</param> /// <param name="config">The config.</param> public void Configure(PropertyInfo propertyInfo, SitecoreParentConfiguration config) { base.Configure(propertyInfo, config); }
/// <summary> /// Configures the specified property info. /// </summary> /// <param name="propertyInfo">The property info.</param> /// <returns>AbstractPropertyConfiguration.</returns> public override Mapper.Configuration.AbstractPropertyConfiguration Configure(System.Reflection.PropertyInfo propertyInfo) { var config = new SitecoreParentConfiguration(); Configure(propertyInfo, config); return config; }