* Web.csproj: * instdbws.sql: * packages.config: * TestByteA.cs: * App.master: * MyClass.cs: * LocalizedText.resx: * Index.aspx: * LocalizedText.fr.resx: * packages.config: * Details.aspx: * packages.config: * packages.config: * packages.config: * EventPub.aspx: * LocalizedText.Designer.cs: * FileSystemController.cs: * FrontOfficeController.cs: * NpgsqlContentProvider.cs: * ITContentProvider.csproj: * FileSystemManager.cs: * Circle.cs: * YaEvent.cs: * NpgsqlBlogProvider.csproj: * NpgsqlMRPProviders.csproj: * EventPub.cs: * NpgsqlContentProvider.csproj: * EventType.cs: * UserPrefs.cs: * CalendarController.cs: * EstablishmentType.cs: * ITCPNpgsqlProvider.cs: * NpgsqlBlogProvider.cs: * NpgsqlRoleProvider.cs: * NpgsqlProfileProvider.cs: * NpgsqlMembershipProvider.cs: Npgsql Command.Parameters.Add is obsolete * Commande.cs: FileSystem ctor needs a format parameter in order to use path by membership * google-services.json: intented to be used to build android application able to receive push notification via GCM
89 lines
No EOL
2.2 KiB
C#
89 lines
No EOL
2.2 KiB
C#
#if TEST
|
|
using NUnit.Framework;
|
|
using System;
|
|
using System.Configuration;
|
|
using Npgsql;
|
|
|
|
namespace Yavsc
|
|
{
|
|
[TestFixture ()]
|
|
public class TestByteA: IDisposable
|
|
{
|
|
//string cnxName = "yavsc";
|
|
string ConnectionString { get {
|
|
return "Server=127.0.0.1;Port=5432;Database=mae;User Id=mae;Password=admin;Encoding=Unicode;" ;
|
|
// return ConfigurationManager.ConnectionStrings [cnxName].ConnectionString;
|
|
|
|
} }
|
|
|
|
[TestFixtureSetUp]
|
|
public void Init()
|
|
{
|
|
// create the table
|
|
Console.WriteLine ("cnx:"+ConnectionString);
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (ConnectionString))
|
|
{
|
|
cnx.Open ();
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
cmd.CommandText = "drop table testbytea";
|
|
try { cmd.ExecuteNonQuery (); }
|
|
catch (NpgsqlException) {
|
|
}
|
|
cmd.CommandText = "create table testbytea( t bytea )";
|
|
cmd.ExecuteNonQuery ();
|
|
}
|
|
}
|
|
}
|
|
|
|
[Test(Description="Test storing a byte array in a Postgresql table field")]
|
|
public void TestStoreByteA ()
|
|
{
|
|
byte []a = new byte[3];
|
|
a[0]=1;
|
|
a[1]=2;
|
|
a[2]=3;
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (ConnectionString)) {
|
|
cnx.Open ();
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ())
|
|
{
|
|
cmd.CommandText = "insert into testbytea (t) values (@tv)";
|
|
cmd.Parameters.AddWithValue ("@tv", a);
|
|
cmd.ExecuteNonQuery ();
|
|
}
|
|
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ())
|
|
{
|
|
cmd.CommandText = "select t from testbytea";
|
|
cmd.Parameters.AddWithValue ("@tv", a);
|
|
|
|
NpgsqlDataReader rdr = cmd.ExecuteReader ();
|
|
if (!rdr.Read ())
|
|
throw new Exception ("Read failed");
|
|
int i = rdr.GetOrdinal ("t");
|
|
byte []rded = (byte[]) rdr.GetValue (i);
|
|
if (rded.Length!=a.Length)
|
|
throw new Exception("Lengthes don't match");
|
|
}
|
|
}
|
|
}
|
|
|
|
#region IDisposable implementation
|
|
|
|
[TestFixtureTearDown]
|
|
public void Dispose ()
|
|
{
|
|
// drop the table
|
|
using (NpgsqlConnection cnx = new NpgsqlConnection (ConnectionString)) {
|
|
cnx.Open ();
|
|
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
|
|
cmd.CommandText = "drop table testbytea";
|
|
cmd.ExecuteNonQuery ();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#endif |