public void MapToCms_SavingName_UpdatesTheItemName()
        {
            //Assign
            var type     = SitecoreInfoType.Name;
            var expected = "new  name";

            var mapper = new SitecoreInfoMapper();
            var config = new SitecoreInfoConfiguration();

            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            var item = _db.GetItem("/sitecore/Content/Tests/DataMappers/SitecoreInfoMapper/DataMappersEmptyItem");

            Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");


            var dataContext = new SitecoreDataMappingContext(null, item, null);

            dataContext.PropertyValue = expected;

            string actual = string.Empty;

            //Act
            using (new SecurityDisabler())
            {
                item.Editing.BeginEdit();
                mapper.MapToCms(dataContext);
                actual = item.Name;
                item.Editing.CancelEdit();
            }

            //Assert
            Assert.AreEqual(expected, actual);
        }
 /// <summary>
 /// Configures the specified property info.
 /// </summary>
 /// <param name="propertyInfo">The property info.</param>
 /// <param name="config">The config.</param>
 public void Configure(PropertyInfo propertyInfo, SitecoreInfoConfiguration config)
 {
     config.Type = Type;
     config.UrlOptions = UrlOptions;
     config.MediaUrlOptions = MediaUrlOptions;
     base.Configure(propertyInfo, config);
 }
        public void MapToProperty_SitecoreInfoTypeTemplateId_ReturnsTemplateIdAsID()
        {
            //Assign
            var type = SitecoreInfoType.TemplateId;

            var mapper = new SitecoreInfoMapper();
            var config = new SitecoreInfoConfiguration();

            config.Type         = type;
            config.PropertyInfo = typeof(Stub).GetProperty("TemplateId");

            mapper.Setup(new DataMapperResolverArgs(null, config));

            var item     = _db.GetItem("/sitecore/Content/Tests/DataMappers/SitecoreInfoMapper/DataMappersEmptyItem");
            var expected = item.TemplateID;

            Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
            var dataContext = new SitecoreDataMappingContext(null, item, null);

            //Act
            var value = mapper.MapToProperty(dataContext);

            //Assert
            Assert.AreEqual(expected, value);
        }
Пример #4
0
        public void MapToProperty_SitecoreInfoTypeNotSet_ThrowsException()
        {
            //Assign
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
            })
            {
                SitecoreInfoType type = SitecoreInfoType.NotSet;

                var mapper = new SitecoreInfoMapper();
                var config = new SitecoreInfoConfiguration();
                config.Type = type;

                var item    = database.GetItem("/sitecore/Content/TestItem");
                var options = new GetItemOptionsParams();

                Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
                var dataContext = new SitecoreDataMappingContext(null, item, null, options);

                //Act
                Assert.Throws <MapperException>(() => mapper.Setup(new DataMapperResolverArgs(null, config)));

                //Assert
                //No asserts expect exception
            }
        }
Пример #5
0
        /// <summary>
        /// Configures the specified property info.
        /// </summary>
        /// <param name="propertyInfo">The property info.</param>
        /// <returns>AbstractPropertyConfiguration.</returns>
        public override Mapper.Configuration.AbstractPropertyConfiguration Configure(System.Reflection.PropertyInfo propertyInfo)
        {
            var config = new SitecoreInfoConfiguration();

            Configure(propertyInfo, config);
            return(config);
        }
        public void MapToProperty_SitecoreInfoTypeBaseTemplateIds_ReturnsBaseTemplateIds()
        {
            //Assign
            var type = SitecoreInfoType.BaseTemplateIds;

            var mapper = new SitecoreInfoMapper();
            var config = new SitecoreInfoConfiguration();

            config.Type         = type;
            config.PropertyInfo = typeof(Stub).GetProperty("BaseTemplateIds");

            mapper.Setup(new DataMapperResolverArgs(null, config));

            var item = _db.GetItem("/sitecore/Content/Tests/DataMappers/SitecoreInfoMapper/DataMappersEmptyItem");

            Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
            var dataContext = new SitecoreDataMappingContext(null, item, null);

            //Act
            IEnumerable <ID> results;

            using (new SecurityDisabler())
            {
                results = mapper.MapToProperty(dataContext) as IEnumerable <ID>;
            }

            //Assert
            Assert.Greater(results.Count(), 10);
            Assert.IsTrue(results.All(x => x != item.TemplateID));
        }
