public void changeTrackingService_beginAtomicOperation_normal_should_create_valid_atomic_operation()
		{
			var target = new ChangeTrackingService();
			var actual = target.BeginAtomicOperation();

			actual.Should().Not.Be.Null();
		}
        public void changeTrackingService_hasTransientEntities_should_be_false_after_acceptChanges()
        {
            var svc = new ChangeTrackingService();
            var p = new Person( svc, true );
            svc.AcceptChanges();

            svc.HasTransientEntities.Should().Be.False();
        }
        public void changeTrackingService_hasTransientEntities_should_be_true_after_undo()
        {
            var svc = new ChangeTrackingService();
            var p = new Person( svc, true );
            svc.Undo();

            svc.HasTransientEntities.Should().Be.True();
        }
Exemplo n.º 4
0
		public void entityMemento_ctor_memento_set_default_values()
		{
			var expected = new ChangeTrackingService();
			var target = this.CreateMock( expected );

			( ( IMemento )target ).Memento.Should().Be.EqualTo( expected );
			( ( IMemento )target ).Memento.Should().Be.EqualTo( expected );
		}
        public void afterPropertyChange_canUndo_is_true()
        {
            ChangeTrackingService svc = new ChangeTrackingService();

            Person p = new Person( svc, false );
            p.Name = "Mauro";

            Assert.IsTrue( svc.CanUndo );
        }
        public void after_Add_canUndo_is_true()
        {
            IChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection( svc );
            p.Add( new Person( svc, false ) );

            svc.CanUndo.Should().Be.True();
        }
        public void after_mutual_exclusive_actions_service_CanUndo()
        {
            IChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection( svc );
            p.Add( new Person( svc, false ) );
            p.RemoveAt( 0 );

            Assert.IsTrue( svc.CanUndo );
        }
        public void after_Add_getChangeSet_contains_change()
        {
            IChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection( svc );
            p.Add( new Person( svc, false ) );
            p.Add( new Person( svc, false ) );

            IChangeSet cSet = svc.GetChangeSet();

            cSet.Count.Should().Be.EqualTo( 2 );
        }
        public void after_Undo_collection_is_rolledback()
        {
            Int32 expected = 0;

            IChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection( svc );
            p.Add( new Person( svc, false ) );

            svc.Undo();

            p.Count.Should().Be.EqualTo( expected );
        }
        public void after_add_GetEntityState_is_Changed()
        {
            EntityTrackingStates expected = EntityTrackingStates.HasBackwardChanges;

            ChangeTrackingService svc = new ChangeTrackingService();

            PersonCollection p = new PersonCollection( svc );
            p.Add( new Person( svc, false ) );
            p.Add( new Person( svc, false ) );

            EntityTrackingStates actual = svc.GetEntityState( p );

            actual.Should().Be.EqualTo( expected );
        }
		public void changeTrackingService_using_atomicOperation_after_operation_complete_entityState_should_be_changed()
		{
			var target = new ChangeTrackingService();

			var person = new Person( target );

			target.AcceptChanges();
			
			using( var op = target.BeginAtomicOperation() )
			{
				person.Name = "Mauro";

				op.Complete();
			}

			var state = target.GetEntityState( person );

			var actual = (state & EntityTrackingStates.HasBackwardChanges ) == EntityTrackingStates.HasBackwardChanges;
			actual.Should().Be.True();
		}
		public void changeTrackingService_using_beginAtomicOperation_should_set_is_changed_only_on_operation_completed()
		{
			var target = new ChangeTrackingService();

			var person = new Person( target );
			var list = new PersonCollection( target );

			using( var actual = target.BeginAtomicOperation() )
			{
				person.Name = "Mauro";
				list.Add( person );
				person.Name = "Mauro Servienti";

				target.IsChanged.Should().Be.False();

				actual.Complete();
			}

			target.IsChanged.Should().Be.True();
		}
		public void changeTrackingService_using_beginAtomicOperation_should_fully_rollback_on_single_undo()
		{
			var target = new ChangeTrackingService();

			var person = new Person( target );
			var list = new PersonCollection( target );

			using( var actual = target.BeginAtomicOperation() )
			{
				person.Name = "Mauro";
				list.Add( person );
				person.Name = "Mauro Servienti";

				actual.Complete();
			}

			target.Undo();

			list.Count.Should().Be.EqualTo( 0 );
			person.Name.Should().Be.EqualTo( String.Empty );
		}
		public void changeTrackingService_using_beginAtomicOperation_hasTransientEntities_should_return_true_even_for_entities_created_in_the_atomic_operation()
		{
			var target = new ChangeTrackingService();

			var list = new PersonCollection( target );
			var person = new Person( target, false );

			using( var op = target.BeginAtomicOperation() )
			{
				target.RegisterTransient( person );
				person.Name = "Mauro";
				list.Add( person );
				person.Name = "Mauro Servienti";

				op.Complete();
			}

			var actual = target.HasTransientEntities;

			actual.Should().Be.True();
		}
		public void changeTrackingService_using_beginAtomicOperation_getEntities_should_return_all_transient_entities()
		{
			var target = new ChangeTrackingService();

			var list = new PersonCollection( target );
			var person = new Person( target, false );

			using( var op = target.BeginAtomicOperation() )
			{
				target.RegisterTransient( person );
				person.Name = "Mauro";
				list.Add( person );
				person.Name = "Mauro Servienti";

				op.Complete();
			}

			var actual = target.GetEntities( EntityTrackingStates.IsTransient, false );

			actual.Contains( person ).Should().Be.True();
		}
		public void changeTrackingService_using_beginAtomicOperation_getEntities_should_return_all_changed_entities()
		{
			var target = new ChangeTrackingService();

			var person = new Person( target );
			var list = new PersonCollection( target );

			using( var op = target.BeginAtomicOperation() )
			{
				person.Name = "Mauro";
				list.Add( person );
				person.Name = "Mauro Servienti";

				op.Complete();
			}

			var actual = target.GetEntities( EntityTrackingStates.HasBackwardChanges, false );

			/*
			 * Non funziona perchè non funziona GetEntityState()
			 */

			actual.Contains( person ).Should().Be.True();
		}
		public void changeTrackingService_using_beginAtomicOperation_getEntityState_should_return_valid_entity_state()
		{
			var target = new ChangeTrackingService();

			var person = new Person( target );
			var list = new PersonCollection( target );

			using( var op = target.BeginAtomicOperation() )
			{
				person.Name = "Mauro";
				list.Add( person );
				person.Name = "Mauro Servienti";

				op.Complete();
			}

			var actual = target.GetEntityState( person );
			actual.Should().Be.EqualTo( EntityTrackingStates.HasBackwardChanges | EntityTrackingStates.IsTransient | EntityTrackingStates.AutoRemove );
		}
        public void afterUndo_propertyValue_is_rolledback()
        {
            ChangeTrackingService svc = new ChangeTrackingService();

            Person p = new Person( svc, false );
            String expected = p.Name;
            p.Name = "Mauro";

            svc.Undo();

            Assert.AreEqual<String>( expected, p.Name );
        }
        public void service_successfully_revert_to_a_valid_bookmark_created_at_initial_state()
        {
            String expected = String.Empty;

            ChangeTrackingService svc = new ChangeTrackingService();
            IBookmark bmk = svc.CreateBookmark();

            Person p = new Person( svc );
            p.Name = "foo..";
            p.Name = "foo once again...";

            svc.Revert( bmk );

            Assert.AreEqual<String>( expected, p.Name );
        }
        public void service_with_no_changes_create_non_null_bookmark()
        {
            ChangeTrackingService svc = new ChangeTrackingService();
            var bmk = svc.CreateBookmark();

            Assert.IsNotNull( bmk );
        }
        public void service_revert_to_a_bookmark_created_by_another_service()
        {
            ChangeTrackingService svc1 = new ChangeTrackingService();
            IBookmark bmk = svc1.CreateBookmark();

            ChangeTrackingService svc2 = new ChangeTrackingService();
            svc2.Revert( bmk );
        }
 public void service_revert_with_a_null_bookmark()
 {
     ChangeTrackingService svc = new ChangeTrackingService();
     svc.Revert( null );
 }
        public void service_validate_a_bookmark_invalid_is_false()
        {
            ChangeTrackingService svc = new ChangeTrackingService();

            Person p = new Person( svc );
            p.Name = "Mauro";

            var bmk = svc.CreateBookmark();
            svc.Undo();

            Assert.IsFalse( svc.Validate( bmk ) );
        }
        public void service_add_notSupported_AddChangeBehavior()
        {
            IChange stub = MockRepository.GenerateStub<IChange>();

            ChangeTrackingService svc = new ChangeTrackingService();
            svc.Add( stub, AddChangeBehavior.None );
        }
 public void service_cannot_validate_a_null_bookmark()
 {
     ChangeTrackingService svc = new ChangeTrackingService();
     svc.Validate( null );
 }
        public void afterPropertyChanges_getChangeSet_contains_change()
        {
            ChangeTrackingService svc = new ChangeTrackingService();

            Person p = new Person( svc, false );
            p.Name = "Mauro";
            p.Name = "Andrea";

            IChangeSet cSet = svc.GetChangeSet();

            Assert.AreEqual<Int32>( 2, cSet.Count );
        }
        public void service_validate_a_valid_bookmark_is_true()
        {
            RejectCallback<String> cb = cv => { };
            Object fakeOwner = new Object();
            String change = String.Empty;
            IChange expected = new PropertyValueChange<String>( fakeOwner, "property-name", change, cb );

            ChangeTrackingService svc = new ChangeTrackingService();
            svc.Add( expected, AddChangeBehavior.RedoRequest );

            var bmk = svc.CreateBookmark();

            Assert.IsTrue( svc.Validate( bmk ) );
        }
        public void service_add_invalid_AddChangeBehavior()
        {
            IChange stub = MockRepository.GenerateStub<IChange>();

            ChangeTrackingService svc = new ChangeTrackingService();
            svc.Add( stub, ( AddChangeBehavior )1000 );
        }
		public void changeTrackingService_using_beginAtomicOperation_redo_should_reapply_all_changes_with_one_pass()
		{
			var target = new ChangeTrackingService();

			var person = new Person( target );
			var list = new PersonCollection( target );

			using( var actual = target.BeginAtomicOperation() )
			{
				person.Name = "Mauro";
				list.Add( person );
				person.Name = "Mauro Servienti";

				actual.Complete();
			}

			target.Undo();
			target.Redo();

			list.Count.Should().Be.EqualTo( 1 );
			person.Name.Should().Be.EqualTo( "Mauro Servienti" );
		}
        public void service_validate_a_bookmark_owned_by_another_service_is_false()
        {
            ChangeTrackingService svc1 = new ChangeTrackingService();
            var bmk = svc1.CreateBookmark();

            ChangeTrackingService svc2 = new ChangeTrackingService();

            Assert.IsFalse( svc2.Validate( bmk ) );
        }