[MonoDevelop] Tests for Db providers in Mono.Data.Sql

Daniel Morgan danielmorgan at verizon.net
Sun Aug 21 01:16:42 EDT 2005


I have created some tests for the sybase, oracle, and firebird db 
providers in Mono.Data.Sql which is part of the MonoQuery add-in.

The tests are not nunit2, but they should give you an idea on how to use 
them.

-------------- next part --------------
// test-sybase-1.cs
//
// $ mcs test-sybase-1.cs /r:System.Data /r:Mono.Data.SybaseClient /r:Mono.Data.Sql
//

using System;
using System.Data;
using Mono.Data.SybaseClient;
using System.Text;
using Mono.Data.Sql;

namespace Mono.Data.Sql.Tests
{
	public class CreateProviderTest
	{
		static SybaseDbProvider provider = null;

		static TableSchema[] tables = null;
		static ViewSchema[] views = null;
		
		public static void Main(string[] args) 
		{	
			Console.WriteLine("Test Sybase Meta Data Provider...");

			provider = new SybaseDbProvider ();
			provider.ConnectionString = "Server=DANPC,5000;Database=testdb;User ID=sa;Password=;";

			Console.WriteLine("Opening database...");
			provider.Open ();
			
			Console.WriteLine("Do tests...");			

			ListTables ();
			ListViews ();

			tables = null;
			views = null;

			Console.WriteLine("Close provider...");			

			provider.Close();

			Console.WriteLine("Test Done.");
		}
		
		public static void ListTables ()
		{
			Console.WriteLine("List Tables...");
			tables = provider.GetTables ();
			Console.WriteLine("Tables Found: {0}", tables.Length);
			
			for (int i = 0; i < tables.Length; i++) {
				TableSchema table = tables[i];
				Console.WriteLine("  Table{0} Owner: {1} Name: {2} ", 
					i, table.OwnerName, table.Name);
				if (i == 0)
					ListTableColumns(table);
			}
		}

		public static void ListTableColumns (TableSchema table)
		{
			ColumnSchema[] columns = table.Columns;

			for (int c = 0; c < columns.Length; c++) {
				ColumnSchema column = columns[c];
				Console.WriteLine("Column{0}: ", c);
				Console.WriteLine("  Name: {0}", column.Name);
				Console.WriteLine("  DataTypeName: {0}", column.DataTypeName);
				Console.WriteLine("  Length: {0}", column.Length);
				//Console.WriteLine("  Precision: {0}", column.Precision);
				//Console.WriteLine("  Scale: {0}", column.Scale);
				//Console.WriteLine("  NotNull: {0}", column.NotNull);
				Console.WriteLine("");
			}
		}

		public static void ListViews () 
		{
			Console.WriteLine("List Views...");

			views = provider.GetViews ();
			for (int v = 0; v < views.Length; v++) {
				ViewSchema view = views[v];
				Console.WriteLine("View{0}: " ,v);
				Console.WriteLine("  Name: {0}", view.Name);
				Console.WriteLine("  Owner: {0}", view.OwnerName);
				if (v == 0)
					ListView (view);
			}
		}

		public static void ListView (ViewSchema view) 
		{
			Console.WriteLine("View Definition:\n" + view.Definition);
		}
	}
}

-------------- next part --------------
// test-firebird-1.cs
//
// $ mcs test-firebird-1.cs /r:System.Data /r:FirebirdSql.Data.Firebird /r:Mono.Data.Sql
//

using System;
using System.Data;
using FirebirdSql.Data.Firebird;
using System.Text;
using Mono.Data.Sql;

namespace Mono.Data.Sql.Tests
{
	public class CreateProviderTest
	{
		static FirebirdDbProvider provider = null;

		static TableSchema[] tables = null;
		static ViewSchema[] views = null;
		
		public static void Main(string[] args) 
		{	
			Console.WriteLine("Test Firebird Meta Data Provider...");

			provider = new FirebirdDbProvider ();
			provider.ConnectionString = @"Database=D:\PROGRA~1\Firebird\Firebird_1_5\examples\EMPLOYEE.FDB;User=SYSDBA;Password=masterkey;Dialect=3;Server=localhost";

			Console.WriteLine("Opening database...");
			provider.Open ();
			
			Console.WriteLine("Do tests...");			

			ListTables ();
			ListViews ();

			tables = null;
			views = null;

			Console.WriteLine("Close provider...");			

			provider.Close();

			Console.WriteLine("Test Done.");
		}
		
