public void State (TestCaseResult result)
		{
			string host = TestSettings.GetString ("HOST");
			string connectionString = "HOST=" + host + ";UID=dba;PWD=dba;";
			VirtuosoConnection conn = new VirtuosoConnection (connectionString);
			try
			{
				result.FailIfNotEqual (ConnectionState.Closed, conn.State);
				conn.Open ();
				result.FailIfNotEqual (ConnectionState.Open, conn.State);
				conn.Close ();
				result.FailIfNotEqual (ConnectionState.Closed, conn.State);
			}
			finally
			{
				conn.Dispose ();
			}
		}
		private void CheckParameter (
			TestCaseResult result,
			VirtuosoParameter parameter,
			string parameterName,
			ParameterDirection direction,
			VirtDbType vdbType,
			DbType dbType,
			int size,
			byte precision,
			byte scale)
		{
			result.FailIfNotEqual (this, "ParameterName", parameterName, parameter.ParameterName);
			result.FailIfNotEqual (this, parameterName + ".Direction", direction, parameter.Direction);
			result.FailIfNotEqual (this, parameterName + ".VirtDbType", vdbType, parameter.VirtDbType);
			result.FailIfNotEqual (this, parameterName + ".DbType", dbType, parameter.DbType);
			result.FailIfNotEqual (this, parameterName + ".Size", size, parameter.Size);
			result.FailIfNotEqual (this, parameterName + ".Precision", precision, parameter.Precision);
			result.FailIfNotEqual (this, parameterName + ".Scale", scale, parameter.Scale);
		}
		public void DeriveParamters (TestCaseResult result)
		{
			DropProcedure ();
			ExecuteNonQuery (
				"create function BAR (in X integer, out Y integer, inout Z integer, in V varchar(20), in W nvarchar(20), in D numeric(20, 5)) returns real\n" +
				"{\n" +
				"  return 0.0;\n" +
				"}\n"
				);

			VirtuosoCommand command = connection.CreateCommand ();
			command.CommandType = CommandType.StoredProcedure;
			command.CommandText = "BAR";

			try
			{
				VirtuosoCommandBuilder.DeriveParameters (command);
				result.FailIfNotEqual ("Parameter Count", 7, command.Parameters.Count);
				CheckParameter (result,	command.Parameters[0],
					"ReturnValue", ParameterDirection.ReturnValue, VirtDbType.Real, DbType.Single,
					4, 0, 0); // FIXME: The precision should be 7.
				CheckParameter (result,	command.Parameters[1],
					"X", ParameterDirection.Input, VirtDbType.Integer, DbType.Int32,
					4, 10, 0);
				CheckParameter (result,	command.Parameters[2],
					"Y", ParameterDirection.Output, VirtDbType.Integer, DbType.Int32,
					4, 10, 0);
				CheckParameter (result, command.Parameters[3],
					"Z", ParameterDirection.InputOutput, VirtDbType.Integer, DbType.Int32,
					4, 10, 0);
				CheckParameter (result, command.Parameters[4],
					"V", ParameterDirection.Input, VirtDbType.VarChar, DbType.AnsiString,
					20, 0, 0);
				CheckParameter (result, command.Parameters[5],
					"W", ParameterDirection.Input, VirtDbType.NVarChar, DbType.String,
					20, 0, 0);
				CheckParameter (result, command.Parameters[6],
					"D", ParameterDirection.Input, VirtDbType.Decimal, DbType.Decimal,
					19, 20, 5);
			}
			finally
			{
				command.Dispose ();
			}
		}
		private void CompareData (TestCaseResult result,
			int row, int column, char[] data,
			long length, long offset)
		{
			DataRow dataRow = checkTable.Rows[row];
			char[] chars = dataRow[column].ToString().ToCharArray();
			char[] expected = new char[length];
			char[] actual = new char[length];
			Array.Copy (chars, (int) offset, expected, 0, (int) length);
			Array.Copy (data, 0, actual, 0, (int) length);
			result.FailIfNotEqual (this, expected, actual);
		}
		private void CompareData (TestCaseResult result,
			int row, int column, byte[] data,
			long length, long offset)
		{
			DataRow dataRow = checkTable.Rows[row];
			byte[] bytes = (byte[]) dataRow[column];
			byte[] expected = new byte[length];
			byte[] actual = new byte[length];
			Array.Copy (bytes, (int) offset, expected, 0, (int) length);
			Array.Copy (data, 0, actual, 0, (int) length);
			result.FailIfNotEqual (this, expected, actual);
		}
		private void CompareSize (TestCaseResult result,
			int row, int column, Selector selector,
			long length, long offset)
		{
			DataRow dataRow = checkTable.Rows[row];
			object columnData = dataRow[column];
			if (selector == Selector.GetBytes)
			{
				byte[] bytes = (byte[]) columnData;
				if (offset > bytes.Length)
					result.FailIfNotEqual (this, 0, length);
				else
					result.FailIfNotEqual (this, bytes.Length - offset, length);
			}
			if (selector == Selector.GetChars)
			{
				char[] chars = columnData.ToString().ToCharArray();
				if (offset > chars.Length)
					result.FailIfNotEqual (this, 0, length);
				else
					result.FailIfNotEqual (this, chars.Length - offset, length);
			}
			/*
			if (selector == Selector.GetValue)
			{
				throw new NotSupportedException ();
			}
			*/
		}
		private void CheckGetData (TestCaseResult result,
			VirtuosoDataReader dr, int column, Selector selector, Sequence sequence)
		{
			string name = dr.GetName (column);
			int tableColumn = checkTable.Columns.IndexOf (name);
			for (int row = 0; dr.Read (); row++)
			{
				//if (dr.IsDBNull (column))
				if (row == 0)
					continue;

				long length;
				if (selector == Selector.GetBytes)
					length = dr.GetBytes (column, 0, null, 0, 0);
				else //if (selector == Selector.GetChars)
					length = dr.GetChars (column, 0, null, 0, 0);

				//Console.WriteLine ("row: {0}", row);
				//Console.WriteLine ("length: {0}", length);

				CompareSize (result, row, tableColumn, selector, length, 0);

				long offset = 0;
				byte[] bytes = new byte[BufferSize];
				char[] chars = new char[BufferSize];
				int count = 0;
				while (offset < length)
				{
					//Console.WriteLine ("offset: {0}", offset);

					long nextLength;
					if (selector == Selector.GetBytes)
					{
						for (int i = 0; i < bytes.Length; i++)
							bytes[i] = 0;
						nextLength = dr.GetBytes (column, offset, bytes, 0, bytes.Length);
					}
					else //if (selector == Selector.GetChars)
					{
						for (int i = 0; i < chars.Length; i++)
							chars[i] = (char) 0;
						nextLength = dr.GetChars (column, offset, chars, 0, chars.Length);
					}

					result.FailIfEqual (this, 0, nextLength);
					if (offset + nextLength < length)
						result.FailIfNotEqual (this, (long) BufferSize, nextLength);
					else
						result.FailIfNotEqual (this, (long) (length - offset), nextLength);

					if (selector == Selector.GetBytes)
						CompareData (result, row, tableColumn, bytes, nextLength, offset);
					else //if (selector == Selector.GetChars)
						CompareData (result, row, tableColumn, chars, nextLength, offset);

					if (sequence == Sequence.GetAll)
					{
						offset += nextLength;
					}
					else if (sequence == Sequence.GetHalf)
					{
						offset += 2 * nextLength;
					}
					else //if (sequence == Sequence.GetTwice)
					{
						count++;
						if (count == 2)
						{
							count = 0;
							offset += 2 * nextLength;
						}
					}
				}
			}
		}
		private void CheckDataSetTable (TestCaseResult result)
		{
			VirtuosoCommand select = connection.CreateCommand ();
			select.CommandText = "select * from foo order by id";

			VirtuosoDataAdapter adapter = new VirtuosoDataAdapter ();
			adapter.SelectCommand = (VirtuosoCommand) select;

			DataSet dataset = new DataSet ();
			adapter.Fill (dataset);

			DataTable table = dataset.Tables["table"];

			result.FailIfNotEqual (checkTable.Rows.Count, table.Rows.Count);
			result.FailIfNotEqual (checkTable.Columns.Count, table.Columns.Count);
			for (int i = 0; i < table.Rows.Count; i++)
			{
				DataRow row = table.Rows[i];
				DataRow checkRow = checkTable.Rows[i];
				for (int j = 0; j < table.Columns.Count; j++)
				{
					string name = table.Columns[j].ColumnName;
					result.FailIfNotEqual (this, "Comparison failed for column " + name + ": ", checkRow[name], row[name]);
				}
			}
		}
