@@ -523,5 +523,95 @@ private static IPAddress GetFirstActiveNic()
523523
524524 return null ;
525525 }
526+
527+ [ Test ( Description = "Validate UDP client socket access before connection is started" ) ]
528+ public void ValidateUdpPubSubConnectionSocketAccessBeforeStart ( )
529+ {
530+ // Arrange
531+ Assert . IsNotNull (
532+ m_udpPublisherConnection ,
533+ "The UADP connection from standard configuration is invalid." ) ;
534+
535+ // Act - Access clients before connection is started
536+ IReadOnlyList < UdpClient > publisherClients = m_udpPublisherConnection . PublisherUdpClients ;
537+ IReadOnlyList < UdpClient > subscriberClients = m_udpPublisherConnection . SubscriberUdpClients ;
538+
539+ // Assert - Should return empty lists before connection is started
540+ Assert . IsNotNull ( publisherClients , "PublisherUdpClients should not be null" ) ;
541+ Assert . IsNotNull ( subscriberClients , "SubscriberUdpClients should not be null" ) ;
542+ Assert . AreEqual ( 0 , publisherClients . Count , "PublisherUdpClients should be empty before start" ) ;
543+ Assert . AreEqual ( 0 , subscriberClients . Count , "SubscriberUdpClients should be empty before start" ) ;
544+ }
545+
546+ [ Test ( Description = "Validate UDP client socket access after connection is started" ) ]
547+ public void ValidateUdpPubSubConnectionSocketAccessAfterStart ( )
548+ {
549+ // Arrange
550+ Assert . IsNotNull (
551+ m_udpPublisherConnection ,
552+ "The UADP connection from standard configuration is invalid." ) ;
553+
554+ // Act - Start the connection
555+ m_udpPublisherConnection . Start ( ) ;
556+
557+ try
558+ {
559+ // Access clients after connection is started
560+ IReadOnlyList < UdpClient > publisherClients = m_udpPublisherConnection . PublisherUdpClients ;
561+ IReadOnlyList < UdpClient > subscriberClients = m_udpPublisherConnection . SubscriberUdpClients ;
562+
563+ // Assert - Should have clients after connection is started
564+ Assert . IsNotNull ( publisherClients , "PublisherUdpClients should not be null" ) ;
565+ Assert . IsNotNull ( subscriberClients , "SubscriberUdpClients should not be null" ) ;
566+
567+ // Publisher should have clients since there are publishers configured
568+ if ( m_udpPublisherConnection . Publishers . Count > 0 )
569+ {
570+ Assert . Greater ( publisherClients . Count , 0 , "PublisherUdpClients should not be empty when publishers exist" ) ;
571+
572+ // Verify we can access the underlying socket
573+ foreach ( UdpClient client in publisherClients )
574+ {
575+ Assert . IsNotNull ( client , "UDP client should not be null" ) ;
576+ Assert . IsNotNull ( client . Client , "UDP client Socket should not be null" ) ;
577+
578+ // Verify we can read socket properties (e.g., ReceiveBufferSize)
579+ int receiveBufferSize = client . Client . ReceiveBufferSize ;
580+ Assert . Greater ( receiveBufferSize , 0 , "ReceiveBufferSize should be greater than 0" ) ;
581+
582+ m_logger . LogInformation (
583+ "Publisher UDP Socket - ReceiveBufferSize: {Size}, LocalEndPoint: {Endpoint}" ,
584+ receiveBufferSize ,
585+ client . Client . LocalEndPoint ) ;
586+ }
587+ }
588+ }
589+ finally
590+ {
591+ // Cleanup - Stop the connection
592+ m_udpPublisherConnection . Stop ( ) ;
593+ }
594+ }
595+
596+ [ Test ( Description = "Validate that UDP client list is read-only" ) ]
597+ public void ValidateUdpPubSubConnectionSocketListIsReadOnly ( )
598+ {
599+ // Arrange
600+ Assert . IsNotNull (
601+ m_udpPublisherConnection ,
602+ "The UADP connection from standard configuration is invalid." ) ;
603+
604+ // Act
605+ IReadOnlyList < UdpClient > publisherClients = m_udpPublisherConnection . PublisherUdpClients ;
606+ IReadOnlyList < UdpClient > subscriberClients = m_udpPublisherConnection . SubscriberUdpClients ;
607+
608+ // Assert - The returned collections should be read-only
609+ Assert . IsNotNull ( publisherClients , "PublisherUdpClients should not be null" ) ;
610+ Assert . IsNotNull ( subscriberClients , "SubscriberUdpClients should not be null" ) ;
611+
612+ // Verify that the collections are truly read-only (no Add/Remove methods exposed)
613+ Assert . IsInstanceOf < IReadOnlyList < UdpClient > > ( publisherClients , "PublisherUdpClients should be IReadOnlyList" ) ;
614+ Assert . IsInstanceOf < IReadOnlyList < UdpClient > > ( subscriberClients , "SubscriberUdpClients should be IReadOnlyList" ) ;
615+ }
526616 }
527617}
0 commit comments