示例#1
0
        public void Test_GentleList()
        {
            Role r1 = fixedRoles[1];
            Role r2 = fixedRoles[3];

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

            Assert.AreEqual(0, list.Count, "Relation table not empty.");
            // verify add
            list.Add(new UserRole(u1.Id, r1.Id));
            Assert.AreEqual(1, list.Count, "No element in relation table.");
            list.Add(new UserRole(u1.Id, r2.Id));
            Assert.AreEqual(2, list.Count, "Wrong number of elements in relation table.");
            // verify read upon create
            list = new GentleList(typeof(UserRole), u1);
            Assert.AreEqual(2, list.Count, "Elements in relation table was not automatically retrieved.");
            // verify remove
            list.Remove(list[0]);
            Assert.AreEqual(1, list.Count, "Relation element was not removed from list.");
            list.Remove(list[0]);
            Assert.AreEqual(0, list.Count, "Relation element was not removed from list.");
            list = new GentleList(typeof(UserRole), u1);
            Assert.AreEqual(0, list.Count, "Relation element was not removed from database.");
            u1.Remove();
        }
示例#2
0
        public void TestGentleListNoParent()
        {
            IList      dblist = Broker.RetrieveList(typeof(MailingList));
            GentleList list   = new GentleList(typeof(MailingList));

            Assert.AreEqual(dblist.Count, list.Count, "GentleList did not retrieve same object count as Broker.RetrieveList");
            // verify backwards compatibility (i.e. that the list performs object uniqing for items added more than once)
            Broker.RetrieveList(typeof(MailingList), list);
            Assert.AreEqual(dblist.Count, list.Count, "GentleList does not perform object uniqing as expected.");
        }
示例#3
0
 public void TestGentleListWithConcurrency()
 {
     if (GentleSettings.ConcurrencyControl)
     {
         MailingList list    = MailingList.Retrieve(1);
         GentleList  members = new GentleList(typeof(MemberCC), list);
         Assert.AreEqual(2, members.Count, "List not initialized.");
         IList check = Broker.RetrieveList(typeof(MemberCC), list.GetKey());
         Assert.AreEqual(2, check.Count, "List contents dubious.");
     }
 }
示例#4
0
        public void Test_GentleListWithCaching()
        {
            // enable all caching
            GentleSettings.CacheObjects       = true;
            GentleSettings.CacheStatements    = true;
            GentleSettings.SkipQueryExecution = true;
            CacheManager.Clear();

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

            Assert.AreEqual(0, list.Count, "Test requires that tables are initially empty.");
            // verify add
            Role r1 = new Role(0, "Role 1");

            r1.Persist();
            list.Add(r1);
            Assert.AreEqual(1, list.Count, "No element in relation table.");
            Role r2 = new Role(0, "Role 2");

            r2.Persist();
            list.Add(r2);
            Assert.AreEqual(2, list.Count, "Wrong number of elements in relation table.");
            // verify read upon create
            list = new GentleList(typeof(Role), u1, typeof(UserRole));
            Assert.AreEqual(2, list.Count, "Elements in relation table were not automatically retrieved.");
            // verify remove
            list.Remove(r1);
            Assert.AreEqual(1, list.Count, "Element was not removed from list.");
            // verify add after remove
            Role r3 = new Role(0, "Role 3");

            r3.Persist();
            list.Add(r3);
            Assert.AreEqual(2, list.Count, "Wrong number of elements in relation table.");
            // remove remaining elements
            list.Remove(r2);
            list.Remove(r3);
            Assert.AreEqual(0, list.Count, "Relation element was not removed from list.");
            list = new GentleList(typeof(UserRole), u1);
            Assert.AreEqual(0, list.Count, "Relation element was not removed from database.");
            u1.Remove();
        }
