-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathOpenApiServerExtensionsTests.cs
85 lines (74 loc) · 2.54 KB
/
OpenApiServerExtensionsTests.cs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using FluentAssertions;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Xunit;
namespace Microsoft.OpenApi.Tests.Extensions;
public class OpenApiServerExtensionsTests
{
[Fact]
public void ShouldSubstituteServerVariableWithProvidedValues()
{
var variable = new OpenApiServer
{
Url = "http://example.com/api/{version}",
Description = string.Empty,
Variables = new Dictionary<string, OpenApiServerVariable>
{
{ "version", new OpenApiServerVariable { Default = "v1", Enum = ["v1", "v2"]} }
}
};
var url = variable.ReplaceServerUrlVariables(new Dictionary<string, string> {{"version", "v2"}});
url.Should().Be("http://example.com/api/v2");
}
[Fact]
public void ShouldSubstituteServerVariableWithDefaultValues()
{
var variable = new OpenApiServer
{
Url = "http://example.com/api/{version}",
Description = string.Empty,
Variables = new Dictionary<string, OpenApiServerVariable>
{
{ "version", new OpenApiServerVariable { Default = "v1", Enum = ["v1", "v2"]} }
}
};
var url = variable.ReplaceServerUrlVariables(new Dictionary<string, string>(0));
url.Should().Be("http://example.com/api/v1");
}
[Fact]
public void ShouldFailIfNoValueIsAvailable()
{
var variable = new OpenApiServer
{
Url = "http://example.com/api/{version}",
Description = string.Empty,
Variables = new Dictionary<string, OpenApiServerVariable>
{
{ "version", new OpenApiServerVariable { Enum = ["v1", "v2"]} }
}
};
Assert.Throws<ArgumentException>(() =>
{
variable.ReplaceServerUrlVariables(new Dictionary<string, string>(0));
});
}
[Fact]
public void ShouldFailIfProvidedValueIsNotInEnum()
{
var variable = new OpenApiServer
{
Url = "http://example.com/api/{version}",
Description = string.Empty,
Variables = new Dictionary<string, OpenApiServerVariable>
{
{ "version", new OpenApiServerVariable { Enum = ["v1", "v2"]} }
}
};
Assert.Throws<ArgumentException>(() =>
{
variable.ReplaceServerUrlVariables(new Dictionary<string, string> {{"version", "v3"}});
});
}
}