1
+ using System ;
1
2
using System . Linq ;
2
3
using NUnit . Framework ;
3
4
using SQLite . Net . Attributes ;
@@ -9,7 +10,7 @@ public class CreateTableTest
9
10
{
10
11
private static void VerifyCreations ( TestDb db )
11
12
{
12
- TableMapping orderLine = db . GetMapping ( typeof ( OrderLine ) ) ;
13
+ TableMapping orderLine = db . GetMapping ( typeof ( OrderLine ) ) ;
13
14
Assert . AreEqual ( 6 , orderLine . Columns . Length ) ;
14
15
15
16
var l = new OrderLine
@@ -34,10 +35,10 @@ public void CreateAsPassedInTypes()
34
35
{
35
36
var db = new TestDb ( ) ;
36
37
37
- db . CreateTable ( typeof ( Product ) ) ;
38
- db . CreateTable ( typeof ( Order ) ) ;
39
- db . CreateTable ( typeof ( OrderLine ) ) ;
40
- db . CreateTable ( typeof ( OrderHistory ) ) ;
38
+ db . CreateTable ( typeof ( Product ) ) ;
39
+ db . CreateTable ( typeof ( Order ) ) ;
40
+ db . CreateTable ( typeof ( OrderLine ) ) ;
41
+ db . CreateTable ( typeof ( OrderHistory ) ) ;
41
42
42
43
VerifyCreations ( db ) ;
43
44
}
@@ -76,19 +77,63 @@ public void Issue115_MissingPrimaryKey()
76
77
{
77
78
conn . CreateTable < Issue115_MyObject > ( ) ;
78
79
conn . InsertAll ( from i in Enumerable . Range ( 0 , 10 )
79
- select new Issue115_MyObject
80
- {
81
- UniqueId = i . ToString ( ) ,
82
- OtherValue = ( byte ) ( i * 10 ) ,
83
- } ) ;
80
+ select new Issue115_MyObject
81
+ {
82
+ UniqueId = i . ToString ( ) ,
83
+ OtherValue = ( byte ) ( i * 10 ) ,
84
+ } ) ;
84
85
85
86
TableQuery < Issue115_MyObject > query = conn . Table < Issue115_MyObject > ( ) ;
86
87
foreach ( Issue115_MyObject itm in query )
87
88
{
88
89
itm . OtherValue ++ ;
89
- Assert . AreEqual ( 1 , conn . Update ( itm , typeof ( Issue115_MyObject ) ) ) ;
90
+ Assert . AreEqual ( 1 , conn . Update ( itm , typeof ( Issue115_MyObject ) ) ) ;
90
91
}
91
92
}
92
93
}
94
+
95
+ public class ObjWithMaxLength
96
+ {
97
+ [ MaxLength ( 20 ) ]
98
+ public string Name { get ; set ; }
99
+ }
100
+
101
+ [ Test ]
102
+ public void CheckMaxLengthAttributesRespected ( )
103
+ {
104
+ var db = new TestDb ( ) ;
105
+
106
+ db . CreateTable < ObjWithMaxLength > ( ) ;
107
+
108
+ string creationString = db . ExecuteScalar < string > ( "select min(sql) from sqlite_master" ) ;
109
+ Assert . That ( creationString , Is . StringContaining ( "varchar(20)" ) ) ;
110
+ }
111
+
112
+
113
+ public class TweetStringAttribute : MaxLengthAttribute
114
+ {
115
+ public TweetStringAttribute ( ) : base ( 140 )
116
+ {
117
+ }
118
+ }
119
+ public class Tweet
120
+ {
121
+ [ TweetString ]
122
+ public string Message { get ; set ; }
123
+
124
+
125
+ public string Sender { get ; set ; }
126
+ }
127
+
128
+ [ Test ]
129
+ public void CheckMaxLengthAttributesSubtypesRespected ( )
130
+ {
131
+ var db = new TestDb ( ) ;
132
+
133
+ db . CreateTable < Tweet > ( ) ;
134
+
135
+ string creationString = db . ExecuteScalar < string > ( "select min(sql) from sqlite_master" ) ;
136
+ Assert . That ( creationString , Is . StringContaining ( "varchar(140)" ) ) ;
137
+ }
93
138
}
94
139
}
0 commit comments