Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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));
        }