Beispiel #1
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);
        }
Beispiel #2
0
        public async void TestWnehUnknownSensor_ThenDoNothing()
        {
            IReadOnlyCollection <SwitchToSensorBinding> config = new []
            {
                new SwitchToSensorBinding {
                    SwitchId = SwitchId.NewId(), SensorId = SensorId.NewId()
                }
            };
            var bindingsRepoMock = new Mock <ISwitchToSensorBindingsRepository>(MockBehavior.Strict);

            bindingsRepoMock.Setup(m => m.GetAll()).Returns(Task.FromResult(config));
            var publisherMock = new Mock <IEventSender>(MockBehavior.Strict);
            var handler       = new BindingController(publisherMock.Object, bindingsRepoMock.Object);

            await handler.ProcessSensorActivation(SensorId.NewId());

            await handler.ProcessSensorDeactivation(SensorId.NewId());

            publisherMock.Verify(m => m.SendEvent(It.IsAny <IEvent>()), Times.Never);
        }
Beispiel #3
0
        public async void TestWhenSensorBindToMultipleSwitches_ThenTurnOnThemAll()
        {
            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 <TurnOnEvent>(e => e.SwitchId == config1.SwitchId)));
            publisherMock.Setup(m => m.SendEvent(It.Is <TurnOnEvent>(e => e.SwitchId == config2.SwitchId)));
            var handler = new BindingController(publisherMock.Object, bindingsRepoMock.Object);

            await handler.ProcessSensorActivation(sensorId);

            publisherMock.Verify(m => m.SendEvent(It.IsAny <TurnOnEvent>()), Times.Exactly(2));
        }