예제 #9
0
		public void ResultSetAndOutputParameters (TestCaseResult result)
		{
			DropProcedure ();
			DropProcedure ();
			ExecuteNonQuery (
				"create procedure bar (out x integer)\n" +
				"{\n" +
				"  declare i int;\n" +
				"  result_names (i);\n" +
				"  result (1);\n" +
				"  result (2);\n" +
				"  x := 3;\n" +
				"  return 4;\n" +
				"}\n"
				);

			VirtuosoCommand command = connection.CreateCommand ();
			command.CommandType = CommandType.StoredProcedure;
			command.CommandText = "bar";

			VirtuosoParameter returnValue = command.CreateParameter ();
			returnValue.ParameterName = "ReturnValue";
			returnValue.Direction = ParameterDirection.ReturnValue;
			returnValue.VirtDbType = VirtDbType.Integer;
			command.Parameters.Add (returnValue);

			VirtuosoParameter x = command.CreateParameter ();
			x.ParameterName = "x";
			x.Direction = ParameterDirection.Output;
			x.VirtDbType = VirtDbType.Integer;
			command.Parameters.Add (x);

			VirtuosoDataReader reader = null;
			bool closed = false;
			try
			{
				reader = command.ExecuteReader ();
				result.FailIfNotEqual (1, reader.FieldCount);
				result.FailIfNotEqual ("i", reader.GetName (0).ToLower ());
				result.FailIfNotEqual (typeof (int), reader.GetFieldType (0));
				result.FailIfNotEqual (true, reader.Read ());
				result.FailIfNotEqual (1, reader["i"]);
				result.FailIfNotEqual (true, reader.Read ());
				result.FailIfNotEqual (2, reader["i"]);
				result.FailIfNotEqual (false, reader.Read ());

				reader.Close ();
				closed = true;

				result.FailIfNotEqual ("Out Parameter", 3, x.Value);
				result.FailIfNotEqual ("Return Value", 4, returnValue.Value);
			}
			finally
			{
				if (reader != null && !closed)
					reader.Close ();
				command.Dispose ();
			}
		}
