6
6
using System . Collections . Generic ;
7
7
using System . Diagnostics ;
8
8
using System . Linq ;
9
+ using System . Net ;
9
10
using System . Net . Sockets ;
10
11
using System . Text ;
11
12
using System . Threading ;
@@ -86,7 +87,7 @@ public async Task Connect_Disconnect_Connect()
86
87
await client . ConnectAsync ( clientOptions ) ;
87
88
}
88
89
}
89
-
90
+
90
91
[ TestMethod ]
91
92
[ ExpectedException ( typeof ( InvalidOperationException ) ) ]
92
93
public async Task Connect_Multiple_Times_Should_Fail ( )
@@ -748,8 +749,8 @@ public async Task Send_Reply_In_Message_Handler()
748
749
{
749
750
if ( e . ApplicationMessage . Topic == "request" )
750
751
{
751
- // Use AtMostOnce here because with QoS 1 or even QoS 2 the process waits for
752
- // the ACK etc. The problem is that the SpinUntil below only waits until the
752
+ // Use AtMostOnce here because with QoS 1 or even QoS 2 the process waits for
753
+ // the ACK etc. The problem is that the SpinUntil below only waits until the
753
754
// flag is set. It does not wait until the client has sent the ACK
754
755
await client2 . PublishStringAsync ( "reply" ) ;
755
756
}
@@ -925,5 +926,54 @@ public async Task Subscribe_With_QoS2()
925
926
Assert . IsFalse ( disconnectedFired ) ;
926
927
}
927
928
}
929
+
930
+ [ TestMethod ]
931
+ public void Backward_compatible_TCP_options ( )
932
+ {
933
+ var options = new MqttClientOptionsBuilder ( ) . WithTcpServer ( "host" , 3 ) . Build ( ) ;
934
+
935
+ Assert . AreEqual ( "host" , ( ( MqttClientTcpOptions ) options . ChannelOptions ) . Server ) ;
936
+ Assert . AreEqual ( 3 , ( ( MqttClientTcpOptions ) options . ChannelOptions ) . Port ) ;
937
+
938
+ options = new MqttClientOptions
939
+ {
940
+ ChannelOptions = new MqttClientTcpOptions
941
+ {
942
+ Server = "host" ,
943
+ Port = 3
944
+ }
945
+ } ;
946
+
947
+ Assert . AreEqual ( "host:3" , options . ChannelOptions . ToString ( ) ) ;
948
+ Assert . AreEqual ( "host" , ( ( MqttClientTcpOptions ) options . ChannelOptions ) . Server ) ;
949
+ Assert . AreEqual ( 3 , ( ( MqttClientTcpOptions ) options . ChannelOptions ) . Port ) ;
950
+
951
+ options = new MqttClientOptionsBuilder ( ) . WithEndPoint ( new DnsEndPoint ( "host" , 3 ) ) . Build ( ) ;
952
+ Assert . AreEqual ( "Unspecified/host:3" , options . ChannelOptions . ToString ( ) ) ;
953
+ Assert . AreEqual ( "host" , ( ( MqttClientTcpOptions ) options . ChannelOptions ) . Server ) ;
954
+ Assert . AreEqual ( 3 , ( ( MqttClientTcpOptions ) options . ChannelOptions ) . Port ) ;
955
+
956
+ options = new MqttClientOptionsBuilder ( ) . WithTcpServer ( "host" ) . Build ( ) ;
957
+
958
+ Assert . AreEqual ( "host" , ( ( MqttClientTcpOptions ) options . ChannelOptions ) . Server ) ;
959
+ Assert . AreEqual ( 1883 , ( ( MqttClientTcpOptions ) options . ChannelOptions ) . Port ) ;
960
+ Assert . AreEqual ( "Unspecified/host:1883" , options . ChannelOptions . ToString ( ) ) ;
961
+
962
+ options = new MqttClientOptionsBuilder ( ) . WithTlsOptions ( o => o . UseTls ( ) ) . WithTcpServer ( "host" ) . Build ( ) ;
963
+
964
+ Assert . AreEqual ( "host" , ( ( MqttClientTcpOptions ) options . ChannelOptions ) . Server ) ;
965
+ Assert . AreEqual ( 8883 , ( ( MqttClientTcpOptions ) options . ChannelOptions ) . Port ) ;
966
+
967
+ options = new MqttClientOptions
968
+ {
969
+ ChannelOptions = new MqttClientTcpOptions
970
+ {
971
+ Server = "host"
972
+ }
973
+ } ;
974
+
975
+ Assert . AreEqual ( "host" , ( ( MqttClientTcpOptions ) options . ChannelOptions ) . Server ) ;
976
+ Assert . AreEqual ( null , ( ( MqttClientTcpOptions ) options . ChannelOptions ) . Port ) ;
977
+ }
928
978
}
929
979
}
0 commit comments