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()); }
public T GetRenderingParameters <T>() where T : class { var parameters = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering[Sc.GlassHtml.Parameters]; return (GlassHtml.GetRenderingParameters <T>(parameters)); }
public T GetRenderingParameters <T>() where T : class { var parameters = new NameValueCollection(); foreach (var pair in Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering.Parameters) { parameters[pair.Key] = pair.Value; } return (GlassHtml.GetRenderingParameters <T>(parameters)); }
/// <summary> /// Converts rendering parameters to a concrete type. Use this method if you have defined the template ID on the /// model configuration. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parameters"></param> /// <returns></returns> public virtual T RenderingParameters <T>(NameValueCollection parameters) where T : class { return(GlassHtml.GetRenderingParameters <T>(parameters)); }
/// <summary> /// Converts rendering parameters to a concrete type. Use this method if you have defined the template ID on the /// model configuration. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parameters"></param> /// <returns></returns> public virtual T RenderingParameters <T>(string parameters) where T : class { return(GlassHtml.GetRenderingParameters <T>(parameters)); }
protected virtual T GetRenderingParameters <T>() where T : class { string renderingParameters = MvcContext.RenderingParameters; return(renderingParameters.HasValue() ? GlassHtml.GetRenderingParameters <T>(renderingParameters) : null); }
public virtual T GetRenderingParameters <T>() where T : class { return(GlassHtml.GetRenderingParameters <T>(RenderingParameters)); }
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()); }
public T GetRenderingParameters <T>() where T : class { string renderingParameters = RenderingContext.GetRenderingParameters(); return(renderingParameters.HasValue() ? GlassHtml.GetRenderingParameters <T>(renderingParameters) : null); }
public virtual T GetRenderingParameters <T>(NameValueCollection parameters, ID renderParametersTemplateId) where T : class { return(GlassHtml.GetRenderingParameters <T>(parameters, renderParametersTemplateId)); }
public virtual K GetRenderingParameters <K>() where K : class { return(GlassHtml.GetRenderingParameters <K>(RenderingParameters)); }
public virtual TParam GetRenderingParameters <TParam>() where TParam : class { return(RenderingParameters.HasValue() ? GlassHtml.GetRenderingParameters <TParam>(RenderingParameters) : default(TParam)); }