当前位置: 首页>>代码示例>>C#>>正文


C# SitecoreService.Save方法代码示例

本文整理汇总了C#中SitecoreService.Save方法的典型用法代码示例。如果您正苦于以下问题:C# SitecoreService.Save方法的具体用法?C# SitecoreService.Save怎么用?C# SitecoreService.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SitecoreService的用法示例。


在下文中一共展示了SitecoreService.Save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Save_ItemDisplayNameChangedUsingProxyUsingInterface_SavesDisplayName

        public void Save_ItemDisplayNameChangedUsingProxyUsingInterface_SavesDisplayName()
        {
            //Assign
            var itemPath = "/sitecore/content/Tests/SitecoreService/Save/EmptyItem";
            string expected = "new name";

            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var context = Context.Create(Utilities.CreateStandardResolver());
            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));
            var currentItem = db.GetItem(itemPath);
            var service = new SitecoreService(db, context);


            //setup item
            using (new SecurityDisabler())
            {
                currentItem.Editing.BeginEdit();
                currentItem[Global.Fields.DisplayName] = "old name";
                currentItem.Editing.EndEdit();
            }

            var cls = service.GetItem<IStubSaving>(itemPath);



            using (new SecurityDisabler())
            {
                //Act
                cls.Name = expected;
                service.Save(cls);

                //Assert
                var newItem = db.GetItem(itemPath);

                Assert.AreEqual(expected, newItem[Global.Fields.DisplayName]);

                Assert.IsTrue(cls is IStubSaving);
                Assert.AreNotEqual(typeof(IStubSaving), cls.GetType());
            }

        }
开发者ID:uv20,项目名称:Glass.Mapper,代码行数:41,代码来源:SitecoreServiceFixture.cs

示例2: Save_ItemDisplayNameChangedUsingProxyUsingInterface_SavesDisplayName

        public void Save_ItemDisplayNameChangedUsingProxyUsingInterface_SavesDisplayName()
        {
            //Assign
            Guid id = Guid.NewGuid();

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target", new ID(id))
            })
            {
                var context = Context.Create(Utilities.CreateStandardResolver());
                context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubSaving)));
                var service = new SitecoreService(database.Database);

                var itemPath = "/sitecore/content/Target";
                string expected = "new name";

                var currentItem = database.Database.GetItem(itemPath);

                //setup item
                using (new SecurityDisabler())
                {
                    currentItem.Editing.BeginEdit();
                    currentItem[Global.Fields.DisplayName] = "old name";
                    currentItem.Editing.EndEdit();
                }

                var cls = service.GetItem<IStubSaving>(itemPath);
                using (new SecurityDisabler())
                {
                    //Act
                    cls.Name = expected;
                    service.Save(cls);

                    //Assert
                    var newItem = database.Database.GetItem(itemPath);

                    Assert.AreEqual(expected, newItem[Global.Fields.DisplayName]);

                    Assert.IsTrue(cls is IStubSaving);
                    Assert.AreNotEqual(typeof(IStubSaving), cls.GetType());
                }

            }

        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:46,代码来源:SitecoreServiceFixture.cs


注:本文中的SitecoreService.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。