11using System . Globalization ;
22using System . Net ;
33using System . Net . Http . Json ;
4- using System . Text . Json ;
54using Api . Endpoints ;
65using IntegrationTests . Setup ;
76using Shouldly ;
@@ -19,9 +18,7 @@ public sealed class ApiEndpointsTests(Fixture fixture) : IntegrationTestBase(fix
1918 public static TheoryData < string ? , string ? , HttpStatusCode > Cases =>
2019 new ( )
2120 {
22- { DateTime . Now . AddMonths ( - 1 ) . ToString ( DateFormat , CultureInfo . InvariantCulture ) , DateTime . Now . ToString ( DateFormat , CultureInfo . InvariantCulture ) , HttpStatusCode . OK } ,
2321 { s_mockCutOffDate . ToString ( DateFormat , CultureInfo . InvariantCulture ) , s_mockCutOffDate . AddYears ( 1 ) . AddDays ( 1 ) . ToString ( DateFormat , CultureInfo . InvariantCulture ) , HttpStatusCode . Unauthorized } , //Unauthorized for over 365 days old queries
24- { "" , null , HttpStatusCode . BadRequest } ,
2522 } ;
2623
2724 [ Theory ]
@@ -38,93 +35,4 @@ public async Task LongestDownwardTrend(string? fromDate, string? toDate, HttpSta
3835 data . ShouldNotBeNull ( ) ;
3936 }
4037 }
41-
42- [ Theory ]
43- [ MemberData ( nameof ( Cases ) ) ]
44- public async Task HighestTradingVolume ( string ? fromDate , string ? toDate , HttpStatusCode status )
45- {
46- var ct = TestContext . Current . CancellationToken ;
47- var result = await _client . GetAsync ( new Uri ( $ "{ BaseUrl } /highestradingvolume?fromDate={ fromDate } &toDate={ toDate } ", UriKind . Relative ) , cancellationToken : ct ) ;
48- result . StatusCode . ShouldBeOneOf ( status , HttpStatusCode . TooManyRequests ) ;
49-
50- if ( result . StatusCode == HttpStatusCode . OK )
51- {
52- var data = await result . Content . ReadFromJsonAsync < HighestTradingVolumeResponse > ( cancellationToken : ct ) ;
53- data . ShouldNotBeNull ( ) ;
54- }
55- }
56-
57- [ Theory ]
58- [ MemberData ( nameof ( Cases ) ) ]
59- public async Task BuyAndSell ( string ? fromDate , string ? toDate , HttpStatusCode status )
60- {
61- var ct = TestContext . Current . CancellationToken ;
62- var result = await _client . GetAsync ( new Uri ( $ "{ BaseUrl } /buyandsell?fromDate={ fromDate } &toDate={ toDate } ", UriKind . Relative ) , cancellationToken : ct ) ;
63- result . StatusCode . ShouldBeOneOf ( status , HttpStatusCode . TooManyRequests ) ;
64-
65- if ( result . StatusCode == HttpStatusCode . OK )
66- {
67- var data = await result . Content . ReadFromJsonAsync < BuyAndSellResponse > ( cancellationToken : ct ) ;
68- data . ShouldNotBeNull ( ) ;
69- }
70- }
71-
72- [ Theory ]
73- [ InlineData ( "/swagger" ) ]
74- [ InlineData ( "/scalar" ) ]
75- public async Task DocsUI ( string endpoint )
76- {
77- var ct = TestContext . Current . CancellationToken ;
78- var result = await _client . GetAsync ( new Uri ( endpoint , UriKind . Relative ) , cancellationToken : ct ) ;
79- result . StatusCode . ShouldBe ( HttpStatusCode . OK ) ;
80- }
81-
82- [ Theory ]
83- [ InlineData ( "/openapi/v1.json" ) ]
84- public async Task DocsJson ( string endpoint )
85- {
86- var ct = TestContext . Current . CancellationToken ;
87- var result = await _client . GetAsync ( new Uri ( endpoint , UriKind . Relative ) , cancellationToken : ct ) ;
88- result . StatusCode . ShouldBe ( HttpStatusCode . OK ) ;
89-
90- var data = await result . Content . ReadAsStringAsync ( cancellationToken : ct ) ;
91-
92- Should . NotThrow ( ( ) =>
93- {
94- using var document = JsonDocument . Parse ( data ) ;
95- var root = document . RootElement ;
96-
97- root . TryGetProperty ( "openapi" , out var _ ) . ShouldBeTrue ( "Missing 'openapi' key" ) ;
98-
99- var firstPath = root . GetProperty ( "paths" ) . EnumerateObject ( ) . First ( ) ;
100- var parameters = firstPath . Value
101- . GetProperty ( "get" )
102- . GetProperty ( "parameters" ) ;
103-
104- foreach ( var param in parameters . EnumerateArray ( ) )
105- {
106- string ? example = null ;
107-
108- if ( param . TryGetProperty ( "example" , out var exampleElement ) )
109- {
110- example = exampleElement . GetString ( ) ;
111- }
112- else if ( param . TryGetProperty ( "schema" , out var schema ) &&
113- schema . TryGetProperty ( "example" , out var schemaExample ) )
114- {
115- example = schemaExample . GetString ( ) ;
116- }
117-
118- example . ShouldNotBeNullOrWhiteSpace ( "Missing example for parameter" ) ;
119- }
120- } ) ;
121- }
122-
123- [ Fact ]
124- public async Task Health ( )
125- {
126- var ct = TestContext . Current . CancellationToken ;
127- var result = await _client . GetAsync ( new Uri ( "/health" , UriKind . Relative ) , cancellationToken : ct ) ;
128- result . StatusCode . ShouldBe ( HttpStatusCode . OK ) ;
129- }
13038}
0 commit comments