Skip to content

Commit 2f3fbf6

Browse files
authored
Add DoubleObject to test-integration (#143) (#239)
1 parent 79e6a26 commit 2f3fbf6

File tree

3 files changed

+153
-0
lines changed

3 files changed

+153
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
using System.Net.Http;
2+
using System.Threading.Tasks;
3+
4+
using FluentAssertions;
5+
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
8+
using Newtonsoft.Json;
9+
using Newtonsoft.Json.Linq;
10+
11+
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests
12+
{
13+
[TestClass]
14+
[TestCategory(Constants.TestCategory)]
15+
public class Post_ApplicationJson_Double_Tests
16+
{
17+
private static HttpClient http = new HttpClient();
18+
19+
private JObject _doc;
20+
21+
[TestInitialize]
22+
public async Task Init()
23+
{
24+
var json = await http.GetStringAsync(Constants.OpenApiDocEndpoint).ConfigureAwait(false);
25+
this._doc = JsonConvert.DeserializeObject<JObject>(json);
26+
}
27+
28+
[DataTestMethod]
29+
[DataRow("/post-applicationjson-double", "post")]
30+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationRequestBody(string path, string operationType)
31+
{
32+
var requestBody = this._doc["paths"][path][operationType]["requestBody"];
33+
34+
requestBody.Should().NotBeNull();
35+
}
36+
37+
[DataTestMethod]
38+
[DataRow("/post-applicationjson-double", "post", "text/plain")]
39+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationRequestBodyContentType(string path, string operationType, string contentType)
40+
{
41+
var content = this._doc["paths"][path][operationType]["requestBody"]["content"];
42+
43+
content[contentType].Should().NotBeNull();
44+
}
45+
46+
[DataTestMethod]
47+
[DataRow("/post-applicationjson-double", "post", "text/plain", "number", "double")]
48+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationRequestBodyContentTypeSchema(string path, string operationType, string contentType, string propertyType, string propertyFormat)
49+
{
50+
var content = this._doc["paths"][path][operationType]["requestBody"]["content"];
51+
52+
var value = content[contentType]["schema"];
53+
54+
value.Should().NotBeNull();
55+
value.Value<string>("type").Should().Be(propertyType);
56+
value.Value<string>("format").Should().Be(propertyFormat);
57+
}
58+
59+
[DataTestMethod]
60+
[DataRow("/post-applicationjson-double", "post", "200")]
61+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponse(string path, string operationType, string responseCode)
62+
{
63+
var responses = this._doc["paths"][path][operationType]["responses"];
64+
65+
responses[responseCode].Should().NotBeNull();
66+
}
67+
68+
[DataTestMethod]
69+
[DataRow("/post-applicationjson-double", "post", "200", "application/json")]
70+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentType(string path, string operationType, string responseCode, string contentType)
71+
{
72+
var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"];
73+
74+
content[contentType].Should().NotBeNull();
75+
}
76+
77+
[DataTestMethod]
78+
[DataRow("/post-applicationjson-double", "post", "200", "application/json", "doubleObjectModel")]
79+
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentTypeSchema(string path, string operationType, string responseCode, string contentType, string reference)
80+
{
81+
var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"];
82+
83+
var @ref = content[contentType]["schema"]["$ref"];
84+
85+
@ref.Value<string>().Should().Be($"#/components/schemas/{reference}");
86+
}
87+
88+
[DataTestMethod]
89+
[DataRow("doubleObjectModel", "object")]
90+
public void Given_OpenApiDocument_Then_It_Should_Return_ComponentSchema(string @ref, string refType)
91+
{
92+
var schemas = this._doc["components"]["schemas"];
93+
94+
var schema = schemas[@ref];
95+
96+
schema.Should().NotBeNull();
97+
schema.Value<string>("type").Should().Be(refType);
98+
}
99+
100+
[DataTestMethod]
101+
[DataRow("doubleObjectModel", "doubleValue", "number", "double")]
102+
public void Given_OpenApiDocument_Then_It_Should_Return_ComponentSchemaProperty(string @ref, string propertyName, string propertyType, string propertyFormat)
103+
{
104+
var properties = this._doc["components"]["schemas"][@ref]["properties"];
105+
106+
var value = properties[propertyName];
107+
108+
value.Should().NotBeNull();
109+
value.Value<string>("type").Should().Be(propertyType);
110+
value.Value<string>("format").Should().Be(propertyFormat);
111+
}
112+
}
113+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
5+
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp.Models
6+
{
7+
public class DoubleObjectModel
8+
{
9+
public double DoubleValue { get; set; }
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System.Net;
2+
using System.Threading.Tasks;
3+
4+
using Microsoft.AspNetCore.Http;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Azure.WebJobs.Extensions.Http;
7+
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
8+
using Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp.Models;
9+
using Microsoft.Extensions.Logging;
10+
using Microsoft.OpenApi.Models;
11+
12+
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp
13+
{
14+
public static class Post_ApplicationJson_DoubleObject_HttpTrigger
15+
{
16+
[FunctionName(nameof(Post_ApplicationJson_DoubleObject_HttpTrigger))]
17+
[OpenApiOperation(operationId: nameof(Post_ApplicationJson_DoubleObject_HttpTrigger.Post_ApplicationJson_DoubleObject), tags: new[] { "double" })]
18+
[OpenApiRequestBody(contentType: "text/plain", bodyType: typeof(double), Required = true, Description = "The OK response")]
19+
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(DoubleObjectModel), Description = "The OK response")]
20+
public static async Task<IActionResult> Post_ApplicationJson_DoubleObject(
21+
[HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = "post-applicationjson-double")] HttpRequest req,
22+
ILogger log)
23+
{
24+
var result = new OkResult();
25+
26+
return await Task.FromResult(result).ConfigureAwait(false);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)