66using System . Globalization ;
77using System . IO ;
88using System . Linq ;
9+ using System . Net ;
10+ using System . Net . Http ;
11+ using System . Net . Http . Headers ;
912using System . Text ;
1013using System . Text . Json . Nodes ;
14+ using System . Threading ;
1115using System . Threading . Tasks ;
1216using FluentAssertions ;
1317using Microsoft . OpenApi . Extensions ;
2024using Microsoft . OpenApi . Validations ;
2125using Microsoft . OpenApi . Validations . Rules ;
2226using Microsoft . OpenApi . Writers ;
27+ using Moq ;
28+ using Moq . Protected ;
2329using Xunit ;
2430
2531namespace Microsoft . OpenApi . Readers . Tests . V3Tests
@@ -28,8 +34,6 @@ namespace Microsoft.OpenApi.Readers.Tests.V3Tests
2834 public class OpenApiDocumentTests
2935 {
3036 private const string SampleFolderPath = "V3Tests/Samples/OpenApiDocument/" ;
31- private const string codacyApi = "https://api.codacy.com/api/api-docs/swagger.yaml" ;
32-
3337 private static async Task < T > CloneAsync < T > ( T element ) where T : class , IOpenApiSerializable
3438 {
3539 using var stream = new MemoryStream ( ) ;
@@ -1493,8 +1497,24 @@ public async Task ParseDocumentWithExampleReferencesPasses()
14931497 [ Fact ]
14941498 public async Task ParseDocumentWithNonStandardMIMETypePasses ( )
14951499 {
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 ( ) ;
14961516 // 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 ) ;
14981518 Assert . NotNull ( result . Document ) ;
14991519 }
15001520 }
0 commit comments