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


C# SiteContextStub.SetDisplayMode方法代码示例

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


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

示例1: Editable_InEditMode_StringFieldWithEditReturned

        public void Editable_InEditMode_StringFieldWithEditReturned()
        {
            //Assign
            string targetPath = "/sitecore/content/Tests/GlassHtml/MakeEditable/Target";

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

            var html = new GlassHtml(service);
            
            var model = service.GetItem<StubClass>(targetPath);

            var fieldValue = "test content field";

            model.StringField = fieldValue ;

            using (new SecurityDisabler())
            {
                service.Save(model);
            }

            var doc = new XmlDocument();
            doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />");

            var siteContext = new SiteContextStub(
                new SiteInfo(
                    doc.FirstChild
                    )
                );

            siteContext.SetDisplayMode(DisplayMode.Edit);

            Sitecore.Context.Site = siteContext;

            //Act
            string result;

            using (new SecurityDisabler())
            {
                result = html.Editable(model, x => x.StringField);
            }

            //Assert
            Assert.IsTrue(result.Contains(fieldValue));
            //this is the webedit class
            Assert.IsTrue(result.Contains("scWebEditInput"));
            Console.WriteLine("result "+result);
        }
开发者ID:JamesHay,项目名称:Glass.Mapper,代码行数:50,代码来源:GlassHtmlFixture.cs

示例2: RenderLink_LinkContainsAnchor_Issue155

        public void RenderLink_LinkContainsAnchor_Issue155()
        {
            //Assign
            string targetPath = "/sitecore/content/Tests/GlassHtml/MakeEditable/Target";

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

            var html = new GlassHtml(service);


            string fieldValue = "<link text='text' linktype='anchor' anchor='footer' title='' class='' />";
            string expected = "<a href='#footer' >text</a>";

            var item = db.GetItem(targetPath);
            var field = item.Fields["StringField"];

            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }

            var model = service.GetItem<IStubLinkClass>(targetPath);

            var doc = new XmlDocument();
            doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />");

            var siteContext = new SiteContextStub(
                new SiteInfo(
                    doc.FirstChild
                    )
                );

            siteContext.SetDisplayMode(DisplayMode.Normal);

            Sitecore.Context.Site = siteContext;

            StringBuilder sb = new StringBuilder();
            //Act
            var result = html.RenderLink(model, x => x.Link);

            //Assert
            Assert.AreEqual(expected, result);
        }
开发者ID:rootix,项目名称:Glass.Mapper,代码行数:46,代码来源:GlassHtmlFixture.cs

示例3: RenderImage_MatchesSitecoreOutput_Issue133_Test3

        public void RenderImage_MatchesSitecoreOutput_Issue133_Test3()
        {
            //Assign
            string targetPath = "/sitecore/content/Tests/GlassHtml/RenderImage/Target";

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

            var html = new GlassHtml(service);


            string fieldValue = "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" mediapath=\"/Files/20121222_001405\" src=\"~/media/D897833C1F534FAEB54BBB5B11B8F851.ashx\" hspace=\"15\" vspace=\"20\" />";

            var item = db.GetItem(targetPath);
            var field = item.Fields["Image"];

            using (new ItemEditing(item, true))
            {
                field.Value = fieldValue;
            }

            var model = service.GetItem<StubClassWithImage>(targetPath);


            var scControl = new Sitecore.Web.UI.WebControls.Image();
            scControl.Item = item;
            scControl.Field = "Image";
            scControl.Parameters = "width=200&as=true";

            var doc = new XmlDocument();
            doc.LoadXml("<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />");

            var siteContext = new SiteContextStub(
                new SiteInfo(
                    doc.FirstChild
                    )
                );

            siteContext.SetDisplayMode(DisplayMode.Normal);

            Sitecore.Context.Site = siteContext;

            StringBuilder sb = new StringBuilder();
            HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb));
            //Act
            scControl.RenderControl(writer);
            var scResult = sb.ToString();
            var result = html.RenderImage(model, x => x.Image, new { width = 200 });

            //Assert
            Assert.AreEqual(result, scResult);


        }
开发者ID:rootix,项目名称:Glass.Mapper,代码行数:56,代码来源:GlassHtmlFixture.cs

示例4: Editable_SimpleLambdaInEditModeInterfaceClearingContext_StringFieldWithEditReturned

        public void Editable_SimpleLambdaInEditModeInterfaceClearingContext_StringFieldWithEditReturned()
        {
            //Assign
            string targetPath = "/sitecore/content/target";

            var templateId = ID.NewID;
            using (Db database = new Db
            {
                new DbTemplate(templateId)
                {
                    new DbField("StringField")
                    {
                        Type = "text"
                    }
                },
                new Sitecore.FakeDb.DbItem("Target", ID.NewID, templateId)
                {
                    {"StringField", ""}
                }
            })
            {
                var context = Context.Create(Utilities.CreateStandardResolver());
                context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass)));

                var service = new SitecoreContext(database.Database);

                var html = new GlassHtml(service);

                var model = service.GetItem<IStubClass>(targetPath);

                var fieldValue = "test content field";

                model.StringField = fieldValue;


                using (new SecurityDisabler())
                {
                    service.Save(model);
                }


                var doc = new XmlDocument();
                doc.LoadXml(
                    "<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />");

                var siteContext = new SiteContextStub(
                    new SiteInfo(
                        doc.FirstChild
                        )
                    );

                siteContext.SetDisplayMode(DisplayMode.Edit);

                Sitecore.Context.Site = siteContext;

                //Act
                string result;


                context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(System.Object)));
                using (new EnableWebEditMode())
                {
                    using (new SiteContextSwitcher(siteContext))
                    {
                        // model = null;
                        using (new SecurityDisabler())
                        {
                            result = html.Editable(model, x => x.StringField);
                        }
                        //Assert
                        Assert.IsTrue(result.Contains(fieldValue));
                        //this is the webedit class
                        Assert.IsTrue(result.Contains("scWebEditInput"));
                        Console.WriteLine("result " + result);
                    }
                }
            }

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