Пример #7
0
        public void MapToProperty_SitecoreInfoTypeTemplateId_ReturnsTemplateIdAsID()
        {
            //Assign

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
            })
            {
                var type = SitecoreInfoType.TemplateId;

                var mapper  = new SitecoreInfoMapper();
                var options = new GetItemOptionsParams();
                var config  = new SitecoreInfoConfiguration();
                config.Type         = type;
                config.PropertyInfo = typeof(Stub).GetProperty("TemplateId");

                mapper.Setup(new DataMapperResolverArgs(null, config));

                var item     = database.GetItem("/sitecore/Content/TestItem");
                var expected = item.TemplateID;

                Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
                var dataContext = new SitecoreDataMappingContext(null, item, null, options);

                //Act
                var value = mapper.MapToProperty(dataContext);

                //Assert
                Assert.AreEqual(expected, value);
            }
        }
        public void MapToProperty_SitecoreInfoTypeLanguage_ReturnsEnStringType()
        {
            //Assign
            var type = SitecoreInfoType.Language;

            var mapper = new SitecoreInfoMapper();
            var config = new SitecoreInfoConfiguration();

            config.Type         = type;
            config.PropertyInfo = new FakePropertyInfo(typeof(string), "StringField", typeof(Stub));
            mapper.Setup(new DataMapperResolverArgs(null, config));

            var item = _db.GetItem("/sitecore/Content/Tests/DataMappers/SitecoreInfoMapper/DataMappersEmptyItem");

            var expected = item.Language.Name;


            Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
            var dataContext = new SitecoreDataMappingContext(null, item, null);

            //Act
            var value = mapper.MapToProperty(dataContext);

            //Assert
            Assert.AreEqual(expected, value);
        }
Пример #9
0
        public void ConfigMapProperties_ImportMap_CanOverrideExistingPropertyConfig()
        {
            //Assign
            FinalStubMap         finalStubMap         = new FinalStubMap();
            FinalStubSubClassMap finalStubSubClassMap = new FinalStubSubClassMap();
            PartialStub1Map      partialStub1Map      = new PartialStub1Map();
            PartialStub2Map      partialStub2Map      = new PartialStub2Map();
            StubBaseMap          stubBaseMap          = new StubBaseMap();

            SitecoreFluentConfigurationLoader loader = new SitecoreFluentConfigurationLoader();
            ConfigurationMap configMap = new ConfigurationMap(new IGlassMap[] { partialStub1Map, stubBaseMap, partialStub2Map, finalStubMap, finalStubSubClassMap });

            configMap.Load(loader);

            //Act
            finalStubMap.PerformMap(loader);
            finalStubSubClassMap.PerformMap(loader);

            //Assert
            Assert.AreEqual(5, finalStubSubClassMap.GlassType.Config.Properties.Count());
            SitecoreFieldConfiguration fieldNameProperty = finalStubSubClassMap.GlassType.Config.Properties.FirstOrDefault(x => x.PropertyInfo.Name == "FieldName") as SitecoreFieldConfiguration;

            Assert.AreEqual("Field Other Name", fieldNameProperty.FieldName);

            SitecoreInfoConfiguration qwertyProperty = finalStubSubClassMap.GlassType.Config.Properties.FirstOrDefault(x => x.PropertyInfo.Name == "Qwerty") as SitecoreInfoConfiguration;

            Assert.AreEqual(SitecoreInfoType.Name, qwertyProperty.Type);

            Assert.IsNotNull(finalStubSubClassMap.GlassType.Config.IdConfig);
        }
