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;

            if (attr.FieldId.IsNotNullOrEmpty())
            {
                Guid id = Guid.Empty;

                if (Utility.GuidTryParse(attr.FieldId, out id))
                {
                    FieldId = new ID(id);
                }
                else
                {
                    throw new MapperException("The field Id {0} on property {1} in class {2} isn't in the correct format".Formatted(
                                                  attr.FieldId, scProperty.Property.Name, scProperty.Property.ReflectedType.FullName));
                }
            }

            base.ConfigureDataHandler(scProperty);
        }
        public void Constructor_Sets_FieldName()
        {
            var testFieldName = "testFieldName";
            var testSitecoreFieldAttribute = new SitecoreFieldAttribute(testFieldName);

            Assert.AreEqual(testSitecoreFieldAttribute.FieldName, testFieldName);
        }
        public void Configure_ConfigureCalled_SitecoreQueryConfigurationReturned()
        {
            //Assign
            SitecoreFieldAttribute attr = new SitecoreFieldAttribute(string.Empty);
            var propertyInfo            = typeof(StubClass).GetProperty("DummyProperty");


            //Act
            var result = attr.Configure(propertyInfo) as SitecoreFieldConfiguration;

            //Assert
            Assert.IsNotNull(result);
        }
        public void Configure_SettingNotSet_SettingsReturnAsDefault()
        {
            //Assign
            SitecoreFieldAttribute attr = new SitecoreFieldAttribute(string.Empty);
            var propertyInfo            = typeof(StubClass).GetProperty("DummyProperty");


            //Act
            var result = attr.Configure(propertyInfo) as SitecoreFieldConfiguration;

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(SitecoreFieldSettings.Default, result.Setting);
        }
        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 Configure_SettingIsUnversioned_IsUnversionedIsSetOnConfiguration(
            [Values(true, false)] bool value,
            [Values(true, false)] bool expected)
        {
            //Assign
            SitecoreFieldAttribute attr = new SitecoreFieldAttribute(string.Empty);
            var propertyInfo            = typeof(StubClass).GetProperty("DummyProperty");

            attr.IsUnversioned = value;

            //Act
            var result = attr.Configure(propertyInfo) as SitecoreFieldConfiguration;

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result.IsUnversioned);
        }
        public void Configure_SettingFieldSource_FieldSourceIsSetOnConfiguration(
            [Values("field Source")] string value,
            [Values("field Source")] string expected)
        {
            //Assign
            SitecoreFieldAttribute attr = new SitecoreFieldAttribute(string.Empty);
            var propertyInfo            = typeof(StubClass).GetProperty("DummyProperty");

            attr.FieldSource = value;

            //Act
            var result = attr.Configure(propertyInfo) as SitecoreFieldConfiguration;

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result.FieldSource);
        }
        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);
        }
Exemplo n.º 9
0
        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 Default_Constructor_Set_Setting_To_Default()
        {
            var testSitecoreFieldAttribute = new SitecoreFieldAttribute();

            Assert.AreEqual(testSitecoreFieldAttribute.Setting, SitecoreFieldSettings.Default);
        }
Exemplo n.º 11
0
        private static object GetSitecoreItemFieldValue(ISitecoreItem item, Type propertyType, SitecoreFieldAttribute fieldAttribute)
        {
            ISitecoreField field = null;

            if (!string.IsNullOrEmpty(fieldAttribute.FieldId))
            {
                field = item.GetField(new Guid(fieldAttribute.FieldId));
            }
            else if (!string.IsNullOrEmpty(fieldAttribute.FieldName))
            {
                field = item.GetField(fieldAttribute.FieldName);
            }
            else
            {
                field = item.GetField(fieldAttribute.FieldIndex);
            }

            if (field == null)
            {
                return(null);
            }

            if (propertyType.IsSimple() || propertyType == typeof(DateTime))
            {
                return(GetFieldValueForSimpleType(propertyType, field.Value));
            }

            if (propertyType == typeof(HtmlString))
            {
                return(field.RenderToHtml());
            }

            return(field.CastToCustomField(propertyType));
        }