예제 #10
0
		public void MultipleResultSets (TestCaseResult result)
		{
			DropProcedure ();
			ExecuteNonQuery (
				"create procedure bar ()\n" +
				"{\n" +
				"  declare i int;\n" +
				"  declare c char;\n" +
				"  result_names (i);\n" +
				"  result (1);\n" +
				"  result (2);\n" +
				"  end_result ();\n" +
				"  result_names (c);\n" +
				"  result ('a');\n" +
				"  result ('b');\n" +
				"  return 0;\n" +
				"}\n"
				);

			VirtuosoCommand command = connection.CreateCommand ();
			command.CommandType = CommandType.StoredProcedure;
			command.CommandText = "bar";

			VirtuosoDataReader reader = null;
			try
			{
				reader = command.ExecuteReader ();
				result.FailIfNotEqual (1, reader.FieldCount);
				result.FailIfNotEqual ("i", reader.GetName (0).ToLower ());
				result.FailIfNotEqual (typeof (int), reader.GetFieldType (0));
				result.FailIfNotEqual (true, reader.Read ());
				result.FailIfNotEqual (1, reader["i"]);
				result.FailIfNotEqual (true, reader.Read ());
				result.FailIfNotEqual (2, reader["i"]);
				result.FailIfNotEqual (false, reader.Read ());
				result.FailIfNotEqual (true, reader.NextResult ());
				result.FailIfNotEqual (1, reader.FieldCount);
				result.FailIfNotEqual ("c", reader.GetName (0).ToLower ());
				result.FailIfNotEqual (typeof (string), reader.GetFieldType (0));
				result.FailIfNotEqual (true, reader.Read ());
				result.FailIfNotEqual ("a", reader["c"]);
				result.FailIfNotEqual (true, reader.Read ());
				result.FailIfNotEqual ("b", reader["c"]);
				result.FailIfNotEqual (false, reader.NextResult ());
			}
			finally
			{
				if (reader != null)
					reader.Close ();
				command.Dispose ();
			}
		}