Пример #10
0
        public void MapToProperty_SitecoreInfoTypeLanguage_ReturnsEnLanguageType()
        {

            //Assign

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
            })
            {
                var type = SitecoreInfoType.Language;

                var mapper = new SitecoreInfoMapper();
                var config = new SitecoreInfoConfiguration();
                config.Type = type;
                mapper.Setup(new DataMapperResolverArgs(null, config));

                var item = database.GetItem("/sitecore/Content/TestItem");

                var expected = item.Language;

                Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
                var dataContext = new SitecoreDataMappingContext(null, item, null);

                //Act
                var value = mapper.MapToProperty(dataContext);

                //Assert
                Assert.AreEqual(expected, value);
            }
        }
Пример #11
0
        /// <summary>
        /// Configures the specified property info.
        /// </summary>
        /// <param name="propertyInfo">The property info.</param>
        /// <param name="config">The config.</param>
        public void Configure(PropertyInfo propertyInfo, SitecoreInfoConfiguration config)
        {
            config.Type       = this.Type;
            config.UrlOptions = this.UrlOptions;

            base.Configure(propertyInfo, config);
        }
Пример #12
0
        public void MapToProperty_SitecoreInfoTypeItemuri_ReturnsFullItemUri()
        {
            //Assign
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
            })
            {
                var type    = SitecoreInfoType.ItemUri;
                var options = new GetItemOptionsParams();

                var mapper = new SitecoreInfoMapper();
                var config = new SitecoreInfoConfiguration();
                config.Type         = type;
                config.PropertyInfo = new FakePropertyInfo(typeof(string), "StringField", typeof(Stub));
                mapper.Setup(new DataMapperResolverArgs(null, config));

                var item = database.GetItem("/sitecore/Content/TestItem");

                Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
                var dataContext = new SitecoreDataMappingContext(null, item, null, options);

                //Act
                var value = mapper.MapToProperty(dataContext) as ItemUri;

                //Assert
                Assert.AreEqual(item.ID, value.ItemID);
                Assert.AreEqual(item.Language, value.Language);
                Assert.AreEqual(item.Database.Name, value.DatabaseName);
                Assert.AreEqual(item.Version, value.Version);
            }
        }
        public void MapToProperty_MediaUrlWithFlag_ReturnsModifiedUrl(
            SitecoreInfoMediaUrlOptions option,
            string expected
            )
        {
            //Assign
            var mapper = new SitecoreInfoMapper();
            var config = new SitecoreInfoConfiguration();

            config.Type            = SitecoreInfoType.MediaUrl;
            config.MediaUrlOptions = option;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            Sitecore.Context.Site = null;

            var item = _db.GetItem("/sitecore/Content/Tests/DataMappers/SitecoreInfoMapper/DataMappersEmptyItem");

            Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
            var dataContext = new SitecoreDataMappingContext(null, item, null);

            //Act
            var value = mapper.MapToProperty(dataContext);

            //Assert
            Assert.AreEqual(expected, value);
        }
