Implement test to delete child element and make it pass.

This commit is contained in:
Daniel Kraus 2015-08-05 20:36:31 +02:00
parent 60296602a9
commit 1205958eb1
2 changed files with 27 additions and 0 deletions

View File

@ -127,6 +127,32 @@ namespace Tests.ViewModels
"Settings' Element collection still contains the element model.");
}
[Test]
public void DeleteChildElement()
{
Settings settings = new Settings();
settings.AddElement(new SelectFirstDay(new Items()));
settings.AddElement(new SelectEachDay());
settings.AddElement(new SelectLastDay());
SettingsViewModel settingsVM = new SettingsViewModel(settings);
ControlElementViewModel parent = ((ControlElementViewModel)settingsVM.Elements.First());
int oldCount = parent.Elements.Count;
ElementViewModel elementVM = ((ControlElementViewModel)settingsVM.Elements.First())
.Elements.First();
ElementBase element = elementVM.RevealModelObject() as ElementBase;
Assert.IsTrue(((ControlElementBase)settings.Elements[0]).FormatElements.Contains(element),
"Settings object does not contain the model that the VM revealed?!");
elementVM.IsSelected = true;
Assert.IsTrue(settingsVM.DeleteElementCommand.CanExecute(null),
"DeleteElementCommand should be enabled.");
settingsVM.DeleteElementCommand.Execute(null);
Assert.AreEqual(oldCount - 1, parent.Elements.Count);
Assert.IsFalse(parent.Elements.Contains(elementVM),
"Elements collection still contains the deleted element view model.");
Assert.IsFalse(((ControlElementBase)settings.Elements[0]).FormatElements.Contains(element),
"Settings' collection of FormatElement children still contains the element model.");
}
[Test]
public void CopyElement()
{

View File

@ -135,6 +135,7 @@ namespace zaaReloaded2.ViewModels
vm = new ControlElementViewModel(element as ControlElementBase);
foreach (FormatElementViewModel childVM in ((ControlElementViewModel)vm).Elements)
{
childVM.Parent = vm as ControlElementViewModel;
childVM.PropertyChanged += ElementViewModel_PropertyChanged;
}
}