예제 #11
0
		public void OutputParameters (TestCaseResult result)
		{
			DropProcedure ();
			ExecuteNonQuery (
				"create procedure bar (in x integer, out y integer, inout z integer)\n" +
				"{\n" +
				"  y := x * 2;\n" +
				"  z := z * 2;\n" +
				"  return y + z;\n" +
				"}\n"
				);

			VirtuosoCommand command = connection.CreateCommand ();
			command.CommandType = CommandType.StoredProcedure;
			command.CommandText = "bar";

			VirtuosoParameter returnValue = command.CreateParameter ();
			returnValue.ParameterName = "ReturnValue";
			returnValue.Direction = ParameterDirection.ReturnValue;
			returnValue.VirtDbType = VirtDbType.Integer;
			command.Parameters.Add (returnValue);

			VirtuosoParameter x = command.CreateParameter ();
			x.ParameterName = "x";
			x.Direction = ParameterDirection.Input;
			x.VirtDbType = VirtDbType.Integer;
			x.Value = 2;
			command.Parameters.Add (x);

			VirtuosoParameter y = command.CreateParameter ();
			y.ParameterName = "y";
			y.Direction = ParameterDirection.Output;
			y.VirtDbType = VirtDbType.Integer;
			command.Parameters.Add (y);

			VirtuosoParameter z = command.CreateParameter ();
			z.ParameterName = "z";
			z.Direction = ParameterDirection.InputOutput;
			z.VirtDbType = VirtDbType.Integer;
			z.Value = 3;
			command.Parameters.Add (z);

			try
			{
				command.ExecuteNonQuery ();
				result.FailIfNotEqual (this, "Return Value", 10, returnValue.Value);
				result.FailIfNotEqual (this, "Out Parameter", 4, y.Value);
				result.FailIfNotEqual (this, "InOut Parameter", 6, z.Value);
			}
			finally
			{
				command.Dispose ();
			}
		}
		public void PersistSecurityInfo (TestCaseResult result)
		{
			string host = TestSettings.GetString ("HOST");
			string connectionString = "HOST=" + host + ";UID=dba;PWD=dba;Persist Security Info=true;";
			VirtuosoConnection conn = new VirtuosoConnection (connectionString);
			try
			{
				result.FailIfNotEqual (connectionString, conn.ConnectionString);
				conn.Open ();
				result.FailIfNotEqual (connectionString, conn.ConnectionString);
				conn.Close ();
				result.FailIfNotEqual (connectionString, conn.ConnectionString);
			}
			finally
			{
				conn.Dispose ();
			}
		}
		public void CheckTable (VirtuosoConnection connection, TestCaseResult result)
		{
			VirtuosoCommand select = connection.CreateCommand ();
			select.CommandText = "select * from foo";

			VirtuosoDataAdapter adapter = new VirtuosoDataAdapter ();
			adapter.SelectCommand = (VirtuosoCommand) select;

			DataSet dataset = new DataSet ();
			adapter.Fill (dataset);

			DataTable table = dataset.Tables["Table"];

			result.FailIfNotEqual (checkTable.Rows.Count, table.Rows.Count);
			result.FailIfNotEqual (checkTable.Columns.Count, table.Columns.Count);
			for (int i = 0; i < table.Rows.Count; i++)
			{
				DataRow row = table.Rows[i];
				DataRow checkRow = checkTable.Rows[i];
				for (int j = 0; j < table.Columns.Count; j++)
				{
					string name = table.Columns[j].ColumnName;
					result.FailIfNotEqual (checkRow[name], row[name]);
				}
			}
		}
예제 #14
0
      public void TestGetValue (TestCaseResult result)
	{
	  InsertRowText ();

	  VirtuosoCommand cmd = connection.CreateCommand ();
	  cmd.CommandText = "select data from xmlt";

	  VirtuosoDataReader rdr = cmd.ExecuteReader ();
	  rdr.Read ();
	  object obj = rdr.GetValue (0);
	  result.FailIfNotEqual (typeof (SqlXml).Name, obj.GetType().Name);
	  SqlXml x = (SqlXml) obj;
	  FailIfXmlNotEqual (result, x.ToString (), TheXml);
	}
예제 #15
0
      private void FailIfXmlNotEqual (TestCaseResult result, String ret, String orig)
	{
	  XmlDocument xd_ret = new XmlDocument ();
	  XmlDocument xd_orig = new XmlDocument ();

	  xd_ret.LoadXml (ret);
	  xd_orig.LoadXml (orig);

	  xd_ret.Normalize ();
	  xd_orig.Normalize ();

	  result.FailIfNotEqual (xd_ret.DocumentElement.OuterXml, xd_orig.DocumentElement.OuterXml);
	}