Пример #14
0
        /// <summary>
        /// Provides the implementation for operations that get member values. Classes derived from the <see cref="T:System.Dynamic.DynamicObject" /> class can override this method to specify dynamic behavior for operations such as getting a value for a property.
        /// </summary>
        /// <param name="binder">Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, where sampleObject is an instance of the class derived from the <see cref="T:System.Dynamic.DynamicObject" /> class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.</param>
        /// <param name="result">The result of the get operation. For example, if the method is called for a property, you can assign the property value to <paramref name="result" />.</param>
        /// <returns>true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a run-time exception is thrown.)</returns>
        /// <exception cref="System.NotSupportedException">No field of Sitecore info matches the name {0} for item {1}.Formatted(name, _item.Paths.FullPath)</exception>
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;

            string name = binder.Name;

            if (name == "Id")
            {
                result = _item.ID;
                return(true);
            }


            if (_item.Fields[name] != null)
            {
                result = GetField(name, _item);
                return(true);
            }

            SitecoreInfoType infoType;

            if (Enum.TryParse <SitecoreInfoType>(name, out infoType))
            {
                var mapper = new SitecoreInfoMapper();
                var config = new SitecoreInfoConfiguration();
                config.Type = infoType;

                mapper.Setup(new DataMapperResolverArgs(null, config));
                result = mapper.MapToProperty(new SitecoreDataMappingContext(null, _item, null));
                return(true);
            }



            switch (name)
            {
            case "Parent":
                result = CreateNew(_item.Parent);
                break;

            case "Children":
                result = new DynamicCollection <DynamicItem>(_item.Children.Select(x => CreateNew(x)).ToArray());
                break;
            }



            if (result == null)
            {
                result = string.Empty;
            }

            return(result != null);

            //throw new NotSupportedException("No field of Sitecore info matches the name {0} for item {1}".Formatted(name, _item.Paths.FullPath));
        }
Пример #15
0
        private T GetInfo <T>(SitecoreInfoType infoType)
        {
            var mapper = new SitecoreInfoMapper();
            var config = new SitecoreInfoConfiguration();

            config.Type = infoType;
            //  config.PropertyInfo = new FakePropertyInfo(typeof(T),typeof(DynamicItem));
            mapper.Setup(new DataMapperResolverArgs(null, config));
            return((T)mapper.MapToProperty(new SitecoreDataMappingContext(null, _item, null)));
        }
Пример #16
0
        public void MapToProperty_SitecoreInfoType_GetsExpectedValueFromSitecore(
            SitecoreInfoType type, object expected
            )
        {
            //Assign
            var mapper = new SitecoreInfoMapper();
            var config = new SitecoreInfoConfiguration();

            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            Sitecore.Context.Site = null;
            var templateId = ID.NewID;
            var itemId     = new ID("031501A9C7F24596BD659276DA3A627A");
            var options    = new GetItemOptionsParams();

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbTemplate("TestTemplate", templateId),
                new Sitecore.FakeDb.DbItem("TestItem", itemId)
                {
                    Fields = { new FakeDbField(new ID("{B5E02AD9-D56F-4C41-A065-A133DB87BDEB}"), "DataMappersEmptyItem DisplayName") },
                    TemplateID = templateId,
                }
            })
            {
#if SC90 || SC91 || SC92
                var mediaUrlProvider = Substitute.For <BaseMediaManager>();

                SitecoreVersionAbstractions.MediaManager = new LazyResetable <BaseMediaManager>(() => mediaUrlProvider);

                mediaUrlProvider
                .GetMediaUrl(Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == itemId), Arg.Any <MediaUrlOptions>())
                .Returns("/~/media/Test.ashx");
#else
                Sitecore.Resources.Media.MediaProvider mediaProvider = Substitute.For <Sitecore.Resources.Media.MediaProvider>();
                mediaProvider
                .GetMediaUrl(Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == itemId), Arg.Any <MediaUrlOptions>())
                .Returns("/~/media/Test.ashx");

                new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider);
