Beispiel #1
0
        public void i_can_compare_operation_with_body_mediatypes_added_or_removed()
        {
            var context = ComparisonContext.FromPath("/path") with {
                Method = OperationType.Get
            };
            var previousOperation = new OpenApiOperation()
            {
                RequestBody = new OpenApiRequestBody()
                {
                    Content = { ["application/json"] = new OpenApiMediaType() }
                }
            };
            var actualOperation = new OpenApiOperation()
            {
                RequestBody = new OpenApiRequestBody()
                {
                    Content =
                    {
                        ["application/xml"] = new OpenApiMediaType(), ["text/xml"] = new OpenApiMediaType()
                    }
                }
            };
            var diffs = previousOperation.CompareTo(actualOperation, context).ToArray();

            foreach (DiffResult diff in diffs)
            {
                TestContext.Progress.WriteLine($"[{diff.Context}] {diff.Kind}: '{diff.Message}'");
            }
            Assert.AreEqual(3, diffs.Length, "unexpected differences count");
        }
Beispiel #2
0
        public void i_can_compare_operation_parameter()
        {
            var context = ComparisonContext.FromPath("/path") with {
                Method = OperationType.Get
            };
            var previousOperation = new OpenApiOperation()
            {
                Parameters =
                {
                    new OpenApiParameter()
                    {
                        Name = "RemovedParam"
                    },
                    new OpenApiParameter()
                    {
                        Name = "ModifiedParam", Deprecated = false
                    },
                    new OpenApiParameter()
                    {
                        Name = "Unmodified"
                    }
                }
            };
            var actualOperation = new OpenApiOperation()
            {
                Parameters =
                {
                    new OpenApiParameter()
                    {
                        Name = "AddedParam"
                    },
                    new OpenApiParameter()
                    {
                        Name = "ModifiedParam", Deprecated = true
                    },
                    new OpenApiParameter()
                    {
                        Name = "Unmodified"
                    }
                }
            };
            var diffs = previousOperation.CompareTo(actualOperation, context).ToArray();

            foreach (DiffResult diff in diffs)
            {
                TestContext.Progress.WriteLine($"[{diff.Context}] {diff.Kind}: '{diff.Message}'");
            }

            Assert.AreEqual(3, diffs.Length, "unexpected differences count");
            foreach (DiffResult diff in diffs)
            {
                //Assert.AreEqual(context with { Request = "<Body>"}, diff.Context, "unexpected context");
            }
        }
Beispiel #3
0
        public void i_can_compare_response_schema(OpenApiSchema previousSchema, OpenApiSchema actualSchema,
                                                  int expectedDiff)
        {
            var context = ComparisonContext.FromPath("/path") with {
                Method = OperationType.Get
            };
            var previousOperation = new OpenApiOperation()
            {
                Responses = new OpenApiResponses()
                {
                    ["200"] = new OpenApiResponse()
                    {
                        Content =
                        {
                            ["application/json"] = new OpenApiMediaType()
                            {
                            Schema = previousSchema
                            }
                        }
                    }
                }
            };
            var actualOperation = new OpenApiOperation()
            {
                Responses = new OpenApiResponses()
                {
                    ["200"] = new OpenApiResponse()
                    {
                        Content =
                        {
                            ["application/json"] = new OpenApiMediaType()
                            {
                            Schema = actualSchema
                            }
                        }
                    }
                }
            };

            DiffResult[] diffs = previousOperation.CompareTo(actualOperation, context).ToArray();
            foreach (DiffResult diff in diffs)
            {
                TestContext.Progress.WriteLine($"[{diff.Context}] {diff.Kind}: '{diff.Message}'");
            }

            Assert.AreEqual(expectedDiff, diffs.Length, "unexpected differences count");
            foreach (DiffResult diff in diffs)
            {
                //Assert.AreEqual(context with { Request = "<Body>"}, diff.Context, "unexpected context");
            }
        }
Beispiel #4
0
        public void i_can_compare_operation_body()
        {
            var context = ComparisonContext.FromPath("/path") with {
                Method = OperationType.Get
            };
            var previousOperation = new OpenApiOperation()
            {
                RequestBody = new OpenApiRequestBody()
                {
                    Content =
                    {
                        ["application/json"] = new OpenApiMediaType()
                                        {
                                        Encoding =
                                        {
                                        ["ENC1"] = new OpenApiEncoding()
                                        {
                                        AllowReserved = false,
                                        Headers       =
                                        {
                                        ["Header1"] = new OpenApiHeader()
                                        {
                                        Required = true
                                        }
                                        }
                                        }
                                        },
                                        Schema = new OpenApiSchema()
                                        {
                                        Type = "string"
                                        }
                                        }
                    }
                }
            };
            var actualOperation = new OpenApiOperation()
            {
                RequestBody = new OpenApiRequestBody()
                {
                    Content =
                    {
                        ["application/json"] = new OpenApiMediaType()
                                        {
                                        Encoding =
                                        {
                                        ["ENC1"] = new OpenApiEncoding()
                                        {
                                        AllowReserved = true,
                                        Headers       =
                                        {
                                        ["Header1"] = new OpenApiHeader()
                                        {
                                        Required = false
                                        },
                                        ["Header2"] = new OpenApiHeader()
                                        }
                                        }
                                        }
                                        },
                        ["application/xml"] = new OpenApiMediaType(), ["text/xml"] = new OpenApiMediaType()
                    }
                }
            };
            var diffs = previousOperation.CompareTo(actualOperation, context).ToArray();

            foreach (DiffResult diff in diffs)
            {
                TestContext.Progress.WriteLine($"[{diff.Context}] {diff.Kind}: '{diff.Message}'");
            }

            Assert.AreEqual(6, diffs.Length, "unexpected differences count");
            foreach (DiffResult diff in diffs)
            {
                //Assert.AreEqual(context with { Request = "<Body>"}, diff.Context, "unexpected context");
            }
        }