Exemplo n.º 1
0
        public void CanConnectTwice()
        {
            using (var device = new TestDevice(0))
            {
                device.Connect();
                device.Connect();

                Assert.AreEqual(ConnectionState.Connected, device.State);
                Assert.AreEqual(1, device.ConnectionAttempts);
            }
        }
Exemplo n.º 2
0
        public void CanOpenAndCloseConnection()
        {
            using (var device = new TestDevice(0))
            {
                device.Connect();
                Assert.AreEqual(ConnectionState.Connected, device.State);
                Assert.AreEqual(1, device.ConnectionAttempts);

                device.Disconnect();
                Assert.AreEqual(ConnectionState.Disconnected, device.State);

                device.Connect();
                Assert.AreEqual(ConnectionState.Connected, device.State);
                Assert.AreEqual(2, device.ConnectionAttempts);
            }
        }
Exemplo n.º 3
0
 public void AbortIfConnectionFails()
 {
     using (var device = new TestDevice(Int32.MaxValue))
     {
         device.Connect();
     }
 }
Exemplo n.º 4
0
        public void CanReconnectAfterError()
        {
            using (var device = new TestDevice(Int32.MaxValue))
            {
                try
                {
                    device.Connect();
                }
                catch (HardwareException)
                {
                }

                Assert.AreEqual(ConnectionState.Error, device.State);

                device.NumberOfConnectionsToFail = 0;
                device.Connect();
                Assert.AreEqual(ConnectionState.Connected, device.State);
            }
        }
Exemplo n.º 5
0
        public void CanMonitorConnectionStatus()
        {
            using (var device = new TestDevice(0))
            {
                int numberOfChanges = 0;

                device.StateChanged += (s, e) => ++ numberOfChanges;
                device.Connect();

                Assert.IsTrue(numberOfChanges > 0);
            }
        }
Exemplo n.º 6
0
        public void RetryConnectionIfFails()
        {
            using (var device = new TestDevice(2))
            {
                var start = DateTime.UtcNow;

                device.Connect();

                Assert.AreEqual(ConnectionState.Connected, device.State);
                Assert.AreEqual(3, device.ConnectionAttempts); // 2 failed + 1 successful

                // At least one second elapsed because of delay between each attempt
                Assert.IsTrue(DateTime.UtcNow - start > TimeSpan.FromSeconds(1));
            }
        }
Exemplo n.º 7
0
        public void ErrorStateIfConnectionFails()
        {
            using (var device = new TestDevice(Int32.MaxValue))
            {
                try
                {
                    device.Connect();
                }
                catch (HardwareException)
                {
                }

                Assert.AreEqual(ConnectionState.Error, device.State);
            }
        }