#endif

                var item = database.GetItem("/sitecore/content/TestItem");
                Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
                var dataContext = new SitecoreDataMappingContext(null, item, null, options);

                //Act
                var value = mapper.MapToProperty(dataContext);

                //Assert
                Assert.AreEqual(expected, value);
            }
        }
        public void CanHandle_ConfigurationIsSitecoreInfo_ReturnsFalse()
        {
            //Assign
            var config = new SitecoreInfoConfiguration();
            var mapper = new SitecoreParentMapper();

            //Act
            var result = mapper.CanHandle(config, null);

            //Assert
            Assert.IsFalse(result);
        }
        public void MapToProperty_SitecoreInfoType_GetsExpectedValueFromSitecore(
            [Values(
                 SitecoreInfoType.ContentPath,
                 SitecoreInfoType.DisplayName,
                 SitecoreInfoType.FullPath,
                 SitecoreInfoType.Key,
                 SitecoreInfoType.MediaUrl,
                 SitecoreInfoType.Name,
                 SitecoreInfoType.Path,
                 SitecoreInfoType.TemplateName,
                 SitecoreInfoType.Url,
                 SitecoreInfoType.Version
                 )] SitecoreInfoType type,
            [Values(
                 "/Tests/DataMappers/SitecoreInfoMapper/DataMappersEmptyItem",                          //content path
                 "DataMappersEmptyItem DisplayName",                                                    //DisplayName
                 "/sitecore/content/Tests/DataMappers/SitecoreInfoMapper/DataMappersEmptyItem",         //FullPath
                 "datamappersemptyitem",                                                                //Key
                 "/~/media/031501A9C7F24596BD659276DA3A627A.ashx",                                      //MediaUrl
                 "DataMappersEmptyItem",                                                                //Name
                 "/sitecore/content/Tests/DataMappers/SitecoreInfoMapper/DataMappersEmptyItem",         //Path
                 "DataMappersEmptyItem",                                                                //TemplateName
                 "/en/sitecore/content/Tests/DataMappers/SitecoreInfoMapper/DataMappersEmptyItem.aspx", //Url
                 1                                                                                      //version

                 )] object expected
            )
        {
            //Assign
            var mapper = new SitecoreInfoMapper();
            var config = new SitecoreInfoConfiguration();

            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            Sitecore.Context.Site = null;

            var item = _db.GetItem("/sitecore/Content/Tests/DataMappers/SitecoreInfoMapper/DataMappersEmptyItem");

            Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
            var dataContext = new SitecoreDataMappingContext(null, item, null);

            //Act
            var value = mapper.MapToProperty(dataContext);

            //Assert
            Assert.AreEqual(expected, value);
        }
Пример #19
0
        public SitecoreRepository(IDatabaseProvider dbProvider,
                                  ISitecoreServiceProvider sitecoreServiceProvider,
                                  IProviderSearchContextProvider searchContextProvider,
                                  ILogger logger)
        {
            _dbProvider = dbProvider;
            _sitecoreServiceProvider = sitecoreServiceProvider;
            _searchContextProvider   = searchContextProvider;
            _logger = logger;

            var classInfo = _sitecoreServiceProvider.GetSitecoreService().GlassContext[typeof(T)];

            _parentProperty = classInfo.Properties.OfType <ParentConfiguration>().FirstOrDefault();

            _pathProperty = classInfo.Properties.OfType <SitecoreInfoConfiguration>().FirstOrDefault(p => p.Type == SitecoreInfoType.FullPath || p.Type == SitecoreInfoType.Path);
            _nameProperty = classInfo.Properties.OfType <SitecoreInfoConfiguration>().FirstOrDefault(p => p.Type == SitecoreInfoType.Name);
        }
        public void MapToProperty_GetUrlUsingDisplayName_ReturnsUrlUsingDisplayNames()
        {
            //Assign
            var    type     = SitecoreInfoType.Url;
            string expected = "/fr-FR/sitecore/content/this is a display name.aspx";

            var mapper = new SitecoreInfoMapper();
            var config = new SitecoreInfoConfiguration();

            config.Type       = type;
            config.UrlOptions = SitecoreInfoUrlOptions.UseItemLanguage | SitecoreInfoUrlOptions.UseUseDisplayName;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            Sitecore.Context.Site = null;
            var templateId = ID.NewID;
            var itemId     = new ID("031501A9C7F24596BD659276DA3A627A");

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem", itemId)
                {
                    Fields =
                    {
                        new DbField("title")
                        {
                            { "fr-fr", 1, "test" }
                        },
                    },
                }
            })
            {
                var item = database.GetItem("/sitecore/content/TestItem", "fr-fr");
                Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
                var dataContext = new SitecoreDataMappingContext(null, item, null);

                item.Editing.BeginEdit();
                item[FieldIDs.DisplayName] = "this is a display name";

                //Act
                var value = mapper.MapToProperty(dataContext);

                //Assert
                Assert.AreEqual(expected, value);
            }
        }
