// Deletes current person
        void DeleteCurrentPerson()
        {
            if (current == null)
            {
                return;
            }
            Person deleted = current;

            if (persons.Count != 1)
            {
                int index = persons.IndexOf(deleted);
                Current = persons[index == 0 ? 1 : index - 1];
            }
            else
            {
                Current = null;
                deleteCommand.RaiseCanExecuteChanged();
            }

            persons.Remove(deleted);
        }
        public void service_redoes_are_in_the_correct_order()
        {
            var p1 = new Person( null, false );
            var p2 = new Person( null, false );
            var p3 = new Person( null, false );

            ChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection list = new PersonCollection( svc );
            list.Add( p1 );
            list.Add( p2 );
            list.Add( p3 );
            list.Move( p2, 0 );
            list.Remove( p1 );

            while( svc.CanUndo )
            {
                svc.Undo();
            }

            svc.Redo();
            Assert.AreEqual<Int32>( 1, list.Count );
            Assert.IsTrue( list.Contains( p1 ) );

            svc.Redo();
            Assert.AreEqual<Int32>( 2, list.Count );
            Assert.IsTrue( list.Contains( p2 ) );

            svc.Redo();
            Assert.AreEqual<Int32>( 3, list.Count );
            Assert.IsTrue( list.Contains( p3 ) );

            svc.Redo();
            Assert.AreEqual<Int32>( 0, list.IndexOf( p2 ) );

            svc.Redo();
            Assert.AreEqual<Int32>( 2, list.Count );
            Assert.IsFalse( list.Contains( p1 ) );
        }
        public void service_on_clear_undo_entities_are_restored()
        {
            var source = new Person[] 
            {
                new Person( null, false ),
                new Person( null, false ),
                new Person( null, false ),
                new Person( null, false ),
                new Person( null, false )
            };

            ChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection list = new PersonCollection( svc );
            list.BeginInit();
            list.AddRange( source );
            list.EndInit();

            list.Clear();
            svc.Undo();

            Assert.AreEqual<Int32>( source.Length, list.Count() );
            source.ForEach( p =>
            {
                Int32 expected = Array.IndexOf( source, p );
                Int32 actual = list.IndexOf( p );

                Assert.AreEqual<Int32>( expected, actual );
            } );
        }