Exemplo n.º 1
0
            public IAdaptiveCardElement FromJson(JsonObject inputJson, AdaptiveElementParserRegistration elementParsers, AdaptiveActionParserRegistration actionParsers, IList <AdaptiveWarning> warnings)
            {
                JsonObject jsonTextBlock   = inputJson.GetNamedObject("internalTextBlock");
                var        textBlockParser = elementParsers.Get("TextBlock");

                IAdaptiveCardElement textBlockElement = textBlockParser.FromJson(jsonTextBlock, elementParsers, actionParsers, warnings);

                return(new TestCustomElement(textBlockElement) as IAdaptiveCardElement);
            }
Exemplo n.º 2
0
        public void ElementParserRegistraton_CustomElementTest()
        {
            AdaptiveActionParserRegistration  actionParserRegistration  = new AdaptiveActionParserRegistration();
            AdaptiveElementParserRegistration elementParserRegistration = new AdaptiveElementParserRegistration();
            List <AdaptiveWarning>            warnings = new List <AdaptiveWarning>();

            elementParserRegistration.Set("TestCustomElement", new TestElementParser());
            IAdaptiveElementParser testElementParserRetrieved = elementParserRegistration.Get("TestCustomElement");

            Assert.IsNotNull(testElementParserRetrieved);
            Assert.IsNotNull(testElementParserRetrieved as TestElementParser);

            String testCard =
                "{" +
                "   \"type\":\"AdaptiveCard\"," +
                "   \"version\":\"1.0\"," +
                "   \"body\":" +
                "   [" +
                "       {" +
                "           \"type\":\"TestCustomElement\"," +
                "           \"internalTextBlock\":" +
                "           {" +
                "               \"type\":\"TextBlock\"," +
                "               \"text\":\"Here is some text\"" +
                "           }" +
                "       }" +
                "   ]" +
                "}";

            AdaptiveCard card = AdaptiveCard.FromJsonString(testCard, elementParserRegistration, actionParserRegistration).AdaptiveCard;

            Assert.IsNotNull(card);

            Assert.AreEqual(1, card.Body.Count);

            IAdaptiveCardElement cardElement = card.Body[0];

            Assert.IsNotNull(cardElement);

            Assert.AreEqual(ElementType.Custom, cardElement.ElementType);
            Assert.AreEqual("TestCustomElement", cardElement.ElementTypeString);

            TestCustomElement customElement = card.Body[0] as TestCustomElement;

            Assert.IsNotNull(customElement);

            Assert.AreEqual(ElementType.TextBlock, customElement.InternalTextBlock.ElementType);
        }
Exemplo n.º 3
0
        public void ElementParserRegistraton_DefaultElementsTest()
        {
            AdaptiveActionParserRegistration  actionParserRegistration  = new AdaptiveActionParserRegistration();
            AdaptiveElementParserRegistration elementParserRegistration = new AdaptiveElementParserRegistration();
            List <AdaptiveWarning>            warnings = new List <AdaptiveWarning>();

            JsonObject jsonObject;

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"ActionSet\",\"id\":\"ActionSetId\"}", out jsonObject));
            Assert.AreEqual(ElementType.ActionSet, elementParserRegistration.Get("ActionSet").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"Input.ChoiceSet\",\"id\":\"ChoiceSetId\", \"choices\":[{\"type\":\"Input.Choice\",\"title\":\"title\",\"value\":\"value\"}]}", out jsonObject));
            Assert.AreEqual(ElementType.ChoiceSetInput, elementParserRegistration.Get("Input.ChoiceSet").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"ColumnSet\"}", out jsonObject));
            Assert.AreEqual(ElementType.ColumnSet, elementParserRegistration.Get("ColumnSet").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"Container\", \"items\":[]}", out jsonObject));
            Assert.AreEqual(ElementType.Container, elementParserRegistration.Get("Container").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"Input.Date\", \"id\":\"DateId\"}", out jsonObject));
            Assert.AreEqual(ElementType.DateInput, elementParserRegistration.Get("Input.Date").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"FactSet\", \"facts\":[{\"title\":\"title\",\"value\":\"value\"}]}", out jsonObject));
            Assert.AreEqual(ElementType.FactSet, elementParserRegistration.Get("FactSet").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"Image\", \"url\":\"www.foo.com\"}", out jsonObject));
            Assert.AreEqual(ElementType.Image, elementParserRegistration.Get("Image").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"ImageSet\", \"images\":[{\"type\":\"Image\", \"url\":\"www.foo.com\"}]}", out jsonObject));
            Assert.AreEqual(ElementType.ImageSet, elementParserRegistration.Get("ImageSet").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"Media\", \"sources\":[{\"mimeType\":\"foo\",\"url\":\"www.foo.com\"}]}", out jsonObject));
            Assert.AreEqual(ElementType.Media, elementParserRegistration.Get("Media").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"Input.Number\", \"id\":\"NumberId\"}", out jsonObject));
            Assert.AreEqual(ElementType.NumberInput, elementParserRegistration.Get("Input.Number").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"TextBlock\",\"text\":\"Hello World\"}", out jsonObject));
            Assert.AreEqual(ElementType.TextBlock, elementParserRegistration.Get("TextBlock").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"Input.Text\", \"id\":\"TextId\"}", out jsonObject));
            Assert.AreEqual(ElementType.TextInput, elementParserRegistration.Get("Input.Text").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"Input.Time\", \"id\":\"TimeId\"}", out jsonObject));
            Assert.AreEqual(ElementType.TimeInput, elementParserRegistration.Get("Input.Time").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"Input.Toggle\", \"id\":\"ToggleId\", \"title\":\"title\"}", out jsonObject));
            Assert.AreEqual(ElementType.ToggleInput, elementParserRegistration.Get("Input.Toggle").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ElementType);
        }