1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
// SqliteDataAdapterUnitTests.cs - NUnit Test Cases for Mono.Data.Sqlite.SqliteDataAdapter
//
// Author(s): Thomas Zoechling <thomas.zoechling@gmx.at>
using System;
using System.Data;
using System.IO;
using System.Text;
using Mono.Data.Sqlite;
using NUnit.Framework;
namespace MonoTests.Mono.Data.Sqlite
{
[TestFixture]
public class SqliteDataAdapterUnitTests
{
string _uri;
string _connectionString;
SqliteConnection _conn;
[SetUp]
public void SetUp ()
{
_uri = Path.GetTempFileName ();
_connectionString = "URI=file://" + _uri + ", version=3";
_conn = new SqliteConnection (_connectionString);
}
[TearDown]
public void TearDown ()
{
if (File.Exists (_uri))
File.Delete (_uri);
}
SqliteDataAdapter PrepareDataAdapter()
{
SqliteCommand select = new SqliteCommand("SELECT t, f, i, b FROM t1",_conn);
SqliteCommand update = new SqliteCommand("UPDATE t1 SET t = :textP, f = :floatP, i = :integerP, n=:blobP WHERE t = :textP ");
update.Connection=_conn;
SqliteCommand delete = new SqliteCommand("DELETE FROM t1 WHERE t = :textP");
delete.Connection=_conn;
SqliteCommand insert = new SqliteCommand("INSERT INTO t1 (t, f, i, b ) VALUES(:textP,:floatP,:integerP,:blobP)");
insert.Connection=_conn;
SqliteDataAdapter custDA = new SqliteDataAdapter(select);
SqliteParameter textP = new SqliteParameter();
textP.ParameterName = "textP";
textP.SourceColumn = "t";
SqliteParameter floatP = new SqliteParameter();
floatP.ParameterName = "floatP";
floatP.SourceColumn = "f";
SqliteParameter integerP = new SqliteParameter();
integerP.ParameterName ="integerP";
integerP.SourceColumn = "i";
SqliteParameter blobP = new SqliteParameter();
blobP.ParameterName = "blobP";
blobP.SourceColumn = "b";
update.Parameters.Add(textP);
update.Parameters.Add(floatP);
update.Parameters.Add(integerP);
update.Parameters.Add(blobP);
delete.Parameters.Add(textP);
insert.Parameters.Add(textP);
insert.Parameters.Add(floatP);
insert.Parameters.Add(integerP);
insert.Parameters.Add(blobP);
custDA.UpdateCommand = update;
custDA.DeleteCommand = delete;
custDA.InsertCommand = insert;
return custDA;
}
[Test]
[Category ("NotWorking")]
public void GetSchemaTable()
{
_conn.ConnectionString = _connectionString;
SqliteDataReader reader = null;
using (_conn)
{
_conn.Open ();
SqliteCommand cmd = (SqliteCommand) _conn.CreateCommand ();
cmd.CommandText = "select * from t1";
reader = cmd.ExecuteReader ();
try
{
DataTable dt = reader.GetSchemaTable ();
Assert.IsNotNull (dt, "#GS1 should return valid table");
Assert.IsTrue (dt.Rows.Count > 0, "#GS2 should return with rows ;-)");
}
finally
{
if (reader != null && !reader.IsClosed)
reader.Close ();
_conn.Close ();
}
}
}
[Test]
[Category ("NotWorking")]
public void DataAdapterRandomValues()
{
SqliteDataAdapter da = PrepareDataAdapter();
DataSet ds = new DataSet();
int i = 0;
Random random = new Random();
using(_conn)
{
_conn.Open();
da.Fill(ds);
for(; i<300;i++)
{
DataRow dr = ds.Tables[0].NewRow();
foreach(DataColumn dc in ds.Tables[0].Columns)
{
switch(dc.DataType.Name)
{
case "String":
{
int ml=0;
if(dc.MaxLength!=-1)
{
ml=dc.MaxLength;
}
else
{
ml=256;
}
StringBuilder builder = new StringBuilder(ml);
for (int k=0; k < random.Next(ml); k++)
{
builder.Append((char)random.Next(65536));
}
string curs = builder.ToString();
dr[dc]=curs;
break;
}
case "Int32":
{
dr[dc]=random.Next(65536);
break;
}
case "Int64":
{
dr[dc]=Convert.ToInt64(random.Next(65536));
break;
}
}
}
ds.Tables[0].Rows.Add(dr);
}
int res = da.Update(ds);
Assert.AreEqual(i,res);
}
}
}
}
|