Exemple #1
0
        public async void ConnectAsyncCallsSocketConnectWithDefaultParams()
        {
            var ip         = "1.1.1.1";
            var socketMock = new Mock <ISocketAdapter>();
            var loggerMock = new Mock <ILogger>();
            var client     = new MqttClient(socketMock.Object, loggerMock.Object, SocketEncryption.None);
            var bldr       = new MqttConnectMessageBuilder
            {
                ClientId         = "UnitTest",
                CleanSession     = true,
                Duplicate        = false,
                KeepAliveTime    = 15,
                UserName         = "******",
                Password         = "******",
                QualityOfService = QualityOfService.ExactlyOnce
            };

            await client.ConnectWithMessageAsync(bldr, ip);

            socketMock.Verify(socket => socket.ConnectAsync(
                                  It.Is <string>(s => s.Equals(ip)),
                                  It.Is <int>(i => i == MqttProtocolInformation.Settings.Port), // Called with default port?
                                  It.Is <SocketEventArgs>(a => a != null)
                                  ),
                              Times.Once());
        }
Exemple #2
0
        public async void ConnectAsyncCallsSocketConnetWithGivenParams()
        {
            var ip         = "1.1.1.1";
            var port       = 1883;
            var socketMock = new Mock <ISocketAdapter>();
            var loggerMock = new Mock <ILogger>();
            var client     = new MqttClient(socketMock.Object, loggerMock.Object, SocketEncryption.None);
            var bldr       = new MqttConnectMessageBuilder
            {
                ClientId = "UnitTest"
            };

            await client.ConnectWithMessageAsync(bldr, ip, port);

            socketMock.Verify(socket => socket.ConnectAsync(
                                  It.Is <string>(s => s.Equals(ip)), // Called with passed in IP address?
                                  It.Is <int>(i => i == port),       // Called with passed in port?
                                  It.Is <SocketEventArgs>(a => a != null)
                                  ),
                              Times.Once());        // Called once and only once
        }