/// <summary> /// Sets the loading item. /// </summary> /// <returns>SystemVariable.</returns> private SystemVariable SetLoadingItem() { var item = new SystemVariable("Loading ...", "loading", null); if (this.SystemVariables.Any(x => x.Value == "loading" && x.CompatibleTypes == null)) { this.selectedSystemVariable = item; return item; } this.SystemVariables.Insert(0, item); this.SelectedSystemVariable = item; return item; }
/// <summary> /// Adds the system parameters. /// </summary> private void AddSystemParameters() { if (!ShowSystemParameters) return; SetLoadingItem(); IsSystemParameterVisibile = false; SystemParametersList.BeginGetSystemParameterList( (o, e) => { if (e.Error != null) return; IsSystemParameterVisibile = true; var newParameters = e.Object; for (var i = SystemVariables.Count - 1; i >= 0; --i) { var variable = SystemVariables[i]; if (variable.IsSystemParametr) { var parameter = newParameters.FirstOrDefault(p => p.SystemName == variable.Value); if (parameter == null || GetParameterType(parameter.Type) == null) SystemVariables.RemoveAt(i); } } foreach (var parameter in newParameters) { var compatibleTypes = GetParameterType(parameter.Type); if (compatibleTypes == null) continue; var caption = parameter.Name; var value = parameter.SystemName; var variable = SystemVariables.FirstOrDefault(v => v.IsSystemParametr && v.Value == value); if (variable == null) { variable = new SystemVariable(caption, value, compatibleTypes, true); SystemVariables.Add(variable); } else { variable.Caption = caption; variable.CompatibleTypes = compatibleTypes; } } SelectedSystemVariable = SystemVariables.FirstOrDefault(x => x.Value == SelectedSystemParameters); RaisePropertyChanged(() => SelectedSystemVariable); ShowSystemParameters = ShowSystemParameters && FilteredSystemVariables.View.OfType<object>().Any(); }); }
public void FilterOptionsCommandShouldUpdatSystemVaribleAfterPopupIsClosed() { var filter = Mock.Create<IFilterDescriptor>(Behavior.Loose); var stepEdit = DisplayListRequiredStepEdit.NewStep(1); stepEdit.SelectedFields = new DisplayListStepFields(); var processFieldViewModel = new ProcessFieldViewModel(new FieldEdit(), new ProcessSectionViewModel(Mock.Create<ISectionEdit>())); var vm = new ProcessFieldDisplayListRequiredStepViewModel(stepEdit, new StepInfo(1), processFieldViewModel); Mock.Arrange(() => vm.GetProcessedFilter()).IgnoreInstance().Returns(Mock.Create<IFilterDescriptor>()); var processEdit = Mock.Create<ProcessEdit>(Behavior.Loose); var fieldsViewModel = new ProcessFieldsViewModel { Model = processEdit }; vm.Model = fieldsViewModel; var popupFactory = Mock.Create<PopupFactory>(Behavior.Loose); var popupBuilder = Mock.Create<PopupBuilder>(Behavior.CallOriginal); Mock.Arrange(() => popupFactory.Popup()).Returns(popupBuilder); Mock.Arrange(() => popupBuilder.Show(Arg.IsAny<Action>(), Arg.IsAny<Func<bool>>())).DoInstead((Action ok, Action cancel) => ok()); vm.ThePopupFactory = popupFactory; var filterOptions = Mock.Create<FilterOptionsViewModel>(Behavior.Loose); vm.FilterOptionsVM = new Lazy<FilterOptionsViewModel>(() => filterOptions); var sysParam = new SystemVariable("test", "test", new List<Type>()); filterOptions.IsSystemVariable = true; filterOptions.SelectedSystemVariable = sysParam; var filterValue = new FilterValue { Type = FilterValueType.SystemVariable }; Mock.Arrange(() => filter.Value).Returns(filterValue); vm.FilterOptionsCommand.Execute(filter); Assert.AreEqual("SYS: test", filterValue.ProvidedValue.ToString()); Mock.Arrange(() => filter.Value).Returns((FilterValue)null); vm.FilterOptionsCommand.Execute(filter); Mock.AssertSet(() => filter.Value = Arg.IsAny<FilterValue>()); }