Example #1
0
		public void TestOrderByRetrieval()
		{
			GentleSqlFactory sf = Broker.GetSqlFactory();
			// first verify that data set is ok for test
			SqlBuilder sb = new SqlBuilder( StatementType.Select, typeof(MailingList) );
			// get ascending
			sb.AddOrderByField( true, "SenderAddress" );
			SqlResult sr = Broker.Execute( sb.GetStatement( true ) );
			Assert.IsTrue( sr.ErrorCode == 0 && sr.RowsContained == MailingList.ListAll.Count,
			               "Wrong number of rows were selected." );
			IList lists = ObjectFactory.GetCollection( typeof(MailingList), sr );
			Assert.IsNotNull( lists, "Test case invalid if row count is not 3." );
			Assert.IsTrue( lists.Count == 3, "Test case invalid if row count is not 3." );
			l1 = lists[ 0 ] as MailingList;
			l2 = lists[ 2 ] as MailingList;
			Assert.IsTrue( l1.SenderAddress.StartsWith( "ann" ), "Test case invalid if row order is wrong." );
			Assert.IsTrue( l2.SenderAddress.StartsWith( "inf" ), "Test case invalid if row order is wrong." );
			// now fetch the reverse ordered list
			sb = new SqlBuilder( StatementType.Select, typeof(MailingList) );
			sb.AddOrderByField( false, "SenderAddress" );
			sr = Broker.Execute( sb.GetStatement( true ) );
			Assert.IsTrue( sr.ErrorCode == 0 && sr.RowsContained == MailingList.ListAll.Count,
			               "Wrong number of rows were selected." );
			IList lists2 = ObjectFactory.GetCollection( typeof(MailingList), sr );
			l1 = lists2[ 0 ] as MailingList;
			l2 = lists2[ 2 ] as MailingList;
			Assert.IsTrue( l1.SenderAddress.StartsWith( "inf" ), "Result set was in wrong order." );
			Assert.IsTrue( l2.SenderAddress.StartsWith( "ann" ), "Result set was in wrong order." );
		}