internal static CarouselTemplate Convert(ICarouselTemplate template) { if (!(template is CarouselTemplate carouselTemplate)) { carouselTemplate = new CarouselTemplate(); } if (template.Columns == null) { throw new InvalidOperationException("The columns cannot be null."); } carouselTemplate.Columns = CarouselColumn.Convert(template.Columns); return(carouselTemplate); }
public static CarouselTemplate ToCarouselTemplate(this ICarouselTemplate self) { CarouselTemplate carouselTemplate = self as CarouselTemplate; if (carouselTemplate == null) { carouselTemplate = new CarouselTemplate(); } if (self.Columns == null) { throw new InvalidOperationException("The columns cannot be null."); } carouselTemplate.Columns = self.Columns.ToCarouselColumn().ToArray(); return(carouselTemplate); }
public void Convert_TemplateMessageWithCarouselTemplate_InstanceIsPreserved() { TemplateMessage message = new TemplateMessage() { AlternativeText = "Alternative", Template = new CarouselTemplate() { Columns = new ICarouselColumn[] { new CarouselColumn() { ThumbnailUrl = new Uri("https://foo.bar"), Title = "CarouselTitle", Text = "CarouselText", Actions = new ITemplateAction[] { new MessageAction() { Label = "PostbackLabel", Text = "PostbackText" } } } } } }; ISendMessage[] messages = MessageConverter.Convert(new ISendMessage[] { message }); Assert.AreEqual(1, messages.Length); ITemplateMessage templateMessage = messages[0] as ITemplateMessage; Assert.AreEqual(message, templateMessage); ICarouselTemplate buttonsTemplate = templateMessage.Template as ICarouselTemplate; Assert.AreEqual(message.Template, buttonsTemplate); ICarouselColumn column = buttonsTemplate.Columns.First(); Assert.AreEqual(column, ((CarouselTemplate)message.Template).Columns.First()); }