1+ using System . Text . Json ;
2+
3+ using AzureOpenAIProxy . AppHost . Tests . Fixtures ;
4+
5+ using FluentAssertions ;
6+
7+ using IdentityModel . Client ;
8+
9+ namespace AzureOpenAIProxy . AppHost . Tests . ApiApp . Endpoints ;
10+
11+ public class GetEventsOpenApiTests ( AspireAppHostFixture host ) : IClassFixture < AspireAppHostFixture >
12+ {
13+ [ Fact ]
14+ public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Path ( )
15+ {
16+ // Arrange
17+ using var httpClient = host . App ! . CreateHttpClient ( "apiapp" ) ;
18+
19+ // Act
20+ var json = await httpClient . GetStringAsync ( "/swagger/v1.0.0/swagger.json" ) ;
21+ var apiDocument = JsonSerializer . Deserialize < JsonDocument > ( json ) ;
22+
23+ // Assert
24+ var result = apiDocument ! . RootElement . GetProperty ( "paths" )
25+ . TryGetProperty ( "/events" , out var property ) ? property : default ;
26+ result . ValueKind . Should ( ) . Be ( JsonValueKind . Object ) ;
27+ }
28+
29+ [ Fact ]
30+ public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Verb ( )
31+ {
32+ // Arrange
33+ using var httpClient = host . App ! . CreateHttpClient ( "apiapp" ) ;
34+
35+ // Act
36+ var json = await httpClient . GetStringAsync ( "/swagger/v1.0.0/swagger.json" ) ;
37+ var apiDocument = JsonSerializer . Deserialize < JsonDocument > ( json ) ;
38+
39+ // Assert
40+ var result = apiDocument ! . RootElement . GetProperty ( "paths" )
41+ . GetProperty ( "/events" )
42+ . TryGetProperty ( "get" , out var property ) ? property : default ;
43+ result . ValueKind . Should ( ) . Be ( JsonValueKind . Object ) ;
44+ }
45+
46+ [ Theory ]
47+ [ InlineData ( "events" ) ]
48+ public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Tags ( string tag )
49+ {
50+ // Arrange
51+ using var httpClient = host . App ! . CreateHttpClient ( "apiapp" ) ;
52+
53+ // Act
54+ var json = await httpClient . GetStringAsync ( "/swagger/v1.0.0/swagger.json" ) ;
55+ var apiDocument = JsonSerializer . Deserialize < JsonDocument > ( json ) ;
56+
57+ // Assert
58+ var result = apiDocument ! . RootElement . GetProperty ( "paths" )
59+ . GetProperty ( "/events" )
60+ . GetProperty ( "get" )
61+ . TryGetProperty ( "tags" , out var property ) ? property : default ;
62+ result . ValueKind . Should ( ) . Be ( JsonValueKind . Array ) ;
63+ result . EnumerateArray ( ) . Select ( p => p . GetString ( ) ) . Should ( ) . Contain ( tag ) ;
64+ }
65+
66+ [ Theory ]
67+ [ InlineData ( "summary" ) ]
68+ [ InlineData ( "operationId" ) ]
69+ public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Value ( string attribute )
70+ {
71+ // Arrange
72+ using var httpClient = host . App ! . CreateHttpClient ( "apiapp" ) ;
73+
74+ // Act
75+ var json = await httpClient . GetStringAsync ( "/swagger/v1.0.0/swagger.json" ) ;
76+ var apiDocument = JsonSerializer . Deserialize < JsonDocument > ( json ) ;
77+
78+ // Assert
79+ var result = apiDocument ! . RootElement . GetProperty ( "paths" )
80+ . GetProperty ( "/events" )
81+ . GetProperty ( "get" )
82+ . TryGetProperty ( attribute , out var property ) ? property : default ;
83+ result . ValueKind . Should ( ) . Be ( JsonValueKind . String ) ;
84+ }
85+
86+ [ Theory ]
87+ [ InlineData ( "responses" ) ]
88+ public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Object ( string attribute )
89+ {
90+ // Arrange
91+ using var httpClient = host . App ! . CreateHttpClient ( "apiapp" ) ;
92+
93+ // Act
94+ var json = await httpClient . GetStringAsync ( "/swagger/v1.0.0/swagger.json" ) ;
95+ var apiDocument = JsonSerializer . Deserialize < JsonDocument > ( json ) ;
96+
97+ // Assert
98+ var result = apiDocument ! . RootElement . GetProperty ( "paths" )
99+ . GetProperty ( "/events" )
100+ . GetProperty ( "get" )
101+ . TryGetProperty ( attribute , out var property ) ? property : default ;
102+ result . ValueKind . Should ( ) . Be ( JsonValueKind . Object ) ;
103+ }
104+
105+ [ Theory ]
106+ [ InlineData ( "200" ) ]
107+ [ InlineData ( "401" ) ]
108+ [ InlineData ( "500" ) ]
109+ public async Task Given_Resource_When_Invoked_Endpoint_Then_It_Should_Return_Response ( string attribute )
110+ {
111+ // Arrange
112+ using var httpClient = host . App ! . CreateHttpClient ( "apiapp" ) ;
113+
114+ // Act
115+ var json = await httpClient . GetStringAsync ( "/swagger/v1.0.0/swagger.json" ) ;
116+ var apiDocument = JsonSerializer . Deserialize < JsonDocument > ( json ) ;
117+
118+ // Assert
119+ var result = apiDocument ! . RootElement . GetProperty ( "paths" )
120+ . GetProperty ( "/events" )
121+ . GetProperty ( "get" )
122+ . GetProperty ( "responses" )
123+ . TryGetProperty ( attribute , out var property ) ? property : default ;
124+ result . ValueKind . Should ( ) . Be ( JsonValueKind . Object ) ;
125+ }
126+ }
0 commit comments