Implement tests for SettingsViewModel add and add child commands.
This commit is contained in:
@ -40,13 +40,52 @@ namespace Tests.ViewModels
|
||||
[Test]
|
||||
public void AddElement()
|
||||
{
|
||||
|
||||
bool messageSent = false;
|
||||
Settings model = _settingsVM.RevealModelObject() as Settings;
|
||||
int oldViewModelElementCount = _settingsVM.Elements.Count;
|
||||
int oldModelElementCount = model.Elements.Count;
|
||||
_settingsVM.AddElementMessage.Sent += (sender, args) =>
|
||||
{
|
||||
messageSent = true;
|
||||
ElementPickerViewModel picker = args.Content.ViewModel as ElementPickerViewModel;
|
||||
Assert.IsNotNull(picker, "ViewModel in MessageContent is not an ElementPickerViewModel");
|
||||
picker.Categories.First().Children.First().IsSelected = true;
|
||||
picker.ChooseElementCommand.Execute(null);
|
||||
};
|
||||
_settingsVM.AddElementCommand.Execute(null);
|
||||
Assert.IsTrue(messageSent, "Message was not sent");
|
||||
Assert.AreEqual(oldViewModelElementCount + 1, _settingsVM.Elements.Count,
|
||||
"Count of elements in ViewModel was not increased by 1");
|
||||
Assert.AreEqual(oldModelElementCount + 1, model.Elements.Count,
|
||||
"Count of elements in settings Model was not increased by 1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddChildElement()
|
||||
{
|
||||
|
||||
bool messageSent = false;
|
||||
SelectEachDay model = new SelectEachDay();
|
||||
ControlElementViewModel viewModel = new ControlElementViewModel(model);
|
||||
_settingsVM.AddElementViewModel(viewModel);
|
||||
viewModel.IsSelected = true;
|
||||
int oldViewModelChildrenCount = viewModel.Elements.Count;
|
||||
int oldModelChildrenCount = model.FormatElements.Count;
|
||||
_settingsVM.AddChildElementMessage.Sent += (sender, args) =>
|
||||
{
|
||||
messageSent = true;
|
||||
ElementPickerViewModel picker = args.Content.ViewModel as ElementPickerViewModel;
|
||||
Assert.IsNotNull(picker, "ViewModel in MessageContent is not an ElementPickerViewModel");
|
||||
picker.Categories.First().Children.First().IsSelected = true;
|
||||
Assert.IsTrue(picker.ChooseElementCommand.CanExecute(null),
|
||||
"Cannot execute element picker's ChooseElementCommand.");
|
||||
picker.ChooseElementCommand.Execute(null);
|
||||
};
|
||||
_settingsVM.AddChildElementCommand.Execute(null);
|
||||
Assert.IsTrue(messageSent, "Message was not sent");
|
||||
Assert.AreEqual(oldViewModelChildrenCount + 1, viewModel.Elements.Count,
|
||||
"Count of children in ViewModel was not increased by 1");
|
||||
Assert.AreEqual(oldModelChildrenCount + 1, model.FormatElements.Count,
|
||||
"Count of children in Model was not increased by 1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -67,13 +106,13 @@ namespace Tests.ViewModels
|
||||
[Test]
|
||||
public void DeleteElement()
|
||||
{
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CopyElement()
|
||||
{
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user