Ejemplo n.º 1
0
        public static KongPlugin AsTarget(this KongPlugin kongPlugin, bool modified = false)
        {
            var target = kongPlugin.Clone();

            if (modified)
            {
                if (target.Config.HasValues)
                {
                    target.Config[0] = Guid.NewGuid().ToString();
                }
                else
                {
                    target.Config.Add(Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
                }
            }
            return(target);
        }
Ejemplo n.º 2
0
        protected ValidatableObjectSteps()
        {
            var examplePluginSchema = new KongPluginSchema
            {
                Fields = new Dictionary <string, FieldDefinition>
                {
                    {
                        "field1",
                        new FieldDefinition
                        {
                            Type    = "number",
                            Default = JToken.FromObject(0)
                        }
                    },
                    {
                        "field2",
                        new FieldDefinition
                        {
                            Type = "string"
                        }
                    },
                    {
                        "field3",
                        new FieldDefinition
                        {
                            Type   = "table",
                            Schema = new KongPluginSchema
                            {
                                Fields = new Dictionary <string, FieldDefinition>
                                {
                                    {
                                        "field1",
                                        new FieldDefinition
                                        {
                                            Type = "boolean"
                                        }
                                    },
                                    {
                                        "field2",
                                        new FieldDefinition
                                        {
                                            Type    = "string",
                                            Default = JToken.FromObject(this.Create <string>())
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            ExamplePlugin = new KongPlugin
            {
                Name   = "plugin1",
                Config = JObject.FromObject(new
                {
                    field1 = 1,
                    field2 = this.Create <string>(),
                    field3 = new
                    {
                        field1 = this.Create <bool>(),
                        field2 = this.Create <string>()
                    }
                })
            };

            ExamplePluginWithMissingDefaultConfigFields = ExamplePlugin.Clone();
            ExamplePluginWithMissingDefaultConfigFields.Config.Remove("field1");
            ((JObject)ExamplePluginWithMissingDefaultConfigFields.Config.SelectToken("field3")).Remove("field2");

            ExamplePluginWithOneInvalidConfigField = ExamplePlugin.Clone();
            ExamplePluginWithOneInvalidConfigField.Config.Remove("field3");
            ExamplePluginWithOneInvalidConfigField.Config.Add("field3", JToken.FromObject(this.Create <string>()));

            ExamplePluginWithTwoUnknownConfigFields = ExamplePlugin.Clone();
            ExamplePluginWithTwoUnknownConfigFields.Config.Add(this.Create <string>(), JToken.FromObject(1));
            ((JObject)ExamplePluginWithTwoUnknownConfigFields.Config.SelectToken("field3")).Add(this.Create <string>(), JToken.FromObject(this.Create <bool>()));

            AvailablePlugins.Add(ExamplePlugin.Name, new AsyncLazy <KongPluginSchema>(() => Task.FromResult(examplePluginSchema)));
        }