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_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 after_suspend_cannot_call_AcceptChanges()
        {
            ChangeTrackingService svc = new ChangeTrackingService();

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

            svc.Suspend();
            svc.AcceptChanges();
        }
        public void after_acceptChanges_service_canRedo_is_false()
        {
            ChangeTrackingService svc = new ChangeTrackingService();

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

            Assert.IsFalse( svc.CanRedo );
        }
        public void entity_registeredAsTransient_without_autoRemove_on_AcceptChanges_is_no_more_transient()
        {
            ChangeTrackingService svc = new ChangeTrackingService();
            EntityTrackingStates expected = EntityTrackingStates.None;

            Person p = new Person( svc, false );
            svc.RegisterTransient( p, false );
            svc.AcceptChanges();

            EntityTrackingStates actual = svc.GetEntityState( p );

            Assert.AreEqual<EntityTrackingStates>( expected, actual );
        }
        public void after_acceptChanges_entity_is_no_more_changed()
        {
            EntityTrackingStates expected = EntityTrackingStates.None;

            ChangeTrackingService svc = new ChangeTrackingService();

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

            svc.AcceptChanges();

            EntityTrackingStates actual = svc.GetEntityState( p );
            Assert.AreEqual<EntityTrackingStates>( expected, actual );
        }
        public void service_on_acceptChanges_successfully_commit_a_commitSupported_change()
        {
            var iChange = MockRepository.GenerateStub<IChange>();
            iChange.Expect( obj => obj.IsCommitSupported ).Return( true );
            iChange.Expect( obj => obj.Commit( CommitReason.AcceptChanges ) ).Repeat.Once();

            var svc = new ChangeTrackingService();
            svc.Add( iChange, AddChangeBehavior.Default );

            svc.AcceptChanges();

            iChange.VerifyAllExpectations();
        }
        public void service_on_acceptChanges_with_nothing_to_do_not_raise_trackingServiceStateChanged_event()
        {
            Int32 expected = 0;
            Int32 actual = 0;

            ChangeTrackingService svc = new ChangeTrackingService();
            Person p = new Person( svc, false );

            svc.TrackingServiceStateChanged += ( sender, args ) => { actual++; };
            svc.AcceptChanges();

            Assert.AreEqual<Int32>( expected, actual );
        }
        public void service_with_changes_and_transientEntities_on_acceptChanges_raise_trackingServiceStateChanged_event()
        {
            Int32 expected = 1;
            Int32 actual = 0;

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

            svc.TrackingServiceStateChanged += ( sender, args ) => { actual++; };
            svc.AcceptChanges();

            Assert.AreEqual<Int32>( expected, actual );
        }
        public void service_on_clear_generate_valid_advisory()
        {
            ChangeTrackingService svc = new ChangeTrackingService();

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

            svc.AcceptChanges();

            p.Clear();

            IEnumerable<IAdvisedAction> advisory = svc.GetAdvisory();

            Assert.IsNotNull( advisory );
            Assert.AreEqual<Int32>( 5, advisory.Count() );
            foreach( var aa in advisory )
            {
                Assert.AreEqual<ProposedActions>( ProposedActions.Delete, aa.Action );
            }
        }
        public void after_acceptChanges_service_canRedo_is_false()
        {
            ChangeTrackingService svc = new ChangeTrackingService();

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

            svc.AcceptChanges();

            Assert.IsFalse( svc.CanRedo );
        }