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


C# GlassHtml类代码示例

本文整理汇总了C#中GlassHtml的典型用法代码示例。如果您正苦于以下问题:C# GlassHtml类的具体用法?C# GlassHtml怎么用?C# GlassHtml使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Setup

        public void Setup()
        {
            var loader = new AttributeConfigurationLoader(
               new string[] { "Glass.Sitecore.Mapper.Tests.HtmlFixtureNS, Glass.Sitecore.Mapper.Tests" }
               );
            _context = new Context(loader, new AbstractSitecoreDataHandler[] { });

            _db = global::Sitecore.Configuration.Factory.GetDatabase("master");
            _sitecore = new SitecoreService(_db);
            _itemId = new Guid("{5864308D-A91A-4E74-B8CA-7F27372CBB73}");
            _item = _db.GetItem(new ID(_itemId));
            _html = new GlassHtml(_sitecore);
            _sltTextOriginal = _item["SingleLineText"];
            _mltTextOriginal = _item["MultiLineText"];
            _intOriginal = _item["Integer"];
            _numberOriginal = _item["Number"];

            using (new SecurityDisabler())
            {
                _item.Editing.BeginEdit();
                _item["SingleLineText"] = _sltContent;
                _item["MultiLineText"] = _mltContent;
                _item["Integer"] = _intContent;
                _item["Number"] = _numberContent;
                _item.Editing.EndEdit();
            }

        }
开发者ID:JamesHay,项目名称:Glass.Sitecore.Mapper,代码行数:28,代码来源:HtmlFixture.cs

示例2: FieldWithSpacesReturningNullIssue

        public void FieldWithSpacesReturningNullIssue()
        {
            /*
             * This test is in response to issue 53 raised on the Glass.Sitecore.Mapper
             * project. When two interfaces have similar names are created as proxies
             * the method GetTypeConfiguration returns the wrong config.
             */


            //Assign
            string path = "/sitecore/content/Tests/Misc/FieldWithSpace";
            string expected = "Hello space";
            string imageValue =
                "<image mediaid=\"{C2CE5623-1E36-4535-9A01-669E1541DDAF}\" mediapath=\"/Tests/Dayonta\" src=\"~/media/C2CE56231E3645359A01669E1541DDAF.ashx\" />";

            var context = Context.Create(Utilities.CreateStandardResolver());
            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));

            var db = Sitecore.Configuration.Factory.GetDatabase("master");

            var item = db.GetItem(path);

            using (new ItemEditing(item, true))
            {
                item["Field With Space"] = expected;
                item["Image Field"] = imageValue;
            }
            
            var scContext = new SitecoreContext(db);

            var glassHtml = new GlassHtml(scContext);

            //Act
            var instance = scContext.GetItem<FieldWithSpaceIssue>(path);
           

            //Assert
            Assert.AreEqual(expected, instance.FieldWithSpace);
            Assert.IsNotNull(instance.ImageSpace);

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

示例3: InterfaceIssueInPageEditorWhenInterfaceInheritsFromAnInterfaceWithSimilarName

        public void InterfaceIssueInPageEditorWhenInterfaceInheritsFromAnInterfaceWithSimilarName()
        {
            /*
             * This test is in response to issue 53 raised on the Glass.Sitecore.Mapper
             * project. When two interfaces have similar names are created as proxies
             * the method GetTypeConfiguration returns the wrong config.
             */
             
            
            //Assign
            var context = Context.Create(Utilities.CreateStandardResolver());
            context.Load(new SitecoreAttributeConfigurationLoader("Glass.Mapper.Sc.Integration"));

            var db = Sitecore.Configuration.Factory.GetDatabase("master");
            var scContext = new SitecoreContext(db);

            var glassHtml = new GlassHtml(scContext);
            var instance = scContext.GetItem<IBasePage>("/sitecore");

            //Act
            glassHtml.Editable(instance, x => x.Title);

            //This method should execute without error


        }
开发者ID:bplasmeijer,项目名称:Glass.Mapper,代码行数:26,代码来源:MiscFixture.cs

