public void Add_Item() { var s = new SharedSource <MySharedItem>(); var item1 = new MySharedItem { Id = 1, Name = "A" }; item1.CActivate = false; s.Add(item1, 1); Assert.AreEqual(true, item1.IsCanActivateInvoked); Assert.AreEqual(false, item1.IsOnNavigatingFromInvoked); Assert.AreEqual(false, item1.IsOnNavigatingToInvoked); Assert.AreEqual(null, item1.POnNavigatingTo); Assert.AreEqual(false, item1.IsOnNavigatedToInvoked); Assert.AreEqual(null, item1.POnNavigatedTo); item1.CActivate = true; s.Add(item1, 1); Assert.AreEqual(true, item1.IsCanActivateInvoked); Assert.AreEqual(false, item1.IsOnNavigatingFromInvoked); Assert.AreEqual(true, item1.IsOnNavigatingToInvoked); Assert.AreEqual(1, item1.POnNavigatingTo); Assert.AreEqual(true, item1.IsOnNavigatedToInvoked); Assert.AreEqual(1, item1.POnNavigatedTo); Assert.AreEqual(1, s.Items.Count); Assert.AreEqual(item1, s.Items.ElementAt(0)); }
public void Navigate_With_Commands_Update_CanExecute() { var sharedSource = new SharedSource <MySharedItem>(); var commands = new SharedSourceCommands(sharedSource); Assert.AreEqual(false, commands.MoveToFirstCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToPreviousCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToNextCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToLastCommand.CanExecute(null)); var itemA = new MySharedItem(); sharedSource.Add(itemA); Assert.AreEqual(true, itemA.IsOnNavigatedToInvoked); Assert.AreEqual(false, commands.MoveToFirstCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToPreviousCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToNextCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToLastCommand.CanExecute(null)); var itemB = new MySharedItem(); sharedSource.Add(itemB); Assert.AreEqual(true, itemB.IsOnNavigatedToInvoked); Assert.AreEqual(true, commands.MoveToFirstCommand.CanExecute(null)); Assert.AreEqual(true, commands.MoveToPreviousCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToNextCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToLastCommand.CanExecute(null)); commands.MoveToPreviousCommand.Execute(null); // B => A Assert.AreEqual(itemA, sharedSource.SelectedItem); Assert.AreEqual(false, commands.MoveToFirstCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToPreviousCommand.CanExecute(null)); Assert.AreEqual(true, commands.MoveToNextCommand.CanExecute(null)); Assert.AreEqual(true, commands.MoveToLastCommand.CanExecute(null)); commands.MoveToNextCommand.Execute(null); // A => B Assert.AreEqual(itemB, sharedSource.SelectedItem); Assert.AreEqual(true, commands.MoveToFirstCommand.CanExecute(null)); Assert.AreEqual(true, commands.MoveToPreviousCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToNextCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToLastCommand.CanExecute(null)); commands.MoveToFirstCommand.Execute(null); Assert.AreEqual(itemA, sharedSource.SelectedItem); Assert.AreEqual(false, commands.MoveToFirstCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToPreviousCommand.CanExecute(null)); Assert.AreEqual(true, commands.MoveToNextCommand.CanExecute(null)); // not clear backstack Assert.AreEqual(true, commands.MoveToLastCommand.CanExecute(null)); commands.MoveToLastCommand.Execute(null); Assert.AreEqual(itemB, sharedSource.SelectedItem); Assert.AreEqual(true, commands.MoveToFirstCommand.CanExecute(null)); Assert.AreEqual(true, commands.MoveToPreviousCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToNextCommand.CanExecute(null)); Assert.AreEqual(false, commands.MoveToLastCommand.CanExecute(null)); }
public void FindSelectable_With_Interface() { var item1 = new MySelectableViewModel { Id = 2 }; var sources = new List <IMyViewModel> { new MyViewModelCanDeactivate(), new MySelectableViewModel { Id = 1 }, new MyViewModelCanActivate(), item1, new MySelectableViewModel { Id = 3 } }; var sharedSource = new SharedSource <IMyViewModel>().Load(sources); Assert.AreEqual(5, sharedSource.Items.Count); Assert.AreEqual(0, sharedSource.SelectedIndex); sharedSource.Add(new MySelectableViewModel { Id = 2 }, 2); Assert.AreEqual(3, sharedSource.SelectedIndex); Assert.AreEqual(item1, sharedSource.SelectedItem); }