public void DeletedItem_IsThrownInTrash()
        {
            persister.ItemDeleting += null;
            IEventRaiser invokeDelete = LastCall.IgnoreArguments().GetEventRaiser();
            persister.ItemCopied += null;
            LastCall.IgnoreArguments();
            persister.ItemMoving += null;
            LastCall.IgnoreArguments();

            TrashHandler th = mocks.StrictMock<TrashHandler>(persister, null, null, new ContainerRepository<TrashContainerItem>(persister, null, new Host(webContext, 1, 1), null), null);
            th.UseNavigationMode = true;
            Expect.Call(delegate { th.Throw(item); });

            mocks.ReplayAll();

            DeleteInterceptor interceptor = new DeleteInterceptor(persister, th);
            interceptor.Start();

            CancellableItemEventArgs deleteArgs = new CancellableItemEventArgs(item);
            invokeDelete.Raise(persister, deleteArgs);

            deleteArgs.FinalAction(deleteArgs.AffectedItem);

            mocks.VerifyAll();
        }
		public void NonThrowableItem_IsNotMovedToTrashcan_LegacyAttribute()
		{
			var nonThrowable = CreateItem<NonThrowableItem>(4, "neverInTrash", root);

			var th = CreateTrashHandler();
			DeleteInterceptor interceptor = new DeleteInterceptor(persister, th);
			interceptor.Start();

			persister.Delete(nonThrowable);
			
			Assert.That(trash.Children.Count, Is.EqualTo(0));
		}
        public void DeletedItem_IsThrownInTrash()
        {
			var th = CreateTrashHandler();
			th.UseNavigationMode = true;

            DeleteInterceptor interceptor = new DeleteInterceptor(persister, th);
            interceptor.Start();

			persister.Delete(item);

			item.Parent.ShouldBeTypeOf<TrashContainerItem>();
        }
        public void TrashedItem_MovedFromTrashcan_IsUnexpired()
        {
            PutItemInTrash();

			var th = CreateTrashHandler();
			th.UseNavigationMode = true;
            th.RestoreValues(item);
			DeleteInterceptor interceptor = new DeleteInterceptor(persister, th);
            interceptor.Start();

			// now restore through drag&drop
			persister.Move(item, root);

			item.Parent.ShouldBe(root);
			item[TrashHandler.DeletedDate].ShouldBe(null);
        }
        public void Item_MovedIntoTrash_IsNeutralized()
        {
            persister.ItemDeleting += null;
            LastCall.IgnoreArguments();
            persister.ItemCopied += null;
            LastCall.IgnoreArguments();
            persister.ItemMoving += null;
            IEventRaiser invokeMoved = LastCall.IgnoreArguments().GetEventRaiser();

            TrashHandler th = mocks.StrictMock<TrashHandler>(persister, null, null, new ContainerRepository<TrashContainerItem>(persister, null, new Host(webContext, 1, 1), null), null);
            th.UseNavigationMode = true;
            th.ExpireTrashedItem(item);

            mocks.ReplayAll();

            DeleteInterceptor interceptor = new DeleteInterceptor(persister, th);
            interceptor.Start();

            // move item into trashcan
            invokeMoved.Raise(persister, new CancellableDestinationEventArgs(item, trash));

            mocks.VerifyAll();
        }
        public void TrashedItem_CopiedFromTrashcan_IsUnexpired()
        {
            PutItemInTrash();

			var th = CreateTrashHandler();
			th.UseNavigationMode = true;
            th.RestoreValues(item);
			DeleteInterceptor interceptor = new DeleteInterceptor(persister, th);
            interceptor.Start();

			var copy = persister.Copy(item, root);

			copy.Parent.ShouldBe(root);
			copy[TrashHandler.DeletedDate].ShouldBe(null);
        }
        public void Item_MovedIntoTrash_IsNeutralized()
        {
			var th = CreateTrashHandler();
			th.UseNavigationMode = true;
            th.ExpireTrashedItem(item);
			DeleteInterceptor interceptor = new DeleteInterceptor(persister, th);
            interceptor.Start();

			persister.Move(item, trash);

			item[TrashHandler.DeletedDate].ShouldNotBe(null);
        }
        public void NonThrowableItem_IsNotMovedToTrashcan()
        {
            IDefinitionManager definitions = mocks.Stub<IDefinitionManager>();

            IPersister persister = mocks.Stub<IPersister>();
            Expect.Call(persister.Get(1)).Return(root).Repeat.Any();
            persister.ItemDeleting += null;
            IEventRaiser invokeDelete = LastCall.IgnoreArguments().GetEventRaiser();

            mocks.ReplayAll();

            var host = new Host(webContext, 1, 1);
            TrashHandler th = new TrashHandler(persister, null, null, new ContainerRepository<TrashContainerItem>(persister, null, host, null), new StateChanger()) { UseNavigationMode = true };
            DeleteInterceptor interceptor = new DeleteInterceptor(persister, th);
            interceptor.Start();

            CancellableItemEventArgs deleteArgs = new CancellableItemEventArgs(nonThrowable);
            invokeDelete.Raise(persister, deleteArgs);

            Assert.That(deleteArgs.Cancel, Is.False);
            Assert.That(trash.Children.Count, Is.EqualTo(0));
        }
        public void TrashedItem_MovedFromTrashcan_IsUnexpired()
        {
            PutItemInTrash();

            persister.ItemDeleting += null;
            LastCall.IgnoreArguments();
            persister.ItemCopied += null;
            LastCall.IgnoreArguments();
            persister.ItemMoving += null;
            IEventRaiser invokeMoved = LastCall.IgnoreArguments().GetEventRaiser();

            TrashHandler th = mocks.PartialMock<TrashHandler>(persister, null, null, new ContainerRepository<TrashContainerItem>(persister, null, new Host(webContext, 1, 1), null), null);
            th.UseNavigationMode = true;
            th.RestoreValues(item);

            mocks.ReplayAll();

            DeleteInterceptor interceptor = new DeleteInterceptor(persister, th);
            interceptor.Start();

            // now restore through drag&drop
            invokeMoved.Raise(persister, new CancellableDestinationEventArgs(item, root));

            mocks.VerifyAll();
        }