public void GetField_EmptyField_ReturnsEmptyList() { //Assign var fieldValue = ""; var item = Database.GetItem("/sitecore/content/Tests/DataMappers/SitecoreFieldIEnumerableMapper/GetField"); var field = item.Fields[FieldName]; var config = new SitecoreFieldConfiguration(); config.PropertyInfo = typeof(StubClass).GetProperty("IList"); var mapper = new SitecoreFieldIEnumerableMapper(); var subMapper = new SitecoreFieldDoubleMapper(); var args = new DataMapperResolverArgs(null, config); args.DataMappers = new[] { subMapper }; mapper.Setup(args); using (new ItemEditing(item, true)) { field.Value = fieldValue; } //Act var result = mapper.GetField(field, config, null) as List <double>; //Assert Assert.AreEqual(0, result.Count); }
public void GetField_ContainsPipeSeparatedValues_ReturnsListOfValues() { //Assign var templateId = ID.NewID; var fieldId = ID.NewID; var targetId = ID.NewID; using (Db database = new Db { new DbTemplate(templateId) { { "Field", "" } }, new Sitecore.FakeDb.DbItem("Target", targetId, templateId), }) { var fieldValue = "1|2|3"; var item = database.GetItem("/sitecore/content/Target"); var field = item.Fields["Field"]; var config = new SitecoreFieldConfiguration(); config.PropertyInfo = typeof(StubClass).GetProperty("IList"); var mapper = new SitecoreFieldIEnumerableMapper(); var subMapper = new SitecoreFieldDoubleMapper(); var args = new DataMapperResolverArgs(null, config); args.DataMappers = new[] { subMapper }; mapper.Setup(args); using (new ItemEditing(item, true)) { field.Value = fieldValue; } //Act var result = mapper.GetField(field, config, null) as List <double>; //Assert Assert.AreEqual(1D, result.Skip(0).First()); Assert.AreEqual(2D, result.Skip(1).First()); Assert.AreEqual(3D, result.Skip(2).First()); } }