6
6
using System . Globalization ;
7
7
using System . IO ;
8
8
using System . Linq ;
9
+ using System . Net ;
10
+ using System . Net . Http ;
11
+ using System . Net . Http . Headers ;
9
12
using System . Text ;
10
13
using System . Text . Json . Nodes ;
14
+ using System . Threading ;
11
15
using System . Threading . Tasks ;
12
16
using FluentAssertions ;
13
17
using Microsoft . OpenApi . Extensions ;
20
24
using Microsoft . OpenApi . Validations ;
21
25
using Microsoft . OpenApi . Validations . Rules ;
22
26
using Microsoft . OpenApi . Writers ;
27
+ using Moq ;
28
+ using Moq . Protected ;
23
29
using Xunit ;
24
30
25
31
namespace Microsoft . OpenApi . Readers . Tests . V3Tests
@@ -28,8 +34,6 @@ namespace Microsoft.OpenApi.Readers.Tests.V3Tests
28
34
public class OpenApiDocumentTests
29
35
{
30
36
private const string SampleFolderPath = "V3Tests/Samples/OpenApiDocument/" ;
31
- private const string codacyApi = "https://api.codacy.com/api/api-docs/swagger.yaml" ;
32
-
33
37
private static async Task < T > CloneAsync < T > ( T element ) where T : class , IOpenApiSerializable
34
38
{
35
39
using var stream = new MemoryStream ( ) ;
@@ -1493,8 +1497,24 @@ public async Task ParseDocumentWithExampleReferencesPasses()
1493
1497
[ Fact ]
1494
1498
public async Task ParseDocumentWithNonStandardMIMETypePasses ( )
1495
1499
{
1500
+ var path = Path . Combine ( SampleFolderPath , "basicDocumentWithMultipleServers.yaml" ) ;
1501
+ using var stream = Resources . GetStream ( path ) ;
1502
+ using var streamReader = new StreamReader ( stream ) ;
1503
+ var contentAsString = await streamReader . ReadToEndAsync ( ) ;
1504
+ var mockMessageHandler = new Mock < HttpMessageHandler > ( ) ;
1505
+ mockMessageHandler . Protected ( )
1506
+ . Setup < Task < HttpResponseMessage > > ( "SendAsync" , ItExpr . IsAny < HttpRequestMessage > ( ) , ItExpr . IsAny < CancellationToken > ( ) )
1507
+ . ReturnsAsync ( new HttpResponseMessage {
1508
+ StatusCode = HttpStatusCode . OK ,
1509
+ Content = new StringContent ( contentAsString , new MediaTypeHeaderValue ( "text/x-yaml" ) )
1510
+ } ) ;
1511
+ var settings = new OpenApiReaderSettings
1512
+ {
1513
+ HttpClient = new HttpClient ( mockMessageHandler . Object )
1514
+ } ;
1515
+ settings . AddYamlReader ( ) ;
1496
1516
// Act & Assert: Ensure NotSupportedException is not thrown for non-standard MIME type: text/x-yaml
1497
- var result = await OpenApiDocument . LoadAsync ( codacyApi , SettingsFixture . ReaderSettings ) ;
1517
+ var result = await OpenApiDocument . LoadAsync ( "https://localhost/doesntmatter/foo.bar" , settings ) ;
1498
1518
Assert . NotNull ( result . Document ) ;
1499
1519
}
1500
1520
}
0 commit comments