public void GetFieldValue_FieldContainsInvalidId_ReturnsNull() { //Assign var itemId = Guid.NewGuid(); using (Db database = new Db { new DbItem("Target", new ID(itemId)) { { "Field", "invalid id" } } }) { var item = database.GetItem("/sitecore/content/Target"); var mapper = new SitecoreFieldItemMapper(); var field = item.Fields["Field"]; var config = new SitecoreFieldConfiguration(); var context = Context.Create(Utilities.CreateStandardResolver()); var service = new SitecoreService(database.Database, context); var options = new GetItemOptionsParams(); var scContext = new SitecoreDataMappingContext(null, item, service, options); //Act var result = mapper.GetFieldValue(field.Value, config, scContext) as Item; //Assert Assert.Null(result); } }
public void GetFieldValue_FieldContainsId_ReturnsItem() { //Assign var itemId = Guid.NewGuid(); using (Db database = new Db { new DbItem("Target", new ID(itemId)) { { "Field", new ID(itemId).ToString() } } }) { var item = database.GetItem("/sitecore/content/Target"); var mapper = new SitecoreFieldItemMapper(); var field = item.Fields["Field"]; var config = new SitecoreFieldConfiguration(); var context = Context.Create(Utilities.CreateStandardResolver()); var service = new SitecoreService(database.Database, context); var scContext = new SitecoreDataMappingContext(null, item, service); //Act var result = mapper.GetFieldValue(field.Value, config, scContext) as Item; //Assert Assert.NotNull(result); Assert.AreEqual(item.ID, result.ID); Assert.AreEqual(item.Name, "Target"); } }