public MapToProperty ( AbstractDataMappingContext mappingContext ) : object | ||
mappingContext | AbstractDataMappingContext | The mapping context. |
Résultat | object |
public void MapToProperty_ItemHasThreeChildren_ThreeObjectAreCreated() { //Assign using (Db database = new Db { new Sitecore.FakeDb.DbItem("TestItem") { new Sitecore.FakeDb.DbItem("Child1"), new Sitecore.FakeDb.DbItem("Child2"), new Sitecore.FakeDb.DbItem("Child3") } }) { var item = database.GetItem("/sitecore/content/TestItem"); var mapper = new SitecoreChildrenMapper(); var config = new SitecoreChildrenConfiguration(); config.InferType = false; config.IsLazy = false; config.PropertyInfo = typeof(Stub).GetProperty("Children"); var service = Substitute.For<ISitecoreService>(); var predicate = Arg.Is<Item>(x => item.Children.Any(y => x.ID == y.ID)); //ME - Although this looks correct I am not sure it is service.CreateType(typeof(StubChild), predicate, false, false, null) .ReturnsForAnyArgs(info => new StubChild() { Id = info.Arg<Item>().ID }); service.Config.Returns(new Config()); var context = new SitecoreDataMappingContext(null, item, service); mapper.Setup(new DataMapperResolverArgs(null, config)); //Act var result = mapper.MapToProperty(context) as IEnumerable<StubChild>; //Assert Assert.AreEqual(item.Children.Count, result.Count()); foreach (Item child in item.Children) { Assert.IsTrue(result.Any(x => x.Id == child.ID)); } } }
public void MapToProperty_ItemHasNoChildren_NoObjectsCreated() { //Assign var database = Sitecore.Configuration.Factory.GetDatabase("master"); var item = database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreChildrenMapper/Parent/Child1"); var mapper = new SitecoreChildrenMapper(); var config = new SitecoreChildrenConfiguration(); config.InferType = false; config.IsLazy = false; config.PropertyInfo = typeof(Stub).GetProperty("Children"); var service = Substitute.For<ISitecoreService>(); var predicate = Arg.Is<Item>(x => item.Children.Any(y => x.ID == y.ID)); //ME - Although this looks correct I am not sure it is service.CreateType(typeof(StubChild), predicate, false, false, null).ReturnsForAnyArgs(info => new StubChild() { Id = info.Arg<Item>().ID }); service.Config = new Config(); var context = new SitecoreDataMappingContext(null, item, service); mapper.Setup(new DataMapperResolverArgs(null,config)); //Act var result = mapper.MapToProperty(context) as IEnumerable<StubChild>; //Assert Assert.AreEqual(0, result.Count()); }