22// Licensed under the MIT License.
33
44using System ;
5- using System . Collections . Generic ;
65using System . Linq ;
76using System . Reflection ;
7+ using System . Collections . Generic ;
88using System . Text . Json ;
99using Azure . Messaging ;
1010using Newtonsoft . Json . Linq ;
@@ -1403,7 +1403,7 @@ public void MediaStreamingFailedEventParsed_Test()
14031403 }
14041404
14051405 [ Test ]
1406- public void IncomingCallEventParsed_Test ( )
1406+ public void IncomingCallEventParsed_XMS_Header_Test ( )
14071407 {
14081408 // arrange
14091409 var to = new CommunicationUserIdentifier ( "8:acs:12345" ) ;
@@ -1413,8 +1413,8 @@ public void IncomingCallEventParsed_Test()
14131413
14141414 Dictionary < string , string > sipHeaders = new Dictionary < string , string > ( ) ;
14151415 Dictionary < string , string > voipHeaders = new Dictionary < string , string > ( ) ;
1416- var customContext = new CustomCallingContext ( voipHeaders , sipHeaders ) ;
1417- customContext . AddSipX ( "Test-SIP-Header" , "TestSIPValue" ) ;
1416+ var customContext = new CustomCallingContext ( sipHeaders , voipHeaders ) ;
1417+ customContext . AddSipX ( "Test-SIP-Header" , "TestSIPValue" , CustomCallingContext . SipHeaderPrefix . XMSCustom ) ;
14181418 customContext . AddVoip ( "Test-VoIP-Header" , "TestVoIPValue" ) ;
14191419
14201420 var incomingCallContext = "incomingCallContext" ;
@@ -1445,6 +1445,72 @@ public void IncomingCallEventParsed_Test()
14451445 Assert . AreEqual ( incomingCallContext , IncomingCall . IncomingCallContext ) ;
14461446 Assert . AreEqual ( onBehalfOfCallee . RawId , IncomingCall . OnBehalfOfCallee . RawId ) ;
14471447 Assert . AreEqual ( correlationId , IncomingCall . CorrelationId ) ;
1448+
1449+ var sipHeaderKey = IncomingCall . CustomContext . SipHeaders . First ( ) . Key ;
1450+ var sipHeaderValue = IncomingCall . CustomContext . SipHeaders . First ( ) . Value ;
1451+ Console . WriteLine ( $ "SIP Header -> Key: { sipHeaderKey } , Value: { sipHeaderValue } ") ;
1452+
1453+ var voipHeaderKey = IncomingCall . CustomContext . VoipHeaders . First ( ) . Key ;
1454+ var voipHeaderValue = IncomingCall . CustomContext . VoipHeaders . First ( ) . Value ;
1455+ Console . WriteLine ( $ "VoIP Header -> Key: { voipHeaderKey } , Value: { voipHeaderValue } ") ;
1456+ }
1457+ else
1458+ {
1459+ Assert . Fail ( "Event parsed wrongfully" ) ;
1460+ }
1461+ }
1462+
1463+ [ Test ]
1464+ public void IncomingCallEventParsed_X_Header_Test ( )
1465+ {
1466+ // arrange
1467+ var to = new CommunicationUserIdentifier ( "8:acs:12345" ) ;
1468+ var from = new CommunicationUserIdentifier ( "8:acs:54321" ) ;
1469+ var callerDisplayName = "callerDisplayName" ;
1470+ var serverCallId = "serverCallId" ;
1471+
1472+ Dictionary < string , string > sipHeaders = new Dictionary < string , string > ( ) ;
1473+ Dictionary < string , string > voipHeaders = new Dictionary < string , string > ( ) ;
1474+ var customContext = new CustomCallingContext ( sipHeaders , voipHeaders ) ;
1475+ customContext . AddSipX ( "Test-SIP-Header" , "TestSIPValue" , CustomCallingContext . SipHeaderPrefix . X ) ;
1476+ customContext . AddVoip ( "Test-VoIP-Header" , "TestVoIPValue" ) ;
1477+
1478+ var incomingCallContext = "incomingCallContext" ;
1479+ var onBehalfOfCallee = from ;
1480+ var correlationId = "correlationId" ;
1481+ var @event = CallAutomationModelFactory . IncomingCall ( to , from , callerDisplayName , serverCallId , customContext , incomingCallContext , onBehalfOfCallee , correlationId ) ;
1482+
1483+ JsonSerializerOptions jsonOptions = new ( ) { PropertyNamingPolicy = JsonNamingPolicy . CamelCase } ;
1484+ string jsonEvent = JsonSerializer . Serialize ( @event , jsonOptions ) ;
1485+
1486+ // act
1487+ var parsedEvent = CallAutomationEventParser . Parse ( jsonEvent , "Microsoft.Communication.IncomingCall" ) ;
1488+ var IncomingCall = ( IncomingCall ) parsedEvent ;
1489+
1490+ // assert
1491+ if ( parsedEvent is IncomingCall )
1492+ {
1493+ Assert . AreEqual ( to . RawId , IncomingCall . To . RawId ) ;
1494+ Assert . AreEqual ( from . RawId , IncomingCall . From . RawId ) ;
1495+ Assert . AreEqual ( callerDisplayName , IncomingCall . CallerDisplayName ) ;
1496+ Assert . AreEqual ( serverCallId , IncomingCall . ServerCallId ) ;
1497+
1498+ Assert . AreEqual ( customContext . SipHeaders . First ( ) . Key , IncomingCall . CustomContext . SipHeaders . First ( ) . Key ) ;
1499+ Assert . AreEqual ( customContext . SipHeaders . First ( ) . Value , IncomingCall . CustomContext . SipHeaders . First ( ) . Value ) ;
1500+ Assert . AreEqual ( customContext . VoipHeaders . First ( ) . Key , IncomingCall . CustomContext . VoipHeaders . First ( ) . Key ) ;
1501+ Assert . AreEqual ( customContext . VoipHeaders . First ( ) . Value , IncomingCall . CustomContext . VoipHeaders . First ( ) . Value ) ;
1502+
1503+ Assert . AreEqual ( incomingCallContext , IncomingCall . IncomingCallContext ) ;
1504+ Assert . AreEqual ( onBehalfOfCallee . RawId , IncomingCall . OnBehalfOfCallee . RawId ) ;
1505+ Assert . AreEqual ( correlationId , IncomingCall . CorrelationId ) ;
1506+
1507+ var sipHeaderKey = IncomingCall . CustomContext . SipHeaders . First ( ) . Key ;
1508+ var sipHeaderValue = IncomingCall . CustomContext . SipHeaders . First ( ) . Value ;
1509+ Console . WriteLine ( $ "SIP Header -> Key: { sipHeaderKey } , Value: { sipHeaderValue } ") ;
1510+
1511+ var voipHeaderKey = IncomingCall . CustomContext . VoipHeaders . First ( ) . Key ;
1512+ var voipHeaderValue = IncomingCall . CustomContext . VoipHeaders . First ( ) . Value ;
1513+ Console . WriteLine ( $ "VoIP Header -> Key: { voipHeaderKey } , Value: { voipHeaderValue } ") ;
14481514 }
14491515 else
14501516 {
0 commit comments