		public static void ListTables ()
		{
			Console.WriteLine("List Tables...");
			tables = provider.GetTables ();
			Console.WriteLine("Tables Found: {0}", tables.Length);
			
			for (int i = 0; i < tables.Length; i++) {
				TableSchema table = tables[i];
				Console.WriteLine("  Table{0} Owner: {1} Name: {2} ", 
					i, table.OwnerName, table.Name);
				if (i == 0)
					ListTableColumns(table);
			}
		}

		public static void ListTableColumns (TableSchema table)
		{
			ColumnSchema[] columns = table.Columns;

			for (int c = 0; c < columns.Length; c++) {
				ColumnSchema column = columns[c];
				Console.WriteLine("Column{0}: ", c);
				Console.WriteLine("  Name: {0}", column.Name);
				Console.WriteLine("  DataTypeName: {0}", column.DataTypeName);
				Console.WriteLine("  Length: {0}", column.Length);
				//Console.WriteLine("  Precision: {0}", column.Precision);
				//Console.WriteLine("  Scale: {0}", column.Scale);
				//Console.WriteLine("  NotNull: {0}", column.NotNull);
				Console.WriteLine("");
			}
		}

		public static void ListViews () 
		{
			Console.WriteLine("List Views...");

			views = provider.GetViews ();
			for (int v = 0; v < views.Length; v++) {
				ViewSchema view = views[v];
				Console.WriteLine("View{0}: " ,v);
				Console.WriteLine("  Name: {0}", view.Name);
				Console.WriteLine("  Owner: {0}", view.OwnerName);
				if (v == 0)
					ListView (view);
			}
		}

		public static void ListView (ViewSchema view) 
		{
			Console.WriteLine("View Definition:\n" + view.Definition);
		}
	}
}

-------------- next part --------------
// test-oracle-1.cs
//
// $ mcs test-oracle-1.cs /r:System.Data /r:System.Data.OracleClient /r:Mono.Data.Sql
//

using System;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using Mono.Data.Sql;

namespace Mono.Data.Sql.Tests
{
	public class CreateProviderTest
	{
		static OracleDbProvider provider = null;

		static TableSchema[] tables = null;
		static ViewSchema[] views = null;
		
		public static void Main(string[] args) 
		{	
			Console.WriteLine("Test Oracle Meta Data Provider...");

			provider = new OracleDbProvider ();
			provider.ConnectionString = "Data Source=palis;user id=scott;password=tiger";
			provider.Open ();
			
			ListTables ();
			ListViews ();

			tables = null;
			views = null;

			provider.Close();

			Console.WriteLine("Test Done.");
		}
		
		public static void ListTables ()
		{
			Console.WriteLine("List Tables...");
			tables = provider.GetTables ();
			Console.WriteLine("Tables Found: {0}", tables.Length);
			
			for (int i = 0; i < tables.Length; i++) {
				TableSchema table = tables[i];
				Console.WriteLine("  Table{0} Owner: {1} Name: {2} TableSpace: {3}", 
					i, table.OwnerName, table.Name, table.TableSpaceName);
				if (i == 0)
					ListTableColumns(table);
			}
		}

		public static void ListTableColumns (TableSchema table)
		{
			ColumnSchema[] columns = table.Columns;

			for (int c = 0; c < columns.Length; c++) {
				ColumnSchema column = columns[c];
				Console.WriteLine("Column{0}: ", c);
				Console.WriteLine("  Name: {0}", column.Name);
				Console.WriteLine("  DataTypeName: {0}", column.DataTypeName);
				Console.WriteLine("  Length: {0}", column.Length);
				Console.WriteLine("  Precision: {0}", column.Precision);
				Console.WriteLine("  Scale: {0}", column.Scale);
				Console.WriteLine("  NotNull: {0}", column.NotNull);
				Console.WriteLine("");
			}
		}

		public static void ListViews () 
		{
			Console.WriteLine("List Views...");

			views = provider.GetViews ();
			for (int v = 0; v < views.Length; v++) {
				ViewSchema view = views[v];
				Console.WriteLine("View{0}: " ,v);
				Console.WriteLine("  Name: {0}", view.Name);
				Console.WriteLine("  Owner: {0}", view.OwnerName);
				if (v == 0)
					ListView (view);
			}
		}

		public static void ListView (ViewSchema view) 
		{
			Console.WriteLine("View Definition:\n" + view.Definition);
		}
	}
}



More information about the Monodevelop-list mailing list