public virtual void Initialize(ChecklistSingleViewModel parentVM, IFieldDefinitionEntity fieldDef, IEventAggregator eventAggregator) { _eventAggregator = eventAggregator; _process = (TemplateEntity)parentVM.QuestionsTemplate; _parentVM = parentVM; _fieldDefinition = fieldDef; ChangeChartTypeCommand = new DelegateCommand(ExecuteChange); PrepareFieldDefRelatedData(); var weakListener = new WeakEventListener<SPCChartControlViewModel, ChecklistViewModelBase, EventArgs>(this, parentVM); parentVM.SelectesQuestionChanged += weakListener.OnEvent; weakListener.OnEventAction = OnSelectedQuestionChanged; weakListener.OnDetachAction = (listener, source) => { source.SelectesQuestionChanged -= listener.OnEvent; }; ShowLCLAnyChart = true; ShowUCLAnyChart = true; ShowMeanAnyChart = true; ShowLCLRangeChart = true; ShowUCLRangeChart = true; ShowMeanRangeChart = true; ShowUSL = false; ShowLSL = false; OnSelectedQuestionChanged(this, parentVM, EventArgs.Empty); }
public void WhenRemoveSelectedQuestion_NextQuestionMustBeSelected() { #region Arrange var answerDetails = new List<EditableRootWithDisplayValue>(); for (var i = 0; i < 5; i++) { var detailsVmMock = Mock.Create<IDetailsViewModel>(); Mock.Arrange(() => detailsVmMock.Model).Returns(Mock.Create<IEditableRoot>()); var item = new EditableRootWithDisplayValue(); item.Initialize(string.Format("property{0}", i), false, null); item.TheEventAggregator = new Lazy<IEventAggregator>(Mock.Create<IEventAggregator>); answerDetails.Add(item); } var vm = new ChecklistSingleViewModel { CanDeleteItem = true, }; var answers = vm.AnswerDetailsSource; foreach (var item in answerDetails) { answers.Add(item); } vm.Init(Mock.Create<IEditableRoot>(), null, null); var checkList = Mock.Create<ChecklistEdit>(); Mock.Arrange(() => checkList.AnswerProcessList).Returns(Mock.Create<IEditList>()); vm.Checklist = checkList; vm.SelectedAnswerDetails = answerDetails[0]; #endregion Arrange //Act: remove 0th element (remain elements: 1 2 3 4) vm.RemoveQuestionCommand.Execute(null); //Assert Assert.IsTrue(answers.FirstOrDefault(x => x.Equals(vm.SelectedAnswerDetails)).Display.Contains("1")); //Act: remove 2th element (remain elements: 1 3 4) vm.SelectedAnswerDetails = answers.First(x => x.Display.Contains("2")); vm.RemoveQuestionCommand.Execute(null); //Assert Assert.IsTrue(answers.FirstOrDefault(x => x.Equals(vm.SelectedAnswerDetails)).Display.Contains("3")); //Act: remove last element (remain elements: 1 3) vm.SelectedAnswerDetails = answers.Last(); vm.RemoveQuestionCommand.Execute(null); //Assert Assert.IsTrue(answers.FirstOrDefault(x => x.Equals(vm.SelectedAnswerDetails)).Display.Contains("3")); }