예제 #1
0
        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());
        }
예제 #2
0
        public T GetRenderingParameters <T>() where T : class
        {
            var parameters = Sitecore.Mvc.Presentation.RenderingContext.CurrentOrNull.Rendering[Sc.GlassHtml.Parameters];

            return
                (GlassHtml.GetRenderingParameters <T>(parameters));
        }
예제 #3
0
        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));
        }
예제 #4
0
 /// <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));
 }
예제 #5
0
 /// <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));
 }
예제 #6
0
        protected virtual T GetRenderingParameters <T>() where T : class
        {
            string renderingParameters = MvcContext.RenderingParameters;

            return(renderingParameters.HasValue() ? GlassHtml.GetRenderingParameters <T>(renderingParameters) : null);
        }
예제 #7
0
 public virtual T GetRenderingParameters <T>() where T : class
 {
     return(GlassHtml.GetRenderingParameters <T>(RenderingParameters));
 }
예제 #8
0
        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());
        }
예제 #9
0
        public T GetRenderingParameters <T>() where T : class
        {
            string renderingParameters = RenderingContext.GetRenderingParameters();

            return(renderingParameters.HasValue() ? GlassHtml.GetRenderingParameters <T>(renderingParameters) : null);
        }
예제 #10
0
 public virtual T GetRenderingParameters <T>(NameValueCollection parameters, ID renderParametersTemplateId) where T : class
 {
     return(GlassHtml.GetRenderingParameters <T>(parameters, renderParametersTemplateId));
 }
예제 #11
0
 public virtual K GetRenderingParameters <K>() where K : class
 {
     return(GlassHtml.GetRenderingParameters <K>(RenderingParameters));
 }
예제 #12
0
 public virtual TParam GetRenderingParameters <TParam>() where TParam : class
 {
     return(RenderingParameters.HasValue()
         ? GlassHtml.GetRenderingParameters <TParam>(RenderingParameters)
         : default(TParam));
 }