1- // filepath: c:\Users\ddelimarsky\source\csharp-sdk\tests\ModelContextProtocol.Tests\Protocol\Auth\ProtectedResourceMetadataTests.cs
21using ModelContextProtocol . Protocol . Auth ;
2+ using ModelContextProtocol . Utils . Json ;
3+ using System ;
34using System . Text . Json ;
5+ using Xunit ;
46
57namespace ModelContextProtocol . Tests . Protocol . Auth ;
68
@@ -25,15 +27,15 @@ public void ProtectedResourceMetadata_JsonSerialization_Works()
2527
2628 // Assert
2729 Assert . NotNull ( deserialized ) ;
28- Assert . Equal ( "http://localhost:7071" , deserialized . Resource . ToString ( ) ) ;
29- Assert . Equal ( "https://login.microsoftonline.com/tenant/v2.0" , deserialized . AuthorizationServers [ 0 ] . ToString ( ) ) ;
30+ Assert . Equal ( metadata . Resource , deserialized . Resource ) ;
31+ Assert . Equal ( metadata . AuthorizationServers [ 0 ] , deserialized . AuthorizationServers [ 0 ] ) ;
3032 Assert . Equal ( "header" , deserialized . BearerMethodsSupported ! [ 0 ] ) ;
3133 Assert . Equal ( 2 , deserialized . ScopesSupported ! . Length ) ;
3234 Assert . Contains ( "mcp.tools" , deserialized . ScopesSupported ! ) ;
3335 Assert . Contains ( "mcp.prompts" , deserialized . ScopesSupported ! ) ;
34- Assert . Equal ( "https://example.com/docs" , deserialized . ResourceDocumentation ! . ToString ( ) ) ;
36+ Assert . Equal ( metadata . ResourceDocumentation , deserialized . ResourceDocumentation ) ;
3537 }
36-
38+
3739 [ Fact ]
3840 public void ProtectedResourceMetadata_JsonDeserialization_WorksWithStringProperties ( )
3941 {
@@ -51,40 +53,12 @@ public void ProtectedResourceMetadata_JsonDeserialization_WorksWithStringPropert
5153
5254 // Assert
5355 Assert . NotNull ( deserialized ) ;
54- Assert . Equal ( "http://localhost:7071" , deserialized . Resource . ToString ( ) ) ;
55- Assert . Equal ( "https://login.microsoftonline.com/tenant/v2.0" , deserialized . AuthorizationServers [ 0 ] . ToString ( ) ) ;
56- Assert . Equal ( "header" , deserialized . BearerMethodsSupported ! [ 0 ] ) ;
57- Assert . Equal ( 2 , deserialized . ScopesSupported ! . Length ) ;
58- Assert . Contains ( "mcp.tools" , deserialized . ScopesSupported ! ) ;
59- Assert . Contains ( "mcp.prompts" , deserialized . ScopesSupported ! ) ;
60- Assert . Equal ( "https://example.com/docs" , deserialized . ResourceDocumentation ! . ToString ( ) ) ;
61- }
62-
63- [ Fact ]
64- public void ResourceMetadata_JsonSerialization_Works ( )
65- {
66- // Arrange
67- var metadata = new ProtectedResourceMetadata
68- {
69- Resource = new Uri ( "http://localhost:7071" ) ,
70- AuthorizationServers = [ new Uri ( "https://login.microsoftonline.com/tenant/v2.0" ) ] ,
71- BearerMethodsSupported = [ "header" ] ,
72- ScopesSupported = [ "mcp.tools" , "mcp.prompts" ] ,
73- ResourceDocumentation = new Uri ( "https://example.com/docs" )
74- } ;
75-
76- // Act
77- var json = JsonSerializer . Serialize ( metadata ) ;
78- var deserialized = JsonSerializer . Deserialize < ProtectedResourceMetadata > ( json ) ;
79-
80- // Assert
81- Assert . NotNull ( deserialized ) ;
82- Assert . Equal ( "http://localhost:7071" , deserialized . Resource . ToString ( ) ) ;
83- Assert . Equal ( "https://login.microsoftonline.com/tenant/v2.0" , deserialized . AuthorizationServers [ 0 ] . ToString ( ) ) ;
56+ Assert . Equal ( new Uri ( "http://localhost:7071" ) , deserialized . Resource ) ;
57+ Assert . Equal ( new Uri ( "https://login.microsoftonline.com/tenant/v2.0" ) , deserialized . AuthorizationServers [ 0 ] ) ;
8458 Assert . Equal ( "header" , deserialized . BearerMethodsSupported ! [ 0 ] ) ;
8559 Assert . Equal ( 2 , deserialized . ScopesSupported ! . Length ) ;
8660 Assert . Contains ( "mcp.tools" , deserialized . ScopesSupported ! ) ;
8761 Assert . Contains ( "mcp.prompts" , deserialized . ScopesSupported ! ) ;
88- Assert . Equal ( "https://example.com/docs" , deserialized . ResourceDocumentation ! . ToString ( ) ) ;
62+ Assert . Equal ( new Uri ( "https://example.com/docs" ) , deserialized . ResourceDocumentation ) ;
8963 }
9064}
0 commit comments