public void CanConnectTwice() { using (var device = new TestDevice(0)) { device.Connect(); device.Connect(); Assert.AreEqual(ConnectionState.Connected, device.State); Assert.AreEqual(1, device.ConnectionAttempts); } }
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); } }
public void AbortIfConnectionFails() { using (var device = new TestDevice(Int32.MaxValue)) { device.Connect(); } }
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); } }
public void CanMonitorConnectionStatus() { using (var device = new TestDevice(0)) { int numberOfChanges = 0; device.StateChanged += (s, e) => ++ numberOfChanges; device.Connect(); Assert.IsTrue(numberOfChanges > 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)); } }
public void ErrorStateIfConnectionFails() { using (var device = new TestDevice(Int32.MaxValue)) { try { device.Connect(); } catch (HardwareException) { } Assert.AreEqual(ConnectionState.Error, device.State); } }