コード例 #1
0
        public void RichTextBlock()
        {
            var card = new AdaptiveCard("1.2");

            var richTB = new AdaptiveRichTextBlock();

            richTB.HorizontalAlignment = AdaptiveHorizontalAlignment.Center;

            // Build text runs
            var textRun1 = new AdaptiveTextRun("Start the rich text block ");

            richTB.Inlines.Add(textRun1);

            var textRun2 = new AdaptiveTextRun("with some cool looking stuff. ");

            textRun2.Color         = AdaptiveTextColor.Accent;
            textRun2.FontType      = AdaptiveFontType.Monospace;
            textRun2.IsSubtle      = true;
            textRun2.Italic        = true;
            textRun2.Strikethrough = true;
            textRun2.Highlight     = true;
            textRun2.Size          = AdaptiveTextSize.Large;
            textRun2.Weight        = AdaptiveTextWeight.Bolder;
            richTB.Inlines.Add(textRun2);

            var textRun3 = new AdaptiveTextRun("This run has a link!");

            textRun3.SelectAction = new AdaptiveOpenUrlAction()
            {
                Title     = "Open URL",
                UrlString = "http://adaptivecards.io/"
            };
            richTB.Inlines.Add(textRun3);

            card.Body.Add(richTB);

            // Indentation needs to be kept as-is to match the result of card.ToJson
            var expected = @"{
  ""type"": ""AdaptiveCard"",
  ""version"": ""1.2"",
  ""body"": [
    {
      ""type"": ""RichTextBlock"",
      ""horizontalAlignment"": ""center"",
      ""inlines"": [
        {
          ""type"": ""TextRun"",
          ""text"": ""Start the rich text block ""
        },
        {
          ""type"": ""TextRun"",
          ""size"": ""large"",
          ""weight"": ""bolder"",
          ""color"": ""accent"",
          ""isSubtle"": true,
          ""italic"": true,
          ""strikethrough"": true,
          ""highlight"": true,
          ""text"": ""with some cool looking stuff. "",
          ""fontType"": ""monospace""
        },
        {
          ""type"": ""TextRun"",
          ""text"": ""This run has a link!"",
          ""selectAction"": {
            ""type"": ""Action.OpenUrl"",
            ""url"": ""http://adaptivecards.io/"",
            ""title"": ""Open URL""
          }
        }
      ]
    }
  ]
}";

            Assert.AreEqual(expected, card.ToJson());
        }
コード例 #2
0
        public void RichTextBlock()
        {
            AdaptiveTextRun textRun1 = new AdaptiveTextRun
            {
                Color     = ForegroundColor.Accent,
                FontStyle = FontStyle.Monospace,
                IsSubtle  = true,
                Language  = "en",
                Size      = TextSize.Large,
                Text      = "This is text run number 1",
                Weight    = TextWeight.Bolder,
            };

            Assert.AreEqual(ForegroundColor.Accent, textRun1.Color);
            Assert.AreEqual(FontStyle.Monospace, textRun1.FontStyle);
            Assert.AreEqual(true, textRun1.IsSubtle);
            Assert.AreEqual("en", textRun1.Language);
            Assert.AreEqual(TextSize.Large, textRun1.Size);
            Assert.AreEqual("This is text run number 1", textRun1.Text);
            Assert.AreEqual(TextWeight.Bolder, textRun1.Weight);

            textRun1.SelectAction = new AdaptiveSubmitAction
            {
                Title = "Select Action"
            };
            Assert.IsNotNull(textRun1.SelectAction);
            Assert.AreEqual("Select Action", textRun1.SelectAction.Title);

            AdaptiveTextRun textRun2 = new AdaptiveTextRun {
                Text = "This is text run number 2"
            };
            AdaptiveTextRun textRun3 = new AdaptiveTextRun {
                Text = "This is text run number 3"
            };

            AdaptiveParagraph paragraph1 = new AdaptiveParagraph {
            };

            paragraph1.Inlines.Add(textRun1);
            paragraph1.Inlines.Add(textRun2);

            AdaptiveParagraph paragraph2 = new AdaptiveParagraph {
            };

            paragraph2.Inlines.Add(textRun3);

            AdaptiveRichTextBlock richTextBlock = new AdaptiveRichTextBlock
            {
                Height = HeightType.Stretch,
                HorizontalAlignment = HAlignment.Center,
                Id        = "RichTextBlockId",
                IsVisible = false,
                MaxLines  = 3,
                Separator = true,
                Spacing   = Spacing.Large,
                Wrap      = true
            };

            ValidateBaseElementProperties(richTextBlock, "RichTextBlockId", false, true, Spacing.Large, HeightType.Stretch);

            Assert.AreEqual(HAlignment.Center, richTextBlock.HorizontalAlignment);
            Assert.AreEqual <uint>(3, richTextBlock.MaxLines);
            Assert.AreEqual(true, richTextBlock.Wrap);

            richTextBlock.Paragraphs.Add(paragraph1);
            richTextBlock.Paragraphs.Add(paragraph2);

            Assert.AreEqual("This is text run number 1", (richTextBlock.Paragraphs[0].Inlines[0] as AdaptiveTextRun).Text);
            Assert.AreEqual("This is text run number 2", (richTextBlock.Paragraphs[0].Inlines[1] as AdaptiveTextRun).Text);
            Assert.AreEqual("This is text run number 3", (richTextBlock.Paragraphs[1].Inlines[0] as AdaptiveTextRun).Text);

            var jsonString = richTextBlock.ToJson().ToString();

            Assert.AreEqual("{\"height\":\"Stretch\",\"horizontalAlignment\":\"center\",\"id\":\"RichTextBlockId\",\"isVisible\":false,\"maxLines\":3,\"paragraphs\":[{\"inlines\":[{\"color\":\"Accent\",\"fontStyle\":\"Monospace\",\"isSubtle\":true,\"selectAction\":{\"title\":\"Select Action\",\"type\":\"Action.Submit\"},\"size\":\"Large\",\"text\":\"This is text run number 1\",\"type\":\"TextRun\",\"weight\":\"Bolder\"},{\"text\":\"This is text run number 2\",\"type\":\"TextRun\"}]},{\"inlines\":[{\"text\":\"This is text run number 3\",\"type\":\"TextRun\"}]}],\"separator\":true,\"spacing\":\"large\",\"type\":\"RichTextBlock\",\"wrap\":true}", jsonString);
        }