Implement tests for SettingsViewModel add and add child commands.
This commit is contained in:
parent
805da69d47
commit
a128b76522
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -146,6 +146,7 @@ namespace zaaReloaded2.ViewModels
|
||||
{
|
||||
FormatElementViewModel vm = new FormatElementViewModel(element);
|
||||
vm.DisplayString = name;
|
||||
vm.PropertyChanged += ElementViewModel_PropertyChanged;
|
||||
return vm;
|
||||
}
|
||||
|
||||
|
@ -145,6 +145,30 @@ namespace zaaReloaded2.ViewModels
|
||||
|
||||
#region Messages
|
||||
|
||||
public Message<ViewModelMessageContent> AddElementMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_addElementMessage == null)
|
||||
{
|
||||
_addElementMessage = new Message<ViewModelMessageContent>();
|
||||
}
|
||||
return _addElementMessage;
|
||||
}
|
||||
}
|
||||
|
||||
public Message<ViewModelMessageContent> AddChildElementMessage
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_addChildElementMessage == null)
|
||||
{
|
||||
_addChildElementMessage = new Message<ViewModelMessageContent>();
|
||||
}
|
||||
return _addChildElementMessage;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Commands
|
||||
@ -216,6 +240,7 @@ namespace zaaReloaded2.ViewModels
|
||||
{
|
||||
elementViewModel.PropertyChanged += ElementViewModel_PropertyChanged;
|
||||
Elements.Add(elementViewModel);
|
||||
_settings.Elements.Add(elementViewModel.RevealModelObject() as ElementBase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -233,9 +258,34 @@ namespace zaaReloaded2.ViewModels
|
||||
|
||||
#region Private methods
|
||||
|
||||
void DoAddElement() { }
|
||||
void DoAddElement()
|
||||
{
|
||||
// Create a new element picker; it will automatically create and
|
||||
// send us a new element view model if one is chosen by the view.
|
||||
ElementPickerViewModel picker = new ElementPickerViewModel(true);
|
||||
picker.ElementChosenMessage.Sent += (sender, args) =>
|
||||
{
|
||||
ElementViewModel newVM = args.Content.ViewModel as ElementViewModel;
|
||||
AddElementViewModel(newVM);
|
||||
};
|
||||
AddElementMessage.Send(new ViewModelMessageContent(picker));
|
||||
}
|
||||
|
||||
void DoAddChildElement() { }
|
||||
void DoAddChildElement()
|
||||
{
|
||||
if (CanAddChildElement())
|
||||
{
|
||||
// Create a new element picker; it will automatically create and
|
||||
// send us a new element view model if one is chosen by the view.
|
||||
ElementPickerViewModel picker = new ElementPickerViewModel(false);
|
||||
picker.ElementChosenMessage.Sent += (sender, args) =>
|
||||
{
|
||||
FormatElementViewModel newVM = args.Content.ViewModel as FormatElementViewModel;
|
||||
AddChildElementViewModel(SelectedElement as ControlElementViewModel, newVM);
|
||||
};
|
||||
AddChildElementMessage.Send(new ViewModelMessageContent(picker));
|
||||
}
|
||||
}
|
||||
|
||||
bool CanAddChildElement()
|
||||
{
|
||||
@ -290,7 +340,8 @@ namespace zaaReloaded2.ViewModels
|
||||
DelegatingCommand _addChildElementCommand;
|
||||
DelegatingCommand _deleteElementCommand;
|
||||
DelegatingCommand _copyElementCommand;
|
||||
|
||||
Message<ViewModelMessageContent> _addElementMessage;
|
||||
Message<ViewModelMessageContent> _addChildElementMessage;
|
||||
List<ElementViewModel> _elements;
|
||||
ElementViewModel _selectedElement;
|
||||
EnumProvider<ReferenceStyle> _referenceStyle;
|
||||
|
Loading…
Reference in New Issue
Block a user