public async void Test_ConsecutiveDisableEvents_AreOk() { var config = new SwitchToSensorBinding { SwitchId = SwitchId.NewId(), SensorId = SensorId.NewId() }; IReadOnlyCollection <SwitchToSensorBinding> configCollection = new [] { config }; var bindingsRepoMock = new Mock <ISwitchToSensorBindingsRepository>(MockBehavior.Strict); bindingsRepoMock.Setup(m => m.GetAll()).Returns(Task.FromResult(configCollection)); var handler = new BindingController(Mock.Of <IEventSender>(), bindingsRepoMock.Object); await handler.DisableBinding(config.SwitchId, config.SensorId); await handler.DisableBinding(config.SwitchId, config.SensorId); }
public async void TestBindingEnabledByDefault_TurnOn() { var config = new SwitchToSensorBinding { SwitchId = SwitchId.NewId(), SensorId = SensorId.NewId() }; IReadOnlyCollection <SwitchToSensorBinding> configCollection = new [] { config }; var bindingsRepoMock = new Mock <ISwitchToSensorBindingsRepository>(MockBehavior.Strict); bindingsRepoMock.Setup(m => m.GetAll()).Returns(Task.FromResult(configCollection)); var publisherMock = new Mock <IEventSender>(MockBehavior.Strict); publisherMock.Setup(m => m.SendEvent(It.Is <TurnOnEvent>(e => e.SwitchId == config.SwitchId))); var handler = new BindingController(publisherMock.Object, bindingsRepoMock.Object); await handler.ProcessSensorActivation(config.SensorId); publisherMock.Verify(m => m.SendEvent(It.IsAny <TurnOnEvent>()), Times.Once); }
public async void TestWhenBindingDeactivated_DoNothing() { var config = new SwitchToSensorBinding { SwitchId = SwitchId.NewId(), SensorId = SensorId.NewId() }; IReadOnlyCollection <SwitchToSensorBinding> configCollection = new [] { config }; var bindingsRepoMock = new Mock <ISwitchToSensorBindingsRepository>(MockBehavior.Strict); bindingsRepoMock.Setup(m => m.GetAll()).Returns(Task.FromResult(configCollection)); var publisherMock = new Mock <IEventSender>(MockBehavior.Strict); var handler = new BindingController(publisherMock.Object, bindingsRepoMock.Object); await handler.DisableBinding(config.SwitchId, config.SensorId); await handler.ProcessSensorActivation(config.SensorId); await handler.ProcessSensorDeactivation(config.SensorId); publisherMock.Verify(m => m.SendEvent(It.IsAny <IEvent>()), Times.Never); }
public async void TestWhenSensorBindToMultipleSwitches_ThenTurnOffThemAll() { var sensorId = SensorId.NewId(); var config1 = new SwitchToSensorBinding { SwitchId = SwitchId.NewId(), SensorId = sensorId }; var config2 = new SwitchToSensorBinding { SwitchId = SwitchId.NewId(), SensorId = sensorId }; IReadOnlyCollection <SwitchToSensorBinding> configCollection = new [] { config1, config2 }; var bindingsRepoMock = new Mock <ISwitchToSensorBindingsRepository>(MockBehavior.Strict); bindingsRepoMock.Setup(m => m.GetAll()).Returns(Task.FromResult(configCollection)); var publisherMock = new Mock <IEventSender>(MockBehavior.Strict); publisherMock.Setup(m => m.SendEvent(It.Is <TurnOffEvent>(e => e.SwitchId == config1.SwitchId))); publisherMock.Setup(m => m.SendEvent(It.Is <TurnOffEvent>(e => e.SwitchId == config2.SwitchId))); var handler = new BindingController(publisherMock.Object, bindingsRepoMock.Object); await handler.ProcessSensorDeactivation(sensorId); publisherMock.Verify(m => m.SendEvent(It.IsAny <TurnOffEvent>()), Times.Exactly(2)); }