Beispiel #1
0
        private void _sensorHub_StatusChanged(object sender, StatusChangedEventArgs e)
        {
            string triggeredBy = sender.GetType().Name;

            _stateStore.SetSensorState(e.Socket, triggeredBy, e.Status);

            var condition = _conditionFilter.FilterBySensor(e.Socket, triggeredBy).FirstOrDefault();

            if (condition != null)
            {
                Logger.Information(string.Format("{0} = True", condition));

                turnOnOrOff(e.Socket, condition.ResultingStatus, condition.Text, e.Message, sender);

                var relatedConditions = _conditionFilter.FilterByRelatedSocket(e.Socket);
                if (relatedConditions.Any())
                {
                    foreach (var x in relatedConditions)
                    {
                        Logger.Information(string.Format("{0} = True", x));

                        turnOnOrOff(x.Socket, x.ResultingStatus, x.Text, e.Message, sender);
                    }
                }
            }
        }
        public void FilterByRelatedSocket_NoConditions()
        {
            var stateStore = getStateStore(_socketOne, _socketTwo, new List <ConditionMode>());
            var conditions = getConditions(_socketOne, "Socket(2).IsOff AND SensorOne.PowerOn");

            var filter = new ConditionFilter(stateStore, conditions);
            var result = filter.FilterByRelatedSocket(_socketOne);

            Assert.Empty(result);
        }
        public void FilterByRelatedSocket()
        {
            var stateStore = getStateStore(_socketOne, _socketTwo, new List <ConditionMode>());
            var conditions = getConditions(_socketOne, "Socket(2).IsOn AND SensorFour.PowerOn");

            var filter = new ConditionFilter(stateStore, conditions);
            var result = filter.FilterByRelatedSocket(_socketTwo);
            //Assert.Single(result);
            //Assert.Contains(conditions.First(), result);

            // TODO: gars­tiges Mocking Zeug...
        }