internal override void ConfigureDataHandler(SitecoreProperty scProperty) { base.ConfigureDataHandler(scProperty); IsLazy = (Setting & SitecoreFieldSettings.DontLoadLazily) != SitecoreFieldSettings.DontLoadLazily; InferType = (Setting & SitecoreFieldSettings.InferType) == SitecoreFieldSettings.InferType; }
public void Setup() { _handler = new SitecoreLinkedHandler(); _database = global::Sitecore.Configuration.Factory.GetDatabase("master"); _target = _database.GetItem("/sitecore/content/Glass/ItemLinksTest"); SitecoreProperty idProperty = new SitecoreProperty(){ Attribute = new SitecoreIdAttribute(), Property = typeof(SitecoreLinkedHandlerFixtureNS.LinkedTestClass).GetProperty("Id") }; SitecoreIdDataHandler idHandler = new SitecoreIdDataHandler(); idHandler.ConfigureDataHandler(idProperty); var context = new InstanceContext( (new SitecoreClassConfig[]{ new SitecoreClassConfig(){ ClassAttribute = new SitecoreClassAttribute(), Properties = new SitecoreProperty[]{ idProperty }, Type = typeof(SitecoreLinkedHandlerFixtureNS.LinkedTestClass), DataHandlers = new AbstractSitecoreDataHandler []{ idHandler } } }).ToDictionary(), new AbstractSitecoreDataHandler[] { }); _service = new SitecoreService(_database, context); }
public void GetValue_ReturnsValidImage() { //Assign Item item = _db.GetItem(new ID(_itemId)); SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(typeof(Image), "Image") }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetValue(item, null) as Image; //Assert Assert.IsNotNull(result); Assert.IsFalse(result.Alt.IsNullOrEmpty()); Assert.AreEqual(540, result.Height); Assert.AreEqual(50, result.HSpace); Assert.IsFalse(result.Src.IsNullOrEmpty()); Assert.AreEqual(60, result.VSpace); Assert.AreEqual(720, result.Width); // Unsure how to test below // result.Border // result.Class // result.MediaItem }
public void GetValue() { //Assign Item item = _db.GetItem(new ID(_itemId)); SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(typeof(Stream), "Attachment") }; _handler.ConfigureDataHandler(property); using (new SecurityDisabler()) { string testString = "Hello World" + DateTime.Now.ToString(); MemoryStream stream = new MemoryStream(); byte[] data = UTF8Encoding.UTF8.GetBytes(testString); stream.Write(data, 0, data.Length); item.Editing.BeginEdit(); item.Fields["Attachment"].SetBlobStream(stream); //Act Stream result = _handler.GetValue(item, null) as Stream; //Assert Assert.IsNotNull(result); item.Editing.CancelEdit(); } }
public void GetValue_SingleLineText_GetsRawString() { //Assign string value= "test single line text"; SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(typeof(string), "SingleLineText") }; _handler.ConfigureDataHandler(property); using (new SecurityDisabler()) { _item.Editing.BeginEdit(); _item["SingleLineText"] = value; //Act var result = _handler.GetValue(_item, null); //Assert Assert.AreEqual(value, result); _item.Editing.CancelEdit(); } }
public override void ConfigureDataHandler(SitecoreProperty scProperty) { SitecoreChildrenAttribute attr = scProperty.Attribute as SitecoreChildrenAttribute; IsLazy = attr.IsLazy; InferType = attr.InferType; base.ConfigureDataHandler(scProperty); }
public override bool WillHandle(Glass.Sitecore.Mapper.Configuration.SitecoreProperty property, IEnumerable <AbstractSitecoreDataHandler> datas, Dictionary <Type, SitecoreClassConfig> classes) { if (!(property.Attribute is SitecoreFieldAttribute)) { return(false); } return(classes.ContainsKey(property.Property.PropertyType)); }
internal override void ConfigureDataHandler(SitecoreProperty scProperty) { SitecoreParentAttribute attr = scProperty.Attribute as SitecoreParentAttribute; this.IsLazy = attr.IsLazy; this.InferType = attr.InferType; base.ConfigureDataHandler(scProperty); }
public void Setup() { _handler = new SitecoreFieldEnumHandler(); _property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = typeof(TestClass).GetProperty("Enum") }; }
public override bool WillHandle(Glass.Sitecore.Mapper.Configuration.SitecoreProperty property, IEnumerable <AbstractSitecoreDataHandler> datas, Dictionary <Type, SitecoreClassConfig> classes) { if (!property.Property.PropertyType.IsGenericType) { return(false); } Type type = Utility.GetGenericOuter(property.Property.PropertyType); return(property.Attribute is SitecoreLinkedAttribute && typeof(IEnumerable <>) == type); }
internal override void ConfigureDataHandler(SitecoreProperty scProperty) { SitecoreFieldAttribute attr = scProperty.Attribute as SitecoreFieldAttribute; if (attr != null && !attr.FieldName.IsNullOrEmpty()) FieldName = attr.FieldName; else FieldName = scProperty.Property.Name; ReadOnly = attr.ReadOnly; Setting = attr.Setting; base.ConfigureDataHandler(scProperty); }
public void WillHandler_ReturnsTrue() { //Assign SitecoreProperty property= new SitecoreProperty() { Attribute = new SitecoreInfoAttribute(SitecoreInfoType.ContentPath) }; //Act var result = _handler.WillHandle(property, null, null); //Assert Assert.IsTrue(result); }
public void WillHandle() { //Assign SitecoreProperty property = new SitecoreProperty(){ Attribute = new SitecoreLinkedAttribute(), Property = new FakePropertyInfo(typeof(IEnumerable<LinkTemplate>)) }; //Act var result =_handler.WillHandle(property, null, null); //Assert Assert.IsTrue(result); }
public void WillHandle_HandlesParentAttribute_ReturnsTrue() { //Assign SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreParentAttribute() }; //Act var result = _handler.WillHandle(property, _service.InstanceContext.Datas, _service.InstanceContext.Classes); //Assert Assert.IsTrue(result); }
public void GetValue_ContentPath() { //Assign SitecoreProperty property= new SitecoreProperty() { Attribute = new SitecoreInfoAttribute(SitecoreInfoType.ContentPath) }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetValue( _item, null); //Assert Assert.AreEqual(_item.Paths.ContentPath, result as string); }
public void CanSetValue_FieldIsWritable_ReturnsTrue() { //Assign SitecoreProperty property = new SitecoreProperty(){ Property = new FakePropertyInfo(typeof(string)), Attribute = new SitecoreFieldAttribute(){ } }; testClass.ConfigureDataHandler(property); //Act var result = testClass.CanSetValue; //Assert Assert.IsTrue(result); }
public void WillHandle_ReturnsFalse_WrongAttribute() { //Assign SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(typeof(Guid)) }; //Act var result = _handler.WillHandle(property, null, null); //Assert Assert.IsFalse(result); }
public void ConfigureHandler_SetIsLazy_True() { //Assign SitecoreFieldAttribute attr = new SitecoreFieldAttribute(); SitecoreProperty property = new SitecoreProperty() { Attribute = attr, Property = new FakePropertyInfo(typeof(string))//this can be anything }; //Act _handler.ConfigureDataHandler(property); //Assert Assert.IsTrue(_handler.IsLazy); }
public void GetValue_ReturnsValidLink_External() { //Assign Item item = _db.GetItem(new ID(_itemId)); SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(typeof(Link), "GeneralLink") }; _handler.ConfigureDataHandler(property); using (new SecurityDisabler()) { item.Editing.BeginEdit(); item["GeneralLink"] = "<link text=\"TestDesc\" querystring=\"TestQuery\" linktype=\"external\" url=\"http://www.google.com\" anchor=\"TestAnchor\" title=\"TestAlt\" class=\"TestClass\" target=\"_blank\" />"; //Act Link result = _handler.GetValue(item, null) as Link; Assert.AreEqual("TestAnchor", result.Anchor); Assert.AreEqual("TestClass", result.Class); Assert.AreEqual("TestQuery", result.Query); Assert.AreEqual("_blank", result.Target); Assert.AreEqual(Guid.Empty, result.TargetId); Assert.AreEqual("TestDesc", result.Text); Assert.AreEqual("TestAlt", result.Title); Assert.AreEqual(LinkType.External, result.Type); Assert.AreEqual("http://www.google.com", result.Url); item.Editing.CancelEdit(); } //Assert }
/// <summary> /// /// </summary> /// <param name="property"></param> public AbstractSitecoreDataHandler GetDataHandler(SitecoreProperty property) { AbstractSitecoreDataHandler handler = Datas.FirstOrDefault(x => x.WillHandle(property, Datas, Classes)); if (handler == null) throw new NotSupportedException("No data handler for: \n\r Class: {0} \n\r Member: {1} \n\r Attribute: {2}" .Formatted( property.Property.ReflectedType.FullName, property.Property.Name, property.Attribute.GetType().FullName )); var newHandler = handler.Clone() as AbstractSitecoreDataHandler; newHandler.ConfigureDataHandler(property); return newHandler; }
public void GetFieldValue_NoHandler_ThrowsException() { //Assign string value = "45|535|22|"; SitecoreProperty property = new SitecoreProperty() { Property = typeof(SitecoreFieldIEnumerableHandlerFixtureNS.TestClass).GetProperty("Test"), Attribute = new SitecoreFieldAttribute() }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetFieldValue(value, null, _service); //Assert //Exception thrown }
public void GetValue_GetsClassUsingId() { //Assign SitecoreItemAttribute attr = new SitecoreItemAttribute(); attr.Id = "{66E62701-3FF2-492D-81A4-BD3E55428837}"; attr.IsLazy = true; SitecoreProperty prop = new SitecoreProperty(); prop.Attribute = attr; prop.Property = new FakePropertyInfo(typeof(EmptyTemplate1)); _handler.ConfigureDataHandler(prop); //Act EmptyTemplate1 result = _handler.GetValue(null, _service) as EmptyTemplate1; //Assert Assert.AreEqual(new Guid(attr.Id), result.Id); }
public void GetValue() { //Assign Item item = _db.GetItem(new ID(_itemId)); SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(typeof(Stream), "Attachment") }; _handler.ConfigureDataHandler(property); //Act Stream stream = _handler.GetValue( item, null) as Stream; //Assert Assert.IsNull(stream); }
public void GetFieldValue_NoHandler_ThrowsException() { //Assign string value = "45|535|22|"; SitecoreProperty property = new SitecoreProperty() { Property = new FakePropertyInfo(typeof(IEnumerable<TestType>)), Attribute = new SitecoreFieldAttribute() }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetFieldValue(value, null, _service); //Assert //Exception thrown }
public void SetValue() { //Assign Item item = _db.GetItem(new ID(_itemId)); SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(typeof(Stream), "Attachment") }; _handler.ConfigureDataHandler(property); string testString = "Hello World" + DateTime.Now.ToString(); MemoryStream stream = new MemoryStream(); byte[] data = UTF8Encoding.UTF8.GetBytes(testString); stream.Write(data, 0, data.Length); using (new SecurityDisabler()) { item.Editing.BeginEdit(); //Act _handler.SetValue( item, stream, null); //Assert Stream result = item.Fields["Attachment"].GetBlobStream(); Assert.AreEqual(data.Length, result.Length); byte[] dataOut = new byte[result.Length]; result.Read(dataOut, 0, dataOut.Length); string text = UTF8Encoding.UTF8.GetString(dataOut); Assert.AreEqual(testString, text); //tidy up item.Editing.CancelEdit(); } }
/// <summary> /// /// </summary> /// <param name="property"></param> public AbstractSitecoreDataHandler GetDataHandler(SitecoreProperty property) { AbstractSitecoreDataHandler newHandler; if (property.Attribute.DataHandler != null) { Type dataType = property.Attribute.DataHandler; if (typeof (AbstractSitecoreDataHandler).IsAssignableFrom(dataType)) { try { newHandler = (AbstractSitecoreDataHandler) dataType.Assembly.CreateInstance(dataType.FullName); } catch (Exception ex) { throw new MapperException( "Failed to create instance of the data handler {0} configured on property {0} on class {1}" .Formatted(dataType.FullName, property.Property.Name, property.Property.ReflectedType.FullName), ex); } } else throw new MapperException( "Custom data handler does not inherit from AbstractSitecoreDataHandler for {0} on class" .Formatted(property.Property.Name, property.Property.ReflectedType.FullName)); } else { AbstractSitecoreDataHandler handler = Datas.FirstOrDefault(x => x.WillHandle(property, Datas, Classes)); if (handler == null) throw new NotSupportedException("No data handler for: \n\r Class: {0} \n\r Member: {1} \n\r Attribute: {2}" .Formatted( property.Property.ReflectedType.FullName, property.Property.Name, property.Attribute.GetType().FullName )); newHandler = handler.Clone() as AbstractSitecoreDataHandler; } newHandler.ConfigureDataHandler(property); return newHandler; }
public void ConfigureDataHandler_CorrectlyConfiguresWithPath() { //Assign SitecoreItemAttribute attr = new SitecoreItemAttribute(); attr.Path = "/stecore/content"; attr.IsLazy = true; SitecoreProperty prop = new SitecoreProperty(); prop.Attribute = attr; //Act _handler.ConfigureDataHandler(prop); //Assert Assert.AreEqual(Guid.Empty, _handler.Id); Assert.AreEqual(attr.IsLazy, _handler.IsLazy); Assert.AreEqual(prop, _handler.Property); Assert.AreEqual(attr.Path, _handler.Path); }
public void ConfigureDataHandler_CorrectlyConfiguresWithID() { //Assign SitecoreItemAttribute attr = new SitecoreItemAttribute(); attr.Id = "{51C00CB9-E82F-4445-8B3A-F2E9A29B2876}"; attr.IsLazy = true; SitecoreProperty prop = new SitecoreProperty(); prop.Attribute = attr; //Act _handler.ConfigureDataHandler(prop ); //Assert Assert.AreEqual(new Guid(attr.Id), _handler.Id); Assert.AreEqual(attr.IsLazy, _handler.IsLazy); Assert.AreEqual(prop, _handler.Property); Assert.IsTrue(_handler.Path.IsNullOrEmpty()); }
public void GetValue_NoField_ReturnsNull() { //Assign Item item = _db.GetItem(new ID(_itemId)); SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(typeof(File), "NoField") }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetValue(item, null) as File; //Assert Assert.IsNull(result); }
public void GetValue_ReturnsValidFile() { //Assign Item item = _db.GetItem(new ID(_itemId)); SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(typeof(File), "File") }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetValue(item, null) as File; //Assert Assert.AreEqual("/~/media/Files/SimpleTextFile.ashx", result.Src); Assert.AreEqual(new Guid("{368A358E-5835-458B-AFE6-BA5F80334F5A}"), result.Id); }
public void GetValue_ReturnsValidRules() { //Assign Item item = _db.GetItem(new ID(_itemId)); Type propertyType = typeof(RuleList<>).MakeGenericType(new Type[] {typeof (TestRuleContext)}); SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(propertyType, "Rules") }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetValue(item, null) as RuleList<TestRuleContext>; //Assert Assert.IsNotNull(result); Assert.True(result.Count == 2); }
public override bool WillHandle(Glass.Sitecore.Mapper.Configuration.SitecoreProperty property, IEnumerable <AbstractSitecoreDataHandler> datas, Dictionary <Type, SitecoreClassConfig> classes) { if (!(property.Attribute is SitecoreFieldAttribute)) { return(false); } Type type = property.Property.PropertyType; if (!type.IsGenericType) { return(false); } if (type.GetGenericTypeDefinition() != typeof(IEnumerable <>) && type.GetGenericTypeDefinition() != typeof(IList <>)) { return(false); } return(true); }
public void GetFieldValue_ReturnsArrayOfIntegers() { //Assign string value = "45|535|22|"; SitecoreProperty property = new SitecoreProperty() { Property = new FakePropertyInfo(typeof(IEnumerable<int>)), Attribute = new SitecoreFieldAttribute() }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetFieldValue(value, null, _service); //Assert var list = result as IEnumerable<int>; Assert.AreEqual(3, list.Count()); Assert.AreEqual(45, list.First()); Assert.AreEqual(535, list.Take(2).Last()); Assert.AreEqual(22, list.Last()); }
public override bool WillHandle(Glass.Sitecore.Mapper.Configuration.SitecoreProperty property, IEnumerable <AbstractSitecoreDataHandler> datas, Dictionary <Type, SitecoreClassConfig> classes) { return(property.Attribute is SitecoreInfoAttribute); }
public override bool WillHandle(Glass.Sitecore.Mapper.Configuration.SitecoreProperty property, IEnumerable <AbstractSitecoreDataHandler> datas, Dictionary <Type, SitecoreClassConfig> classes) { return(property.Property.PropertyType.IsEnum && property.Property.PropertyType != typeof(FieldTypes.TriState)); }