示例5: RenderLink_LinkContainsAnchor_Issue155

        public void RenderLink_LinkContainsAnchor_Issue155()
        {
            //Assign
            string path = "/sitecore/content/target";

            using (Db database = new Db
            {
                new Sitecore.FakeDb.DbItem("Target")
                {
                    {"StringField","" }
                }
            })
            {
                var context = Context.Create(Utilities.CreateStandardResolver());
                context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass)));

                var service = new SitecoreContext(database.Database);

                var html = GetGlassHtml(service);


                string fieldValue = "<link text='text' linktype='anchor' anchor='footer' title='' class='' />";
                string expected = "<a href='#footer' >text</a>";

                var item = database.GetItem(path);
                var field = item.Fields["StringField"];

                using (new ItemEditing(item, true))
                {
                    field.Value = fieldValue;
                }

                var model = service.GetItem<IStubLinkClass>(path);

                var doc = new XmlDocument();
                doc.LoadXml(
                    "<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />");

                var siteContext = new SiteContextStub(
                    new SiteInfo(
                        doc.FirstChild
                        )
                    );

                siteContext.SetDisplayMode(DisplayMode.Normal);

                Sitecore.Context.Site = siteContext;

                StringBuilder sb = new StringBuilder();
                //Act
                var result = html.RenderLink(model, x => x.Link);

                //Assert
                AssertHtml.AreHtmlElementsEqual(expected, result,"a");
            }
        }
开发者ID:mikeedwards83,项目名称:Glass.Mapper,代码行数:56,代码来源:GlassHtmlFixture.cs

示例6: RenderImage_MatchesSitecoreOutput_Issue133_Test3

        public void RenderImage_MatchesSitecoreOutput_Issue133_Test3()
        {
            //Assign
            string targetPath = "/sitecore/content/target";
            var mediaID = new ID("{D897833C-1F53-4FAE-B54B-BB5B11B8F851}");

            var templateId = ID.NewID;
            using (Db database = new Db
            {
                new DbTemplate("MediaTemplate", templateId)
                {
                    new DbField("Image")
                    {
                        Type = "image"
                    }
                },
                new Sitecore.FakeDb.DbItem("Target", new ID(), templateId)
                {
                    {"Image", ""}
                },
                new Sitecore.FakeDb.DbItem("media", mediaID)
                {
                }
            })
            {
                var context = Context.Create(Utilities.CreateStandardResolver());
                context.Load(new OnDemandLoader<SitecoreTypeConfiguration>(typeof(StubClass)));

                var service = new SitecoreContext(database.Database);
                var html = GetGlassHtml(service);

                Sitecore.Resources.Media.MediaProvider mediaProvider =
                    NSubstitute.Substitute.For<Sitecore.Resources.Media.MediaProvider>();

                mediaProvider
                    .GetMediaUrl(Arg.Is<Sitecore.Data.Items.MediaItem>(i => i.ID == mediaID))
                    .Returns("/myimage");

                using (new Sitecore.FakeDb.Resources.Media.MediaProviderSwitcher(mediaProvider))
                {


                    string fieldValue =
                        "<image mediaid=\"{D897833C-1F53-4FAE-B54B-BB5B11B8F851}\" mediapath=\"/Files/20121222_001405\" src=\"~/media/D897833C1F534FAEB54BBB5B11B8F851.ashx\" hspace=\"15\" vspace=\"20\" />";

                    var item = database.GetItem(targetPath);
                    var field = item.Fields["Image"];

                    using (new ItemEditing(item, true))
                    {
                        field.Value = fieldValue;
                    }

                    var model = service.GetItem<StubClassWithImage>(targetPath);


                    var scControl = new Sitecore.Web.UI.WebControls.Image();
                    scControl.Item = item;
                    scControl.Field = "Image";
                    scControl.Parameters = "width=200&as=true";

                    var doc = new XmlDocument();
                    doc.LoadXml(
                        "<site name='GetHomeItem' virtualFolder='/' physicalFolder='/' rootPath='/sitecore/content/Tests/SitecoreContext/GetHomeItem' startItem='/Target1' database='master' domain='extranet' allowDebug='true' cacheHtml='true' htmlCacheSize='10MB' registryCacheSize='0' viewStateCacheSize='0' xslCacheSize='5MB' filteredItemsCacheSize='2MB' enablePreview='true' enableWebEdit='true' enableDebugger='true' disableClientData='false' />");

                    var siteContext = new SiteContextStub(
                        new SiteInfo(
                            doc.FirstChild
                            )
                        );

                    siteContext.SetDisplayMode(DisplayMode.Normal);

                    Sitecore.Context.Site = siteContext;

                    StringBuilder sb = new StringBuilder();
                    HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb));
                    //Act
                    scControl.RenderControl(writer);
                    var scResult = sb.ToString();
                    var result = html.RenderImage(model, x => x.Image, new { width = 200 });

                    //Assert
                    Assert.AreEqual(result, scResult);
                }

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


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