Fix SettingsViewModelTest.CannotAddChildElementToFormatElement.

This commit is contained in:
Daniel Kraus 2015-08-03 06:32:05 +02:00
parent 14b09f89c5
commit db8f88c563
5 changed files with 26 additions and 11 deletions

View File

@ -58,7 +58,7 @@ namespace Tests.ViewModels
parent.IsSelected = true;
Assert.IsTrue(_settingsVM.AddChildElementCommand.CanExecute(null));
FormatElementViewModel child = new FormatElementViewModel(new Items());
parent.AddChildElement(child);
_settingsVM.AddChildElementViewModel(parent, child);
parent.IsSelected = false;
child.IsSelected = true;
Assert.IsFalse(_settingsVM.AddChildElementCommand.CanExecute(null));

View File

@ -31,7 +31,9 @@ namespace zaaReloaded2.Controller.Elements
/// </summary>
public IList<FormatElementBase> FormatElements { get; private set; }
public ControlElementBase() { }
public ControlElementBase()
: this(new List<FormatElementBase>())
{ }
public ControlElementBase(IList<FormatElementBase> formatElements)
{

View File

@ -26,24 +26,26 @@ using System.Collections.ObjectModel;
namespace zaaReloaded2.ViewModels
{
class ControlElementViewModel : ElementViewModel
public class ControlElementViewModel : ElementViewModel
{
#region Properties
public ObservableCollection<ElementViewModel> Elements
{
get { return null; }
}
/// <summary>
/// Gets a collection of child ElementViewModels.
/// </summary>
public ObservableCollection<ElementViewModel> Elements { get; protected set; }
#endregion
#region Constructors
public ControlElementViewModel() : base() { }
public ControlElementViewModel() : this(null) { }
public ControlElementViewModel(ControlElementBase controlElement)
: base(controlElement)
{ }
{
Elements = new ObservableCollection<ElementViewModel>();
}
#endregion

View File

@ -24,7 +24,7 @@ using zaaReloaded2.Controller.Elements;
namespace zaaReloaded2.ViewModels
{
class FormatElementViewModel : ElementViewModel
public class FormatElementViewModel : ElementViewModel
{
#region Public properties

View File

@ -218,6 +218,17 @@ namespace zaaReloaded2.ViewModels
Elements.Add(elementViewModel);
}
/// <summary>
/// Wires the OnProperty changed event of an ElementViewModel's
/// wrapped model and adds the view model as a child of another
/// view model.
/// </summary>
public void AddChildElementViewModel(ControlElementViewModel parent, FormatElementViewModel child)
{
child.PropertyChanged += ElementViewModel_PropertyChanged;
parent.AddChildElement(child);
}
#endregion
#region Private methods
@ -246,7 +257,7 @@ namespace zaaReloaded2.ViewModels
void ElementViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
ElementViewModel vm = sender as ElementViewModel;
if (vm != null)
if (vm != null && e.PropertyName == "IsSelected")
{
SelectedElement = vm.IsSelected ? vm : null;
}