-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestBodyContentGeneratorExtensionTests.cs
More file actions
44 lines (39 loc) · 1.45 KB
/
Copy pathRequestBodyContentGeneratorExtensionTests.cs
File metadata and controls
44 lines (39 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Collections.Generic;
using System.Linq;
using AwesomeAssertions;
using Microsoft.OpenApi;
using OpenAPI.WebApiGenerator.CodeGeneration;
using Xunit;
namespace OpenAPI.WebApiGenerator.UnitTests.CodeGeneration;
public class RequestBodyContentGeneratorExtensionTests
{
[Fact]
public void ListOfRequestBodyContentGenerators_SortByContentType_SortsAccordingToPrecedence()
{
var generators = new[]
{
CreateGenerator("*/*"),
CreateGenerator("application/json; q=0.5"),
CreateGenerator("text/*"),
CreateGenerator("application/geo+json"),
CreateGenerator("application/json"),
CreateGenerator("text/*; q=0.9"),
CreateGenerator("application/json; charset=utf-8"),
CreateGenerator("text/plain"),
};
var sorted = generators.SortByContentType()
.Select(generator => generator.ContentType.ToString())
.ToArray();
sorted.Should().ContainInOrder(
"application/geo+json",
"application/json; charset=utf-8",
"application/json",
"text/plain",
"text/*",
"*/*",
"text/*; q=0.9",
"application/json; q=0.5");
}
private static RequestBodyContentGenerator CreateGenerator(string contentType) =>
new(new KeyValuePair<string, IOpenApiMediaType>(contentType, new OpenApiMediaType()), null!, null!, null!);
}