public void GetValue_FullPath() { //Assign SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreInfoAttribute(SitecoreInfoType.FullPath) }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetValue(_item, null); //Assert Assert.AreEqual(_item.Paths.FullPath, result as string); }
public void SetFieldValue_ReturnsEnumValue() { //Assign TestEnum value = TestEnum.Berry; SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(typeof(TestEnum)) }; _handler.ConfigureDataHandler(property); //Act var result = _handler.SetFieldValue(value, null); //Assert Assert.AreEqual("Berry", result); }
public void ConfigureHandler_SetIsLazy_True_InferType_False() { //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); Assert.IsFalse(_handler.InferType); }
public void ConfigureHandler_SetIsLazy_False() { //Assign SitecoreFieldAttribute attr = new SitecoreFieldAttribute(); attr.Setting = SitecoreFieldSettings.DontLoadLazily; SitecoreProperty property = new SitecoreProperty() { Attribute = attr, Property = new FakePropertyInfo(typeof(string))//this can be anything }; //Act _handler.ConfigureDataHandler(property); //Assert Assert.IsFalse(_handler.IsLazy); }
public void GetValue_Url() { //Assign SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreInfoAttribute(SitecoreInfoType.Url) }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetValue(_item, null); //Assert var value = LinkManager.GetItemUrl(_item); Assert.AreEqual(value, result as string); }
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 SetFieldValue_NotLoadedClass_ThrowsException() { //Assign NotLoadedClass target = new NotLoadedClass(); target.Id = Guid.NewGuid(); SitecoreProperty property = AttributeConfigurationLoader.GetProperty(typeof(RootClass).GetProperty("NotLoaded")); _handler.ConfigureDataHandler(property); //Act var result = _handler.SetFieldValue(target, _service); //Assert Assert.AreEqual(target.Id, new Guid(result)); }
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 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 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 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 void GetValue_NoFieldReturnsEmptyString() { //Assign SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(typeof(string), "NoField") }; _handler.ConfigureDataHandler(property); using (new SecurityDisabler()) { //Act var result = _handler.GetValue(_item, null); //Assert Assert.IsNullOrEmpty((string)result); } }
/// <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 GetValue_ParentClassNotLoaded_ThrowsException() { //Assign Item item = _db.GetItem(_itemPath); SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreParentAttribute(), Property = new FakePropertyInfo(typeof(NotLoaded)) }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetValue(item, _service) as EmptyTemplate1; //Assert //expecting an exception }
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_MediaUrl() { //Assign SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreInfoAttribute(SitecoreInfoType.MediaUrl) }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetValue(_item, null); //Assert //It think this test is probably wrong global::Sitecore.Data.Items.MediaItem media = new global::Sitecore.Data.Items.MediaItem(_item); string value = global::Sitecore.Resources.Media.MediaManager.GetMediaUrl(media); Assert.AreEqual(value, result as string); }
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()); }
/// <summary> /// /// </summary> /// <param name="property"></param> public AbstractSitecoreDataHandler GetDataHandler(SitecoreProperty property) { if (property.Attribute.DataHandler != null) { Type dataType = property.Attribute.DataHandler; if (typeof(AbstractSitecoreDataHandler).IsAssignableFrom(dataType)) { try { return((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)); } } 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_InvalidData_ReturnsNull() { //Assign //Assign Item item = _db.GetItem(_item1Path); SitecoreProperty property = AttributeConfigurationLoader.GetProperty(typeof(RootClass).GetProperty("LazyLoaded")); _handler.ConfigureDataHandler(property); RootClass root = new RootClass(); //Act var result = _handler.GetFieldValue( "random value", item, _service); root.LazyLoaded = result as EmptyTemplate1; //Assert Assert.IsNull(root.LazyLoaded); }
private AbstractSitecoreField GetSubHandler(Type type, ISitecoreService service) { SitecoreProperty fakeProp = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute() { FieldName = FieldName, ReadOnly = ReadOnly, Setting = Setting }, Property = new FakePropertyInfo(type) }; var handler = service.InstanceContext.GetDataHandler(fakeProp) as AbstractSitecoreField; if (handler == null) { throw new NotSupportedException("No handler to support field type {0}".Formatted(type.FullName)); } return(handler); }
public void SetFieldValue_ReturnsPipeString() { //Assign IEnumerable <int> list = new int[] { 44, 535, 22 }; SitecoreProperty property = new SitecoreProperty() { Property = new FakePropertyInfo(typeof(IEnumerable <int>)), Attribute = new SitecoreFieldAttribute() }; _handler.ConfigureDataHandler(property); //Act var result = _handler.SetFieldValue( list, _service); //Assert Assert.AreEqual("44|535|22", result); }
public void SetFieldValue_HandlesNull() { //Assign IEnumerable <int> list = null; SitecoreProperty property = new SitecoreProperty() { Property = new FakePropertyInfo(typeof(IEnumerable <int>)), Attribute = new SitecoreFieldAttribute() }; _handler.ConfigureDataHandler(property); //Act var result = _handler.SetFieldValue( list, _service); //Assert Assert.AreEqual("", result); }
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(); } }
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 }
public void GetValue_GetsClassUsingPath() { //Assign SitecoreItemAttribute attr = new SitecoreItemAttribute(); attr.Path = "/sitecore/content/Data/SitecoreItemHandler/Item1"; 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(attr.Path, result.Path); }
public void GetValue_RichText_GetsModifiedString() { //Assign //for the render method we have to set a site context for link replacement. //this also required a change in the app.config for the website site config, database changed to master //in express edition the website database is set to web instead of master global::Sitecore.Context.Site = global::Sitecore.Configuration.Factory.GetSite("website"); SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreFieldAttribute(), Property = new FakePropertyInfo(typeof(string), "RichText") }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetValue(_item, null); //Assert Assert.AreNotEqual(_richTextContent, result); }
public void SetValue_NoFieldExists_DoesNothing() { //Assign string value = "some test string"; SitecoreProperty property = new SitecoreProperty() { Property = new FakePropertyInfo(typeof(string), "No field"), Attribute = new SitecoreFieldAttribute() { Setting = SitecoreFieldSettings.RichTextRaw } }; _handler.ConfigureDataHandler(property); //Act _handler.SetValue(_item, value, null); //Assert //nothing to test }
public void GetValue_ReturnsResults_NotLazyLoad() { //Assign string query = "/sitecore/content/Data/SitecoreQueryHandler/*"; SitecoreProperty property = new SitecoreProperty() { Attribute = new SitecoreQueryAttribute(query) { IsLazy = false }, Property = new FakePropertyInfo(typeof(IEnumerable <EmptyTemplate1>)) }; _handler.ConfigureDataHandler(property); //Act var result = _handler.GetValue(_item, _service) as IEnumerable <EmptyTemplate1>; //Assert Assert.AreEqual(3, result.Count()); Assert.AreEqual(typeof(EmptyTemplate1), result.First().GetType()); }