Esempio n. 1
0
        public void ApplyTests()
        {
            var filter = new WebHookSubscriptionFilter(new TestWebHookTriggerProvider());

            var context = new OperationFilterContext(new ApiDescription()
                                                     , new SchemaGenerator(new NewtonsoftApiModelResolver(new JsonSerializerSettings(), new SchemaGeneratorOptions()), new SchemaGeneratorOptions())
                                                     , new SchemaRepository()
                                                     , typeof(TestedController).GetMethod(nameof(TestedController.TestedMethod)));

            var operation = new OpenApiOperation();

            filter.Apply(operation, context);

            Assert.NotNull(operation.Callbacks);
            Assert.NotEqual(0, operation.Callbacks.Count);
            Assert.Contains("trigger", operation.Callbacks.Keys);
            Assert.Contains("{$request.body#/callback}", operation.Callbacks["trigger"].PathItems.Keys.Select(k => k.Expression));
            Assert.Contains(OperationType.Post, operation.Callbacks["trigger"].PathItems.First().Value.Operations.Keys);

            var op = operation.Callbacks["trigger"].PathItems.First().Value.Operations[OperationType.Post];

            Assert.Equal("trigger", op.OperationId);
            Assert.Equal("description", op.Description);
            Assert.Equal(4, op.Parameters.Count);
            Assert.Equal(4, op.Responses.Count);
        }
Esempio n. 2
0
        public void GenerationDoesNotThrow()
        {
            var provider = new Mock <IWebHookTriggerProvider>();

            provider.Setup(p => p.GetAvailableTriggers()).Returns(new Dictionary <string, WebHookTrigger>
            {
                ["my.trigger"] = new WebHookTrigger
                {
                    Description = "blabla",
                    Id          = "my.trigger",
                    Schema      = new OpenApiSchema
                    {
                        Type       = "object",
                        Properties = new Dictionary <string, OpenApiSchema> {
                            ["prop1"] = new OpenApiSchema {
                                Type = "string"
                            }
                        }
                    }
                },
                ["my.trigger.2"] = new WebHookTrigger
                {
                    Description = "blabla2",
                    Id          = "my.trigger.2",
                    Schema      = new OpenApiSchema
                    {
                        Type       = "object",
                        Properties = new Dictionary <string, OpenApiSchema> {
                            ["prop2"] = new OpenApiSchema {
                                Type = "integer"
                            }
                        }
                    }
                }
            });

            var filter    = new WebHookSubscriptionFilter(provider.Object);
            var context   = new OperationFilterContext(null, new SchemaGenerator(new SchemaGeneratorOptions(), null), new SchemaRepository(), typeof(CallbackGeneratorTests).GetMethod(nameof(WebHookSubscriptionFilterTests)));
            var operation = new OpenApiOperation();

            filter.Apply(operation, context);

            var json = operation.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
            var yaml = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
        }
Esempio n. 3
0
        public void WebHookSubscriptionFilterTests()
        {
            var provider = new Mock <IWebHookTriggerProvider>();

            provider.Setup(p => p.GetAvailableTriggers()).Returns(new Dictionary <string, WebHookTrigger>
            {
                ["my.trigger"] = new WebHookTrigger
                {
                    Description = "blabla",
                    Id          = "my.trigger",
                    Schema      = new OpenApiSchema
                    {
                        Type       = "object",
                        Properties = new Dictionary <string, OpenApiSchema> {
                            ["prop1"] = new OpenApiSchema {
                                Type = "string"
                            }
                        }
                    }
                },
                ["my.trigger.2"] = new WebHookTrigger
                {
                    Description = "blabla2",
                    Id          = "my.trigger.2",
                    Schema      = new OpenApiSchema
                    {
                        Type       = "object",
                        Properties = new Dictionary <string, OpenApiSchema> {
                            ["prop2"] = new OpenApiSchema {
                                Type = "integer"
                            }
                        }
                    }
                }
            });

            var filter    = new WebHookSubscriptionFilter(provider.Object);
            var context   = new OperationFilterContext(null, null, null, typeof(CallbackGeneratorTests).GetMethod(nameof(WebHookSubscriptionFilterTests)));
            var operation = new OpenApiOperation();

            filter.Apply(operation, context);

            Assert.NotNull(operation.Callbacks);
        }