Ejemplo n.º 1
0
        public void GetMaxImageHeight_EmptyInnerItems_ZeroHeight(DynamicTeaserModel model)
        {
            //Act
            var maxHeight = model.GetMaxImageHeight();

            //Assert
            maxHeight.Should().Be(0);
        }
Ejemplo n.º 2
0
        public ActionResult Carousel()
        {
            var dataSourceItem = RenderingContext.Current.Rendering.Item;

            if (!dataSourceItem?.IsDerived(Templates.DynamicTeaser.ID) ?? true)
            {
                return(Context.PageMode.IsExperienceEditor ? this.InfoMessage(new InfoMessage(AlertTexts.InvalidDataSourceTemplateFriendlyMessage, InfoMessage.MessageType.Error)) : null);
            }

            var model = new DynamicTeaserModel(dataSourceItem);

            return(this.View("Carousel", model));
        }
Ejemplo n.º 3
0
        public ActionResult GetDynamicContent(string viewName)
        {
            var dataSourceItem = RenderingContext.Current.Rendering.Item;

            if (!dataSourceItem?.DescendsFrom(Templates.DynamicTeaser.ID) ?? true)
            {
                return(Context.PageMode.IsExperienceEditor ? this.InfoMessage(new InfoMessage(AlertTexts.InvalidDataSourceTemplateFriendlyMessage, InfoMessage.MessageType.Error)) : null);
            }

            var model = new DynamicTeaserModel(dataSourceItem);

            return(this.View(viewName, model));
        }
Ejemplo n.º 4
0
        public void GetMaxImageHeight_NoImageItems_ZeroHeight(Db db, DbItem modelItem)
        {
            //Arrange
            modelItem.Add(new DbItem("Inner item 1", new ID(), Templates.TeaserHeadline.ID));
            modelItem.Add(new DbItem("Inner item 2", new ID(), Templates.TeaserHeadline.ID));
            db.Add(modelItem);

            var model = new DynamicTeaserModel(db.GetItem(modelItem.ID));
            //Act
            var maxHeight = model.GetMaxImageHeight();

            //Assert
            maxHeight.Should().Be(0);
        }
        public static int GetMaxImageHeight(this DynamicTeaserModel model)
        {
            int maxHeight = 0;

            foreach (var element in model.Items.Where(x => x.Item != null))
            {
                int height;
                var field = Templates.TeaserContent.Fields.Image;
                if (int.TryParse(((ImageField)element.Item.Fields[field]).Height, out height) && height > maxHeight)
                {
                    maxHeight = height;
                }
            }

            return(maxHeight);
        }
Ejemplo n.º 6
0
        public void GetMaxImageHeight_ImageItems_ReturnMaxHeight(Db db, int maxHeight, int difference, DbItem modelItem)
        {
            //Arrange
            modelItem.Add(new DbItem("Inner item 1", new ID(), Templates.TeaserHeadline.ID)
            {
                { Templates.TeaserContent.Fields.Image, $@"<image mediapath="""" src="""" height=""{maxHeight}"" mediaid="""" ></image>" }
            });
            modelItem.Add(new DbItem("Inner item 2", new ID(), Templates.TeaserHeadline.ID)
            {
                { Templates.TeaserContent.Fields.Image, $@"<image mediapath="""" src="""" height=""{maxHeight - difference}"" mediaid="""" ></image>" }
            });
            db.Add(modelItem);

            var model = new DynamicTeaserModel(db.GetItem(modelItem.ID));
            //Act
            var result = model.GetMaxImageHeight();

            //Assert
            result.Should().Be(maxHeight);
        }