Example #1
0
        public async Task <ActionResult> EditRuleProperties(string deviceId, string ruleId)
        {
            EditDeviceRuleModel editModel = null;

            //empty ruleId implies that we are creating new
            if (string.IsNullOrWhiteSpace(ruleId))
            {
                bool canCreate = await _deviceRulesLogic.CanNewRuleBeCreatedForDeviceAsync(deviceId);

                if (!canCreate)
                {
                    editModel = new EditDeviceRuleModel()
                    {
                        DeviceID = deviceId
                    };
                    return(View("AllRulesAssigned", editModel));
                }
            }

            DeviceRule ruleModel = await _deviceRulesLogic.GetDeviceRuleOrDefaultAsync(deviceId, ruleId);

            Dictionary <string, List <string> > availableFields = await _deviceRulesLogic.GetAvailableFieldsForDeviceRuleAsync(ruleModel.DeviceID, ruleModel.RuleId);

            List <SelectListItem> availableDataFields  = this.ConvertStringListToSelectList(availableFields["availableDataFields"]);
            List <SelectListItem> availableOperators   = this.ConvertStringListToSelectList(availableFields["availableOperators"]);
            List <SelectListItem> availableRuleOutputs = this.ConvertStringListToSelectList(availableFields["availableRuleOutputs"]);

            editModel = CreateEditModelFromDeviceRule(ruleModel);
            editModel.AvailableDataFields  = availableDataFields;
            editModel.AvailableOperators   = availableOperators;
            editModel.AvailableRuleOutputs = availableRuleOutputs;

            return(View("EditDeviceRuleProperties", editModel));
        }
        public async void GetDeviceRuleOrDefaultAsyncTest()
        {
            var deviceId = fixture.Create <string>();
            var rules    = fixture.Create <List <DeviceRule> >();

            rules.ForEach(x => x.DeviceID = deviceId);
            _deviceRulesRepositoryMock.Setup(x => x.GetAllRulesForDeviceAsync(deviceId)).ReturnsAsync(rules);

            var ret = await deviceRulesLogic.GetDeviceRuleOrDefaultAsync(deviceId, rules[0].RuleId);

            Assert.Equal(rules[0], ret);

            ret = await deviceRulesLogic.GetDeviceRuleOrDefaultAsync(deviceId, "RuleNotPresent");

            Assert.NotNull(ret);
            Assert.Equal(deviceId, ret.DeviceID);
        }
Example #3
0
 public async Task <HttpResponseMessage> GetDeviceRuleOrDefaultAsync(string deviceId, string ruleId)
 {
     return(await GetServiceResponseAsync(async() => await _deviceRulesLogic.GetDeviceRuleOrDefaultAsync(deviceId, ruleId)));
 }