-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
201 additions
and
71 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
82 changes: 82 additions & 0 deletions
82
...ctions.Extensions.OpenApi.Core.Tests/Extensions/OpenApiPayloadAttributeExtensionsTests.cs
This file contains 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,82 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
|
||
using Aliencube.AzureFunctions.Extensions.OpenApi.Core.Attributes; | ||
using Aliencube.AzureFunctions.Extensions.OpenApi.Core.Extensions; | ||
using Aliencube.AzureFunctions.Extensions.OpenApi.Core.Tests.Fakes; | ||
|
||
using FluentAssertions; | ||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
|
||
using Newtonsoft.Json.Serialization; | ||
|
||
namespace Aliencube.AzureFunctions.Extensions.OpenApi.Core.Tests.Extensions | ||
{ | ||
[TestClass] | ||
public class OpenApiPayloadAttributeExtensionsTests | ||
{ | ||
[TestMethod] | ||
public void Given_Null_When_ToOpenApiMediaType_Invoked_Then_It_Should_Throw_Exception() | ||
{ | ||
Action action = () => OpenApiPayloadAttributeExtensions.ToOpenApiMediaType((OpenApiPayloadAttribute)null); | ||
|
||
action.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow(typeof(string), "string")] | ||
[DataRow(typeof(FakeModel), "object")] | ||
public void Given_OpenApiRequestBodyAttribute_When_ToOpenApiMediaType_Invoked_Then_It_Should_Return_Result(Type bodyType, string expected) | ||
{ | ||
var contentType = "application/json"; | ||
var attribute = new OpenApiRequestBodyAttribute(contentType, bodyType) | ||
{ | ||
Required = true, | ||
Description = "Dummy request model" | ||
}; | ||
var namingStrategy = new CamelCaseNamingStrategy(); | ||
|
||
var result = OpenApiPayloadAttributeExtensions.ToOpenApiMediaType(attribute, namingStrategy); | ||
|
||
result.Schema.Type.Should().Be(expected); | ||
} | ||
|
||
[DataTestMethod] | ||
[DataRow(typeof(string), "string", false, false, null)] | ||
[DataRow(typeof(FakeModel), "object", false, false, null)] | ||
[DataRow(typeof(List<string>), "array", true, false, "string")] | ||
[DataRow(typeof(Dictionary<string, int?>), "object", false, true, "integer")] | ||
public void Given_OpenApiResponseWithBodyAttribute_When_ToOpenApiMediaType_Invoked_Then_It_Should_Return_Result(Type bodyType, string expected, bool items, bool additionalProperties, string underlyingType) | ||
{ | ||
var statusCode = HttpStatusCode.OK; | ||
var contentType = "application/json"; | ||
var attribute = new OpenApiResponseWithBodyAttribute(statusCode, contentType, bodyType); | ||
var namingStrategy = new CamelCaseNamingStrategy(); | ||
|
||
var result = OpenApiPayloadAttributeExtensions.ToOpenApiMediaType(attribute, namingStrategy); | ||
|
||
result.Schema.Type.Should().Be(expected); | ||
if (items) | ||
{ | ||
result.Schema.Items.Should().NotBeNull(); | ||
result.Schema.Items.Type.Should().Be(underlyingType); | ||
} | ||
else | ||
{ | ||
result.Schema.Items.Should().BeNull(); | ||
} | ||
|
||
if (additionalProperties) | ||
{ | ||
result.Schema.AdditionalProperties.Should().NotBeNull(); | ||
result.Schema.AdditionalProperties.Type.Should().Be(underlyingType); | ||
} | ||
else | ||
{ | ||
result.Schema.AdditionalProperties.Should().BeNull(); | ||
} | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.