Пример #21
0
        public void MapToProperty_SitecoreInfoTypeBaseTemplateIds_ReturnsBaseTemplateIds()
        {
            //Assign
            ID templateId1 = ID.NewID;
            ID templateId2 = ID.NewID;

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbTemplate("TestTemplate1", templateId1),
                new Sitecore.FakeDb.DbTemplate("TestTemplate2", templateId2)
                {
                    new FakeDbField(new ID("{12C33F3F-86C5-43A5-AEB4-5598CEC45116}"), templateId1.ToString())
                },
                new Sitecore.FakeDb.DbItem("TestItem", ID.NewID, templateId2)
            })
            {
                var type = SitecoreInfoType.BaseTemplateIds;

                var mapper  = new SitecoreInfoMapper();
                var config  = new SitecoreInfoConfiguration();
                var options = new GetItemOptionsParams();
                config.Type         = type;
                config.PropertyInfo = typeof(Stub).GetProperty("BaseTemplateIds");

                mapper.Setup(new DataMapperResolverArgs(null, config));

                var item = database.GetItem("/sitecore/Content/TestItem");

                Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
                var dataContext = new SitecoreDataMappingContext(null, item, null, options);

                //Act
                IEnumerable <ID> results;
                using (new SecurityDisabler())
                {
                    results = mapper.MapToProperty(dataContext) as IEnumerable <ID>;
                }

                //Assert
                Assert.Greater(results.Count(), 1);
                Assert.IsTrue(results.All(x => x != item.TemplateID));
            }
        }
Пример #22
0
        public void MapToProperty_GetUrlInContextLanguage_ReturnsUrlWithEN()
        {
            //Assign
            var    type     = SitecoreInfoType.Url;
            string expected = "/en/sitecore/content/TestItem.aspx";

            var mapper = new SitecoreInfoMapper();
            var config = new SitecoreInfoConfiguration();

            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            Sitecore.Context.Site = null;
            var templateId = ID.NewID;
            var itemId     = new ID("031501A9C7F24596BD659276DA3A627A");
            var options    = new GetItemOptionsParams();

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem", itemId)
                {
                    Fields =
                    {
                        new DbField("title")
                        {
                            { "fr-fr", 1, "test" }
                        }
                    },
                }
            })
            {
                var item = database.GetItem("/sitecore/content/TestItem", "fr-fr");
                Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
                var dataContext = new SitecoreDataMappingContext(null, item, null, options);

                //Act
                var value = mapper.MapToProperty(dataContext);

                //Assert
                Assert.AreEqual(expected, value);
            }
        }
