Files
yavsc/TestAPI/TestByteA.cs
Paul Schneider d04a68db01 Bug & layout fixes
* Index.aspx:
* Title.aspx:
* YavscModel.csproj:
* BlogEntry.cs:
* yavsc.scrollnotif.js:
* AccountController.cs:
* BlogEntryCollection.cs: refactoring

* yavsc.tags.js: Implements a js call
to the tag & untag methods

* PostActions.ascx: a better html structure

* BasePost.cs: refactoring:
allows the "PostActions" user control to use a common base object as
  post reference

* NpgsqlBlogProvider.cs: implements the tag methods on db

* ResultPages.cs: A multi-pages result meta info when one page only

* yavsc.circles.js:
* AccountController.cs: code formatting

* BlogsController.cs: Untag a post

* style.css: yastyle, yet a better one.

* BlogsController.cs: View the Title after edition

* App.master:
* UserPosts.aspx: a nicer html structure

* yavsc.js: Fixes notice & dimiss js

* Login.aspx: refactoring

* Edit.aspx: better html

* UserPost.aspx: A promess to be allowed to tag.

* Web.csproj: Adds yavsc.tags.js and yavsc.scrollnotifs.js to the
  project decription.

* BlogManager.cs: Makes the blog manager expose of the new `UnTag`
  method

* BlogProvider.cs: introduces a method to `untag`

* FindBlogEntryFlags.cs: Find post entry by tag

* LocalizedText.resx:
* LocalizedText.Designer.cs: new translations: - "Tag"
- "Edit"

* LocalizedText.fr.resx:
* LocalizedText.fr.Designer.cs: nouvelles traductions: - "Tag"
- "Edit"

* Profile.cs: a nicer stack trace at buggy usage
2015-10-13 22:53:39 +02:00

90 lines
2.2 KiB
C#

#if TEST
using NUnit.Framework;
using System;
using Npgsql;
using System.Web.Configuration;
namespace Yavsc
{
[TestFixture ()]
public class TestByteA: IDisposable
{
string cnxName = "yavsc";
string ConnectionString { get {
return "Server=127.0.0.1;Port=5432;Database=YavscDev;User Id=yavscdev;Password=admin;Encoding=Unicode;" ;
// Why? not this : return WebConfigurationManager.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