Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task Init()
}

[DataTestMethod]
[DataRow("/get-applicationjson-dictionary", "get", "200")]
[DataRow("/get-applicationjson-dictionaryobject", "get", "200")]
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponse(string path, string operationType, string responseCode)
{
var responses = this._doc["paths"][path][operationType]["responses"];
Expand All @@ -35,7 +35,7 @@ public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponse(string
}

[DataTestMethod]
[DataRow("/get-applicationjson-dictionary", "get", "200", "application/json")]
[DataRow("/get-applicationjson-dictionaryobject", "get", "200", "application/json")]
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentType(string path, string operationType, string responseCode, string contentType)
{
var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"];
Expand All @@ -44,7 +44,7 @@ public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContent
}

[DataTestMethod]
[DataRow("/get-applicationjson-dictionary", "get", "200", "application/json", "dictionaryObjectModel")]
[DataRow("/get-applicationjson-dictionaryobject", "get", "200", "application/json", "dictionaryObjectModel")]
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentTypeSchema(string path, string operationType, string responseCode, string contentType, string reference)
{
var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;

using FluentAssertions;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Tests
{
[TestClass]
[TestCategory(Constants.TestCategory)]
public class Get_ApplicationJson_Dictionary_Tests
{
private static HttpClient http = new HttpClient();

private JObject _doc;

[TestInitialize]
public async Task Init()
{
var json = await http.GetStringAsync(Constants.OpenApiDocEndpoint).ConfigureAwait(false);
this._doc = JsonConvert.DeserializeObject<JObject>(json);
}

[DataTestMethod]
[DataRow("/get-applicationjson-dictionary")]
[DataRow("/get-applicationjson-dictionary-idictionary")]
[DataRow("/get-applicationjson-dictionary-ireadonlydictionary")]
[DataRow("/get-applicationjson-dictionary-keyvaluepair")]
public void Given_OpenApiDocument_Then_It_Should_Return_Path(string path)
{
var paths = this._doc["paths"];

paths.Value<JToken>(path).Should().NotBeNull();
}

[DataTestMethod]
[DataRow("/get-applicationjson-dictionary", "get")]
[DataRow("/get-applicationjson-dictionary-idictionary", "get")]
[DataRow("/get-applicationjson-dictionary-ireadonlydictionary", "get")]
[DataRow("/get-applicationjson-dictionary-keyvaluepair", "get")]
public void Given_OpenApiDocument_Then_It_Should_Return_OperationType(string path, string operationType)
{
var pathItem = this._doc["paths"][path];

pathItem.Value<JToken>(operationType).Should().NotBeNull();
}

[DataTestMethod]
[DataRow("/get-applicationjson-dictionary", "get", "200")]
[DataRow("/get-applicationjson-dictionary-idictionary", "get", "200")]
[DataRow("/get-applicationjson-dictionary-ireadonlydictionary", "get", "200")]
[DataRow("/get-applicationjson-dictionary-keyvaluepair", "get", "200")]
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponse(string path, string operationType, string responseCode)
{
var responses = this._doc["paths"][path][operationType]["responses"];

responses[responseCode].Should().NotBeNull();
}

[DataTestMethod]
[DataRow("/get-applicationjson-dictionary", "get", "200", "application/json")]
[DataRow("/get-applicationjson-dictionary-idictionary", "get", "200", "application/json")]
[DataRow("/get-applicationjson-dictionary-ireadonlydictionary", "get", "200", "application/json")]
[DataRow("/get-applicationjson-dictionary-keyvaluepair", "get", "200", "application/json")]
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentType(string path, string operationType, string responseCode, string contentType)
{
var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"];

content[contentType].Should().NotBeNull();
}

[DataTestMethod]
[DataRow("/get-applicationjson-dictionary", "get", "200", "application/json", "object")]
[DataRow("/get-applicationjson-dictionary-idictionary", "get", "200", "application/json","object")]
[DataRow("/get-applicationjson-dictionary-ireadonlydictionary", "get", "200", "application/json", "object")]
[DataRow("/get-applicationjson-dictionary-keyvaluepair", "get", "200", "application/json", "object")]
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentTypeSchemaType(string path, string operationType, string responseCode, string contentType, string itemType)
{
var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"];
var schema = content[contentType]["schema"];

var type = schema["type"];

type.Value<string>().Should().Be(itemType);
}

[DataTestMethod]
[DataRow("/get-applicationjson-dictionary", "get", "200", "application/json", "object", "string")]
[DataRow("/get-applicationjson-dictionary-idictionary", "get", "200", "application/json", "object", "integer")]
[DataRow("/get-applicationjson-dictionary-ireadonlydictionary", "get", "200", "application/json", "object", "number")]
[DataRow("/get-applicationjson-dictionary-keyvaluepair", "get", "200", "application/json", "object", "boolean")]
public void Given_OpenApiDocument_Then_It_Should_Return_OperationResponseContentTypeSchemaPropertiesType(string path, string operationType, string responseCode, string contentType, string dataType, string itemType)
{
var content = this._doc["paths"][path][operationType]["responses"][responseCode]["content"];
var schema = content[contentType]["schema"];

var additionaltype = schema["additionalProperties"]["type"];

additionaltype.Value<string>().Should().Be(itemType);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Get_ApplicationJson_DictionaryObject_HttpTrigger
[OpenApiOperation(operationId: nameof(Get_ApplicationJson_DictionaryObject_HttpTrigger.Get_ApplicationJson_DictionaryObject), tags: new[] { "dictionary" })]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(DictionaryObjectModel), Description = "The OK response")]
public static async Task<IActionResult> Get_ApplicationJson_DictionaryObject(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-dictionary")] HttpRequest req,
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-dictionaryobject")] HttpRequest req,
ILogger log)
{
var result = new OkResult();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Attributes;
using Microsoft.Extensions.Logging;

namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.TestApp
{
public class Get_ApplicationJson_Dictionary_HttpTrigger
{
[FunctionName(nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary))]
[OpenApiOperation(operationId: nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary), tags: new[] { "dictionary" })]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(Dictionary<string,string>), Description = "The OK response")]
public static async Task<IActionResult> Get_ApplicationJson_Dictionary(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-dictionary")] HttpRequest req,
ILogger log)
{
var result = new OkResult();

return await Task.FromResult(result).ConfigureAwait(false);
}

[FunctionName(nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary_IDictionary))]
[OpenApiOperation(operationId: nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary_IDictionary), tags: new[] { "dictionary" })]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(IDictionary<string,int>), Description = "The OK response")]
public static async Task<IActionResult> Get_ApplicationJson_Dictionary_IDictionary(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-dictionary-idictionary")] HttpRequest req,
ILogger log)
{
var result = new OkResult();

return await Task.FromResult(result).ConfigureAwait(false);
}

[FunctionName(nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary_IReadOnlyDictionary))]
[OpenApiOperation(operationId: nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary_IReadOnlyDictionary), tags: new[] { "dictionary" })]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(IReadOnlyDictionary<string,double>), Description = "The OK response")]
public static async Task<IActionResult> Get_ApplicationJson_Dictionary_IReadOnlyDictionary(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-dictionary-ireadonlydictionary")] HttpRequest req,
ILogger log)
{
var result = new OkResult();

return await Task.FromResult(result).ConfigureAwait(false);
}

[FunctionName(nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary_KeyValuePair))]
[OpenApiOperation(operationId: nameof(Get_ApplicationJson_Dictionary_HttpTrigger.Get_ApplicationJson_Dictionary_KeyValuePair), tags: new[] { "dictionary" })]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(KeyValuePair<string,bool>), Description = "The OK response")]
public static async Task<IActionResult> Get_ApplicationJson_Dictionary_KeyValuePair(
[HttpTrigger(AuthorizationLevel.Anonymous, "GET", Route = "get-applicationjson-dictionary-keyvaluepair")] HttpRequest req,
ILogger log)
{
var result = new OkResult();

return await Task.FromResult(result).ConfigureAwait(false);
}
}

}