Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 9f4d6c9

Browse files
committed
Failing test to demonstrate byte[] serialization/deserialization problem.
1 parent 9300fd0 commit 9f4d6c9

File tree

1 file changed

+111
-1
lines changed

1 file changed

+111
-1
lines changed

src/ServiceStack.OrmLite.PostgreSQL.Tests/TypeWithByteArrayFieldTests.cs

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace ServiceStack.OrmLite.PostgreSQL.Tests
55
{
66
public class TypeWithByteArrayFieldTests : OrmLiteTestBase
7-
{
7+
{
88
[Test]
99
public void CanInsertAndSelectByteArray()
1010
{
@@ -21,6 +21,116 @@ public void CanInsertAndSelectByteArray()
2121
Assert.AreEqual(orig.Id, target.Id);
2222
Assert.AreEqual(orig.Content, target.Content);
2323
}
24+
}
25+
26+
[Test]
27+
public void CanInsertAndSelectByteArray__manual_insert__manual_select()
28+
{
29+
var orig = new TypeWithByteArrayField { Id = 1, Content = new byte[] { 0, 17, 0, 17, 0, 7 } };
30+
31+
using(var db = ConnectionString.OpenDbConnection()) {
32+
//insert and select manually - ok
33+
db.CreateTable<TypeWithByteArrayField>(true);
34+
_insertManually(orig, db);
35+
36+
_selectAndVerifyManually(orig, db);
37+
}
38+
}
39+
40+
[Test]
41+
public void CanInsertAndSelectByteArray__InsertParam_insert__manual_select()
42+
{
43+
var orig = new TypeWithByteArrayField { Id = 1, Content = new byte[] { 0, 17, 0, 17, 0, 7 } };
44+
45+
using(var db = ConnectionString.OpenDbConnection()) {
46+
//insert using InsertParam, and select manually - ok
47+
db.CreateTable<TypeWithByteArrayField>(true);
48+
db.InsertParam(orig);
49+
50+
_selectAndVerifyManually(orig, db);
51+
}
52+
}
53+
54+
[Test]
55+
public void CanInsertAndSelectByteArray__InsertParam_insert__GetById_select()
56+
{
57+
var orig = new TypeWithByteArrayField { Id = 1, Content = new byte[] { 0, 17, 0, 17, 0, 7 } };
58+
59+
using(var db = ConnectionString.OpenDbConnection()) {
60+
//InsertParam + GetByID - fails
61+
db.CreateTable<TypeWithByteArrayField>(true);
62+
db.InsertParam(orig);
63+
64+
var target = db.GetById<TypeWithByteArrayField>(orig.Id);
65+
66+
Assert.AreEqual(orig.Id, target.Id);
67+
Assert.AreEqual(orig.Content, target.Content);
68+
}
69+
}
70+
71+
[Test]
72+
public void CanInsertAndSelectByteArray__Insert_insert__GetById_select()
73+
{
74+
var orig = new TypeWithByteArrayField { Id = 1, Content = new byte[] { 0, 17, 0, 17, 0, 7 } };
75+
76+
using(var db = ConnectionString.OpenDbConnection()) {
77+
//InsertParam + GetByID - fails
78+
db.CreateTable<TypeWithByteArrayField>(true);
79+
db.Insert(orig);
80+
81+
var target = db.GetById<TypeWithByteArrayField>(orig.Id);
82+
83+
Assert.AreEqual(orig.Id, target.Id);
84+
Assert.AreEqual(orig.Content, target.Content);
85+
}
86+
}
87+
88+
[Test]
89+
public void CanInsertAndSelectByteArray__Insert_insert__manual_select()
90+
{
91+
var orig = new TypeWithByteArrayField { Id = 1, Content = new byte[] { 0, 17, 0, 17, 0, 7 } };
92+
93+
using(var db = ConnectionString.OpenDbConnection()) {
94+
//InsertParam + GetByID - fails
95+
db.CreateTable<TypeWithByteArrayField>(true);
96+
db.Insert(orig);
97+
98+
_selectAndVerifyManually(orig, db);
99+
}
100+
}
101+
102+
private static void _selectAndVerifyManually(TypeWithByteArrayField orig, System.Data.IDbConnection db)
103+
{
104+
using(var cmd = db.CreateCommand()) {
105+
cmd.CommandText = @"select ""Content"" from ""TypeWithByteArrayField"" where ""Id"" = 1 --manual select";
106+
using(var reader = cmd.ExecuteReader()) {
107+
reader.Read();
108+
var ba = reader["Content"] as byte[];
109+
Assert.AreEqual(orig.Content.Length, ba.Length);
110+
Assert.AreEqual(orig.Content, ba);
111+
}
112+
}
113+
}
114+
115+
private static void _insertManually(TypeWithByteArrayField orig, System.Data.IDbConnection db)
116+
{
117+
using(var cmd = db.CreateCommand()) {
118+
cmd.CommandText = @"INSERT INTO ""TypeWithByteArrayField"" (""Id"",""Content"") VALUES (@Id, @Content) --manual insert";
119+
120+
var p_id = cmd.CreateParameter();
121+
p_id.ParameterName = "@Id";
122+
p_id.Value = orig.Id;
123+
124+
cmd.Parameters.Add(p_id);
125+
126+
var p_content = cmd.CreateParameter();
127+
p_content.ParameterName = "@Content";
128+
p_content.Value = orig.Content;
129+
130+
cmd.Parameters.Add(p_content);
131+
132+
cmd.ExecuteNonQuery();
133+
}
24134
}
25135
}
26136

0 commit comments

Comments
 (0)