Пример #23
0
        public void MapToCms_SavingDisplayName_UpdatesTheDisplayNameField()
        {
            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem")
            })
            {
                //Assign
                var type     = SitecoreInfoType.DisplayName;
                var expected = "new display name";

                var mapper  = new SitecoreInfoMapper();
                var config  = new SitecoreInfoConfiguration();
                var options = new GetItemOptionsParams();
                config.Type = type;
                mapper.Setup(new DataMapperResolverArgs(null, config));

                var item = database.GetItem("/sitecore/Content/TestItem");

                Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");


                var dataContext = new SitecoreDataMappingContext(null, item, null, options);
                dataContext.PropertyValue = expected;

                string actual = string.Empty;

                //Act
                using (new SecurityDisabler())
                {
                    item.Editing.BeginEdit();
                    mapper.MapToCms(dataContext);
                    actual = item[Global.Fields.DisplayName];
                    item.Editing.CancelEdit();
                }

                //Assert
                Assert.AreEqual(expected, actual);
            }
        }
        public void MapToProperty_SitecoreInfoTypeNotSet_ThrowsException()
        {
            //Assign
            SitecoreInfoType type = SitecoreInfoType.NotSet;

            var mapper = new SitecoreInfoMapper();
            var config = new SitecoreInfoConfiguration();

            config.Type = type;
            mapper.Setup(new DataMapperResolverArgs(null, config));

            var item = _db.GetItem("/sitecore/Content/Tests/DataMappers/SitecoreInfoMapper/DataMappersEmptyItem");

            Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
            var dataContext = new SitecoreDataMappingContext(null, item, null);

            //Act
            var value = mapper.MapToProperty(dataContext);

            //Assert
            //No asserts expect exception
        }
 /// <summary>
 /// Configures the specified property info.
 /// </summary>
 /// <param name="propertyInfo">The property info.</param>
 /// <returns>AbstractPropertyConfiguration.</returns>
 public override Mapper.Configuration.AbstractPropertyConfiguration Configure(PropertyInfo propertyInfo)
 {
     var config = new SitecoreInfoConfiguration();
     Configure(propertyInfo, config);
     return config;
 }
Пример #26
0
        public void MapToProperty_MediaUrlWithFlag_ReturnsModifiedUrl(
            SitecoreInfoMediaUrlOptions option

            )
        {
            //Assign
            var mapper = new SitecoreInfoMapper();
            var config = new SitecoreInfoConfiguration();

            config.Type            = SitecoreInfoType.MediaUrl;
            config.MediaUrlOptions = option;
            mapper.Setup(new DataMapperResolverArgs(null, config));
            var    itemId   = new ID("031501A9C7F24596BD659276DA3A627A");
            string expected = "media url";

            Sitecore.Context.Site = null;

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("TestItem", itemId)
                {
                    Fields =
                    {
                        new FakeDbField(new ID("{B5E02AD9-D56F-4C41-A065-A133DB87BDEB}"),
                                        "DataMappersEmptyItem DisplayName")
                    },
                }
            })
            {
                Func <MediaUrlOptions, bool> pred = x =>
                {
                    switch (option)
                    {
                    case SitecoreInfoMediaUrlOptions.Default:
                        return(true);

                    case SitecoreInfoMediaUrlOptions.RemoveExtension:
                        return(x.IncludeExtension == false);

                    case SitecoreInfoMediaUrlOptions.LowercaseUrls:
                        return(x.LowercaseUrls == true);

                    default:
                        return(false);
                    }
                };


#if SC90 || SC91 || SC92
                var mediaUrlProvider = Substitute.For <BaseMediaManager>();

                SitecoreVersionAbstractions.MediaManager = new LazyResetable <BaseMediaManager>(() => mediaUrlProvider);

                mediaUrlProvider
                .GetMediaUrl(
                    Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == itemId),
                    Arg.Is <MediaUrlOptions>(x => pred(x))
                    )
                .Returns(expected);
#else
                Sitecore.Resources.Media.MediaProvider mediaProvider =
                    Substitute.For <Sitecore.Resources.Media.MediaProvider>();
                mediaProvider
                .GetMediaUrl(
                    Arg.Is <Sitecore.Data.Items.MediaItem>(i => i.ID == itemId),
                    Arg.Is <MediaUrlOptions>(x => pred(x))
                    )
                .Returns(expected);

                new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider);
#endif

                var options = new GetItemOptionsParams();

                var item = database.GetItem("/sitecore/content/TestItem");
                Assert.IsNotNull(item, "Item is null, check in Sitecore that item exists");
                var dataContext = new SitecoreDataMappingContext(null, item, null, options);

                //Act
                var value = mapper.MapToProperty(dataContext);

                //Assert
                Assert.AreEqual(expected, value);
            }
        }