示例4: RenderImage_AlternativeQuotationMarks_RendersCorrectHtml

        public void RenderImage_AlternativeQuotationMarks_RendersCorrectHtml()
        {
            //Arrange
            var expected = "<img src=\"~/media/Images/Carousel/carousel-example.ashx?h=126&amp;w=240\" alt=\"someAlt\" width=\"380\" />";
            var scContext = Substitute.For<ISitecoreContext>();
            scContext.Config = new Config();

            var html = new GlassHtml(scContext);
            var image = new Fields.Image();
            image.Alt = "someAlt";
            image.Width = 200;
            image.Height = 105;
            image.Src = "~/media/Images/Carousel/carousel-example.ashx";
            var parameters = new { Width = 380, W = 240 };
            var model = new { Image = image };

            GlassHtml.QuotationMark = "\"";

            //Act
            var result = html.RenderImage(model, x => x.Image, parameters, true, true);

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

            //reset GlassHtml
            GlassHtml.QuotationMark = "'";

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

示例5: RenderLink_RendersAValidaLink

        public void RenderLink_RendersAValidaLink()
        {

            //Assign
            GlassHtml html = new GlassHtml("master");

            FieldTypes.Link link = new FieldTypes.Link();
            link.Class = "classy";
            link.Anchor = "landSighted";
            link.Target = "xMarksTheSpot";
            link.Text = "Click here";
            link.Title = "You should click here";
            link.Url = "/yourpage";

            NameValueCollection attrs = new NameValueCollection();
            attrs.Add("style", "got some");

            //Act
            var result = html.RenderLink(link, attrs);

            //Assert
            Assert.AreEqual("<a href='/yourpage#landSighted' title='You should click here' target='xMarksTheSpot' class='classy' style='got some' class='classy' target='xMarksTheSpot' title='You should click here' >Click here</a>", result);


        }
开发者ID:photomoose,项目名称:Glass.Sitecore.Mapper,代码行数:25,代码来源:HtmlFixture.cs

示例6: RenderImage_MatchesSitecoreOutput_Issue133

        public void RenderImage_MatchesSitecoreOutput_Issue133()
        {
            //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 = "mw=200";
           
            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 {mw=200});

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




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

示例7: ConvertTo

        public override object ConvertTo(Type type, CultureInfo culture)
        {
            if (String.IsNullOrEmpty(_parameters))
                return null;

            var glassHtml = new GlassHtml(SitecoreContext.GetFromHttpContext());
            var genericMethod = method.MakeGenericMethod(type);
            return genericMethod.Invoke(glassHtml, new object[]{_parameters}) ??  base.ConvertTo(type, culture);
        }
开发者ID:RalfvandenBurg,项目名称:BoC,代码行数:9,代码来源:TemplateParametersValueProviderFactory.cs

示例8: 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

示例9: 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

示例10: RenderImage_ValidImageWithParametersWidth_RendersCorrectHtmlNoWidthHeight

        public void RenderImage_ValidImageWithParametersWidth_RendersCorrectHtmlNoWidthHeight()
        {    //Arrange
            var expected = "<img src='~/media/Images/Carousel/carousel-example.ashx?h=126&amp;w=240' alt='someAlt' />";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var image = new Fields.Image();
            image.Alt = "someAlt";
            image.Width = 200;
            image.Height = 105;
            image.Src = "~/media/Images/Carousel/carousel-example.ashx";
            var parameters = new { Width = 380, W = 240 };
            var model = new { Image = image };

            //Act
            var result = html.RenderImage(model, x => x.Image, parameters, true, false);

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

示例11: RenderImage_RendersImageWithAttributes

        public void RenderImage_RendersImageWithAttributes()
        {
            GlassHtml html = new GlassHtml("master");

            //Assign
            FieldTypes.Image img = new FieldTypes.Image();
            img.Alt = "Some alt test";
            img.Src = "/cats.jpg";
            img.Class = "classy";

            NameValueCollection attrs = new NameValueCollection();
            attrs.Add("style", "allStyle");
            
            //Act
            var result = html.RenderImage(img, attrs);

            //Assert
            Assert.AreEqual("<img src='/cats.jpg' style='allStyle' class='classy' alt='Some alt test' />", result);

        }
开发者ID:photomoose,项目名称:Glass.Sitecore.Mapper,代码行数:20,代码来源:HtmlFixture.cs

示例12: RenderingParameters_StringPassedInWithParametersUsingIdOnType_ReturnsModelWithValues

        public void RenderingParameters_StringPassedInWithParametersUsingIdOnType_ReturnsModelWithValues()
        {
            //Arrange
            var expectedNumber = 234;
            var expectedId1 = new Guid("{032B690F-5113-44C4-AEC7-A16B44382D4C}");
            var expectedId2 = new Guid("{6CF01319-0234-42C8-AEC1-FE757169F7A0}");
            var expectedFieldValue = "hello world";

            var parameters = "StringField={0}&Number={1}&Items={2}"
                .Formatted(
                    WebUtil.UrlEncode(expectedFieldValue),
                    WebUtil.UrlEncode(expectedNumber.ToString()),
                    WebUtil.UrlEncode("{0}|{1}".Formatted(expectedId1, expectedId2)));

            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);

            //Act
            var result = html.GetRenderingParameters<RenderingTestWithAttribute>(parameters);

            //Assert
            Assert.AreEqual(expectedNumber, result.Number);
            Assert.AreEqual(expectedFieldValue, result.StringField);
            Assert.IsTrue(result.Items.Any(x => x.Id == expectedId1));
            Assert.IsTrue(result.Items.Any(x => x.Id == expectedId2));
            Assert.AreEqual(2, result.Items.Count());
        }
开发者ID:rootix,项目名称:Glass.Mapper,代码行数:31,代码来源:GlassHtmlFixture.cs

示例13: RenderLink_LinkHasQuestionMarkAndAnchorAtEnd

        public void RenderLink_LinkHasQuestionMarkAndAnchorAtEnd()
        {
            //Arrange
            var expected = "<a href='http://www.seek.com.au/jobs/in-australia/?dateRange=test&amp;value1=test2#anchor' >hello world</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello world";
            link.Url = "http://www.seek.com.au/jobs/in-australia/?dateRange=test&value1=test2#anchor";

            var model = new { Link = link };

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

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

示例14: RenderLink_ContainsSpecialCharacters

        public void RenderLink_ContainsSpecialCharacters()
        {
            //Arrange
            var expected = "<a href='http://na2.se.voxco.com/se/?st=6M9NIk9SWq9dkYTuJI2wewuV3b3bWrDQMwgCt2aBnWDGTaoxLYNESg%3D%3D' title='hello &amp; world' >hello &amp; world</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello & world";
            link.Url = "http://na2.se.voxco.com/se/?st=6M9NIk9SWq9dkYTuJI2wewuV3b3bWrDQMwgCt2aBnWDGTaoxLYNESg%3D%3D";
            link.Title = "hello & world";
            var model = new { Link = link };

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

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

示例15: RenderLink_LinkHasHashBang

        public void RenderLink_LinkHasHashBang()
        {
            //Arrange
            var expected = "<a href='http://www.seek.com.au/jobs/in-australia/#dateRange=999&amp;workType=0&amp;industry=&amp;occupation=&amp;graduateSearch=false&amp;salaryFrom=0&amp;salaryTo=999999&amp;salaryType=annual&amp;advertiserID=&amp;advertiserGroup=&amp;keywords=sitecore+developer&amp;page=1&amp;displaySuburb=&amp;seoSuburb=&amp;isAreaUnspecified=false&amp;location=&amp;area=&amp;nation=3000&amp;sortMode=KeywordRelevance&amp;searchFrom=filters&amp;searchType=' >hello world</a>";
            var scContext = Substitute.For<ISitecoreContext>();
            
            var html = new GlassHtml(scContext);
            var link = new Fields.Link();
            link.Text = "hello world";
            link.Url = "http://www.seek.com.au/jobs/in-australia/#dateRange=999&workType=0&industry=&occupation=&graduateSearch=false&salaryFrom=0&salaryTo=999999&salaryType=annual&advertiserID=&advertiserGroup=&keywords=sitecore+developer&page=1&displaySuburb=&seoSuburb=&isAreaUnspecified=false&location=&area=&nation=3000&sortMode=KeywordRelevance&searchFrom=filters&searchType=";

            var model = new { Link = link };

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

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


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