4
4
namespace ServiceStack . OrmLite . PostgreSQL . Tests
5
5
{
6
6
public class TypeWithByteArrayFieldTests : OrmLiteTestBase
7
- {
7
+ {
8
+ TypeWithByteArrayField getSampleObject ( )
9
+ {
10
+ var testByteArray = new byte [ 256 ] ;
11
+ for ( int i = 0 ; i < 256 ; i ++ ) { testByteArray [ i ] = ( byte ) i ; }
12
+
13
+ return new TypeWithByteArrayField { Id = 1 , Content = testByteArray } ;
14
+ }
15
+
8
16
[ Test ]
9
17
public void CanInsertAndSelectByteArray ( )
10
18
{
11
- var orig = new TypeWithByteArrayField { Id = 1 , Content = new byte [ ] { 0 , 17 , 0 , 17 , 0 , 7 } } ;
19
+ var orig = getSampleObject ( ) ;
12
20
13
21
using ( var db = ConnectionString . OpenDbConnection ( ) )
14
22
{
@@ -26,7 +34,7 @@ public void CanInsertAndSelectByteArray()
26
34
[ Test ]
27
35
public void CanInsertAndSelectByteArray__manual_insert__manual_select ( )
28
36
{
29
- var orig = new TypeWithByteArrayField { Id = 1 , Content = new byte [ ] { 0 , 17 , 0 , 17 , 0 , 7 } } ;
37
+ var orig = getSampleObject ( ) ;
30
38
31
39
using ( var db = ConnectionString . OpenDbConnection ( ) ) {
32
40
//insert and select manually - ok
@@ -40,7 +48,7 @@ public void CanInsertAndSelectByteArray__manual_insert__manual_select()
40
48
[ Test ]
41
49
public void CanInsertAndSelectByteArray__InsertParam_insert__manual_select ( )
42
50
{
43
- var orig = new TypeWithByteArrayField { Id = 1 , Content = new byte [ ] { 0 , 17 , 0 , 17 , 0 , 7 } } ;
51
+ var orig = getSampleObject ( ) ;
44
52
45
53
using ( var db = ConnectionString . OpenDbConnection ( ) ) {
46
54
//insert using InsertParam, and select manually - ok
@@ -54,7 +62,7 @@ public void CanInsertAndSelectByteArray__InsertParam_insert__manual_select()
54
62
[ Test ]
55
63
public void CanInsertAndSelectByteArray__InsertParam_insert__GetById_select ( )
56
64
{
57
- var orig = new TypeWithByteArrayField { Id = 1 , Content = new byte [ ] { 0 , 17 , 0 , 17 , 0 , 7 } } ;
65
+ var orig = getSampleObject ( ) ;
58
66
59
67
using ( var db = ConnectionString . OpenDbConnection ( ) ) {
60
68
//InsertParam + GetByID - fails
@@ -71,7 +79,7 @@ public void CanInsertAndSelectByteArray__InsertParam_insert__GetById_select()
71
79
[ Test ]
72
80
public void CanInsertAndSelectByteArray__Insert_insert__GetById_select ( )
73
81
{
74
- var orig = new TypeWithByteArrayField { Id = 1 , Content = new byte [ ] { 0 , 17 , 0 , 17 , 0 , 7 } } ;
82
+ var orig = getSampleObject ( ) ;
75
83
76
84
using ( var db = ConnectionString . OpenDbConnection ( ) ) {
77
85
//InsertParam + GetByID - fails
@@ -88,7 +96,7 @@ public void CanInsertAndSelectByteArray__Insert_insert__GetById_select()
88
96
[ Test ]
89
97
public void CanInsertAndSelectByteArray__Insert_insert__manual_select ( )
90
98
{
91
- var orig = new TypeWithByteArrayField { Id = 1 , Content = new byte [ ] { 0 , 17 , 0 , 17 , 0 , 7 } } ;
99
+ var orig = getSampleObject ( ) ;
92
100
93
101
using ( var db = ConnectionString . OpenDbConnection ( ) ) {
94
102
//InsertParam + GetByID - fails
@@ -115,7 +123,7 @@ private static void _selectAndVerifyManually(TypeWithByteArrayField orig, System
115
123
private static void _insertManually ( TypeWithByteArrayField orig , System . Data . IDbConnection db )
116
124
{
117
125
using ( var cmd = db . CreateCommand ( ) ) {
118
- cmd . CommandText = @"INSERT INTO ""TypeWithByteArrayField"" (""Id"",""Content"") VALUES (@Id, @Content) --manual insert" ;
126
+ cmd . CommandText = @"INSERT INTO ""TypeWithByteArrayField"" (""Id"",""Content"") VALUES (@Id, @Content) --manual parameterized insert" ;
119
127
120
128
var p_id = cmd . CreateParameter ( ) ;
121
129
p_id . ParameterName = "@Id" ;
0 commit comments