示例#1
0
        public void TestMoveToNewFolder( )
        {
            Folder   f1 = null;
            Folder   f2 = null;
            Resource r  = null;

            try
            {
                // Create two folders
                f1 = new Folder( );
                f1.Save( );
                f2 = new Folder( );
                f2.Save( );

                // Create resource in first folder
                r = new Resource();
                r.ResourceInFolder.Add(f1.As <NavContainer>());
                r.Save( );

                // Move resource into second folder
                r = Entity.Get <Resource>(r.Id).AsWritable <Resource>( );
                r.ResourceInFolder.Remove(f1.As <NavContainer>());
                r.ResourceInFolder.Add(f2.As <NavContainer>());
                r.Save( );

                // Verify that resource is in second folder
                f2 = Entity.Get <Folder>(f2.Id);
                Assert.AreEqual(1, f2.FolderContents.Count);

                // Verify that resource is not in first folder
                f1 = Entity.Get <Folder>(f1.Id);
                Assert.AreEqual(0, f1.FolderContents.Count);
            }
            finally
            {
                if (r != null)
                {
                    r.Delete( );
                }

                if (f1 != null)
                {
                    f1.AsWritable( ).Delete( );
                }

                if (f2 != null)
                {
                    f2.AsWritable( ).Delete( );
                }
            }
        }
示例#2
0
        public void TestEntity_Constructor_Type_Null( )
        {
            // Create parent and child folders
            var parent = new Folder
            {
                Name = "Parent"
            };

            parent.Save( );

            var child = new Folder
            {
                Name = "Child"
            };

            child.Save( );

            // Link them together via child
            child.ResourceInFolder.Add(parent.As <NavContainer>( ));
            child.Save( );

            // Assert that the parent has the relationship
            parent = Entity.Get <Folder>(parent.Id);
            Assert.AreEqual(1, parent.FolderContents.Count);

            // Get writeable copy, modify and save
            parent      = parent.AsWritable <Folder>( );
            parent.Name = "Name2";
            parent.Save( );

            // Assert that the parent still has the relationship
            parent = Entity.Get <Folder>(parent.Id);
            Assert.AreEqual(1, parent.FolderContents.Count);

            child.Delete( );
            parent.AsWritable( ).Delete( );
        }