public void WithChange_ShouldStoreChange() { KeyValueChange change = RandomKeyValueChange(); MasterDetailViewModel viewModel = CreateMasterDetailViewModel(); viewModel.KeyValueChanged(change); viewModel.Changes.Should().ContainSingle(c => Equals(c, change)); }
/// <summary> /// Initializes a new <see cref="KeyValueUnitViewModel"/>. /// </summary> /// <param name="parentViewModel">The parent view model</param> /// <param name="tag">The tag providing the data.</param> public KeyValueUnitViewModel(MasterDetailViewModel parentViewModel, Tag tag) : this() { _parentViewModel = parentViewModel; _children = new BindableCollection <KeyValueUnitViewModel>(tag.Children.Select(t => new KeyValueUnitViewModel(parentViewModel, t))); _tag = tag; _pendingChange = null; }
public void OnViewModelWithChange_ShouldClearChanges() { KeyValueChange change = RandomKeyValueChange(); MasterDetailViewModel viewModel = CreateMasterDetailViewModel(); viewModel.KeyValueChanged(change); viewModel.Save(); viewModel.Changes.Should().BeEmpty(); }
public void OnViewModelWithChange_ShouldSaveChangeOnCommander() { KeyValueChange change = RandomKeyValueChange(); MasterDetailViewModel viewModel = CreateMasterDetailViewModel(); viewModel.KeyValueChanged(change); viewModel.Save(); _commander.Verify(c => c.SaveChanges(_randomModule, _randomController, It.IsAny <IEnumerable <KeyValueChange> >())); }
public void OnViewModelWithChange_WithSameChangeAgain_ShouldReplaceOldChange() { KeyValueChange change = RandomKeyValueChange(); MasterDetailViewModel viewModel = CreateMasterDetailViewModel(); viewModel.KeyValueChanged(RandomKeyValueChange()); viewModel.KeyValueChanged(change); viewModel.Changes.Should().ContainSingle(c => Equals(c, change)); }
public void OnViewModelWithSuppressedChanges_ShouldNotStoreChange() { KeyValueChange change = RandomKeyValueChange(); MasterDetailViewModel viewModel = CreateMasterDetailViewModel(); viewModel.SuppressChangeEvent = true; viewModel.KeyValueChanged(change); viewModel.Changes.Should().NotContain(change); }
/// <summary> /// Resets all the changes made on the ui. /// </summary> public void Reset() { _pendingChange = null; foreach (KeyValueUnitViewModel child in _children) { child.Reset(); } NotifyOfPropertyChange(string.Empty); }
/// <summary> /// The KeyValueChanged method will be called by KeyValueUnitViewModels which can change values. /// Value changes are only captured if the SuppressChangeEvent flag is not set. /// </summary> /// <param name="change">The KeyValueChange from the KeyValueUnitViewModel.</param> public void KeyValueChanged(KeyValueChange change) { if (SuppressChangeEvent || change == null) { return; } KeyValueChange previousChangeWithKey = _changes.FirstOrDefault(c => string.Equals(c.Key, change.Key)); if (previousChangeWithKey != null) { _changes.Remove(previousChangeWithKey); } _changes.Add(change); }