示例#5
0
		public void TestGentleListNoParent()
		{
			IList dblist = Broker.RetrieveList( typeof(MailingList) );
			GentleList list = new GentleList( typeof(MailingList) );
			Assert.AreEqual( dblist.Count, list.Count, "GentleList did not retrieve same object count as Broker.RetrieveList" );
			// verify backwards compatibility (i.e. that the list performs object uniqing for items added more than once)
			Broker.RetrieveList( typeof(MailingList), list );
			Assert.AreEqual( dblist.Count, list.Count, "GentleList does not perform object uniqing as expected." );
		}
示例#6
0
		public void Test_GentleListWithCaching()
		{
			// enable all caching 
			GentleSettings.CacheObjects = true;
			GentleSettings.CacheStatements = true;
			GentleSettings.SkipQueryExecution = true;
			CacheManager.Clear();

			// create a user with a known id
			u1 = new User( "John", "Doe", Roles.Customer );
			u1.Persist();
			// create n:m type list
			GentleList list = new GentleList( typeof(Role), u1, typeof(UserRole) );
			Assert.AreEqual( 0, list.Count, "Test requires that tables are initially empty." );
			// verify add
			Role r1 = new Role( 0, "Role 1" );
			r1.Persist();
			list.Add( r1 );
			Assert.AreEqual( 1, list.Count, "No element in relation table." );
			Role r2 = new Role( 0, "Role 2" );
			r2.Persist();
			list.Add( r2 );
			Assert.AreEqual( 2, list.Count, "Wrong number of elements in relation table." );
			// verify read upon create
			list = new GentleList( typeof(Role), u1, typeof(UserRole) );
			Assert.AreEqual( 2, list.Count, "Elements in relation table were not automatically retrieved." );
			// verify remove
			list.Remove( r1 );
			Assert.AreEqual( 1, list.Count, "Element was not removed from list." );
			// verify add after remove
			Role r3 = new Role( 0, "Role 3" );
			r3.Persist();
			list.Add( r3 );
			Assert.AreEqual( 2, list.Count, "Wrong number of elements in relation table." );
			// remove remaining elements
			list.Remove( r2 );
			list.Remove( r3 );
			Assert.AreEqual( 0, list.Count, "Relation element was not removed from list." );
			list = new GentleList( typeof(UserRole), u1 );
			Assert.AreEqual( 0, list.Count, "Relation element was not removed from database." );
			u1.Remove();
		}
示例#7
0
		public void Test_GentleList()
		{
			Role r1 = fixedRoles[ 1 ];
			Role r2 = fixedRoles[ 3 ];
			// create a user with a known id
			u1 = new User( "John", "Doe", Roles.Customer );
			u1.Persist();
			// create 1:n type list
			GentleList list = new GentleList( typeof(UserRole), u1 );
			Assert.AreEqual( 0, list.Count, "Relation table not empty." );
			// verify add
			list.Add( new UserRole( u1.Id, r1.Id ) );
			Assert.AreEqual( 1, list.Count, "No element in relation table." );
			list.Add( new UserRole( u1.Id, r2.Id ) );
			Assert.AreEqual( 2, list.Count, "Wrong number of elements in relation table." );
			// verify read upon create
			list = new GentleList( typeof(UserRole), u1 );
			Assert.AreEqual( 2, list.Count, "Elements in relation table was not automatically retrieved." );
			// verify remove
			list.Remove( list[ 0 ] );
			Assert.AreEqual( 1, list.Count, "Relation element was not removed from list." );
			list.Remove( list[ 0 ] );
			Assert.AreEqual( 0, list.Count, "Relation element was not removed from list." );
			list = new GentleList( typeof(UserRole), u1 );
			Assert.AreEqual( 0, list.Count, "Relation element was not removed from database." );
			u1.Remove();
		}
示例#8
0
		public void TestGentleListWithConcurrency()
		{
			if( GentleSettings.ConcurrencyControl )
			{
				MailingList list = MailingList.Retrieve( 1 );
				GentleList members = new GentleList( typeof(MemberCC), list );
				Assert.AreEqual( 2, members.Count, "List not initialized." );
				IList check = Broker.RetrieveList( typeof(MemberCC), list.GetKey() );
				Assert.AreEqual( 2, check.Count, "List contents dubious." );
			}
		}