Ejemplo n.º 1
0
            public IAdaptiveActionElement FromJson(JsonObject inputJson, AdaptiveElementParserRegistration elementParsers, AdaptiveActionParserRegistration actionParsers, IList <AdaptiveWarning> warnings)
            {
                JsonObject jsonSubmitAction   = inputJson.GetNamedObject("internalSubmitAction");
                var        submitActionParser = actionParsers.Get("Action.Submit");

                IAdaptiveActionElement submitAction = submitActionParser.FromJson(jsonSubmitAction, elementParsers, actionParsers, warnings);

                return(new TestCustomAction(submitAction) as IAdaptiveActionElement);
            }
Ejemplo n.º 2
0
        public void ActionParserRegistraton_DefaultActionsTest()
        {
            AdaptiveActionParserRegistration  actionParserRegistration  = new AdaptiveActionParserRegistration();
            AdaptiveElementParserRegistration elementParserRegistration = new AdaptiveElementParserRegistration();
            List <AdaptiveWarning>            warnings = new List <AdaptiveWarning>();

            JsonObject jsonObject;

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

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"Action.ShowCard\", \"card\":{\"type\":\"AdaptiveCard\", \"version\":\"1.0\"}}", out jsonObject));
            Assert.AreEqual(ActionType.ShowCard, actionParserRegistration.Get("Action.ShowCard").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ActionType);

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

            Assert.IsTrue(JsonObject.TryParse("{\"type\":\"Action.ToggleVisibility\",\"targetElements\": [{\"elementId\":\"idToggle\"}]}", out jsonObject));
            Assert.AreEqual(ActionType.ToggleVisibility, actionParserRegistration.Get("Action.ToggleVisibility").FromJson(jsonObject, elementParserRegistration, actionParserRegistration, warnings).ActionType);
        }
Ejemplo n.º 3
0
        public void ActionParserRegistraton_CustomActionTest()
        {
            AdaptiveActionParserRegistration  actionParserRegistration  = new AdaptiveActionParserRegistration();
            AdaptiveElementParserRegistration elementParserRegistration = new AdaptiveElementParserRegistration();
            List <AdaptiveWarning>            warnings = new List <AdaptiveWarning>();

            actionParserRegistration.Set("TestCustomAction", new TestActionParser());
            IAdaptiveActionParser testActionParserRetrieved = actionParserRegistration.Get("TestCustomAction");

            Assert.IsNotNull(testActionParserRetrieved);
            Assert.IsNotNull(testActionParserRetrieved as TestActionParser);

            String testCard =
                "{" +
                "   \"type\":\"AdaptiveCard\"," +
                "   \"version\":\"1.0\"," +
                "   \"body\":" +
                "   [" +
                "   ]," +
                "   \"actions\":" +
                "   [" +
                "       {" +
                "           \"type\":\"TestCustomAction\"," +
                "           \"internalSubmitAction\":" +
                "           {" +
                "               \"type\": \"Action.Submit\"" +
                "           }" +
                "       }" +
                "   ]" +
                "}";

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

            Assert.IsNotNull(card);

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

            IAdaptiveActionElement action = card.Actions[0];

            Assert.IsNotNull(action);

            Assert.AreEqual(ActionType.Custom, action.ActionType);
            Assert.AreEqual("TestCustomAction", action.ActionTypeString);

            TestCustomAction customElement = card.Actions[0] as TestCustomAction;

            Assert.IsNotNull(customElement);

            Assert.AreEqual(ActionType.Submit, customElement.InternalSubmitAction.ActionType);
        }