-
Notifications
You must be signed in to change notification settings - Fork 197
Add Dictionary test codes and modify Dictionaryobject route #323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...t.Azure.WebJobs.Extensions.OpenApi.Document.Tests/Get_ApplicationJson_Dictionary_Tests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...ft.Azure.WebJobs.Extensions.OpenApi.TestApp/Get_ApplicationJson_Dictionary_HttpTrigger.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.