Example #1
0
        public void Test_GentleRelation()
        {
            Role r1 = fixedRoles[1];

            // create a user with a known id
            u1 = new User("John", "Doe", Roles.Customer);
            u1.Persist();
            // create 1:n type list
            GentleRelation list = new GentleRelation(typeof(UserRole), u1, typeof(Role));

            Assert.AreEqual(0, list.Count, "Relation table not empty.");
            // verify add
            list.Add(r1);
            list.Add(fixedRoles[2]);
            Assert.AreEqual(2, list.Count, "Wrong number of elements in relation table.");
            // verify read upon create
            list = new GentleRelation(typeof(UserRole), u1, typeof(Role));
            Assert.AreEqual(2, list.Count, "Elements in relation table not automatically retrieved.");
            // verify remove
            list.Remove(r1);
            Assert.AreEqual(1, list.Count, "Relation element was not removed from list.");
            list.Remove(fixedRoles[2]);
            Assert.AreEqual(0, list.Count, "Relation element was not removed from list.");
            list = new GentleRelation(typeof(UserRole), u1, typeof(Role));
            Assert.AreEqual(0, list.Count, "Relation element was not removed from database.");
            u1.Remove();
        }
Example #2
0
		public void Test_GentleRelation()
		{
			Role r1 = fixedRoles[ 1 ];
			// create a user with a known id
			u1 = new User( "John", "Doe", Roles.Customer );
			u1.Persist();
			// create 1:n type list
			GentleRelation list = new GentleRelation( typeof(UserRole), u1, typeof(Role) );
			Assert.AreEqual( 0, list.Count, "Relation table not empty." );
			// verify add
			list.Add( r1 );
			list.Add( fixedRoles[ 2 ] );
			Assert.AreEqual( 2, list.Count, "Wrong number of elements in relation table." );
			// verify read upon create
			list = new GentleRelation( typeof(UserRole), u1, typeof(Role) );
			Assert.AreEqual( 2, list.Count, "Elements in relation table not automatically retrieved." );
			// verify remove
			list.Remove( r1 );
			Assert.AreEqual( 1, list.Count, "Relation element was not removed from list." );
			list.Remove( fixedRoles[ 2 ] );
			Assert.AreEqual( 0, list.Count, "Relation element was not removed from list." );
			list = new GentleRelation( typeof(UserRole), u1, typeof(Role) );
			Assert.AreEqual( 0, list.Count, "Relation element was not removed from database." );
			u1.Remove();
		}