Skip to content

Commit a0c9a20

Browse files
committed
add nullable test
1 parent 4e07a7c commit a0c9a20

File tree

1 file changed

+83
-1
lines changed

1 file changed

+83
-1
lines changed

tests/SQLite.Tests/SourceGeneratorTest.cs

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,36 @@ public class AllBasicTypesSetter
117117
public Guid Guid { get; set; }
118118
}
119119

120-
// Shouldn't generate Setter because it is not accessible
120+
121+
public class AllBasicTypesSetterNullable
122+
{
123+
[PrimaryKey]
124+
public int Id { get; set; }
125+
126+
public string String { get; set; }
127+
128+
public byte? Byte { get; set; }
129+
130+
public short? Short { get; set; }
131+
132+
public int? Int { get; set; }
133+
134+
public long? Long { get; set; }
135+
136+
public float? Float { get; set; }
137+
138+
public double? Double { get; set; }
139+
140+
public decimal? Decimal { get; set; }
141+
142+
public TimeSpan? TimeSpam { get; set; }
143+
144+
public DateTime? DateTime { get; set; }
145+
146+
public Guid? Guid { get; set; }
147+
}
148+
149+
// Shouldn't generate Setter because it is not accessible
121150
private class PrivateInnerTestSetter
122151
{
123152
[AutoIncrement, PrimaryKey]
@@ -137,6 +166,15 @@ public AllBasicTypesTestDb (String path)
137166
}
138167
}
139168

169+
public class AllBasicTypesNullableTestDb : SQLiteConnection
170+
{
171+
public AllBasicTypesNullableTestDb (String path)
172+
: base (path)
173+
{
174+
CreateTable<AllBasicTypesSetterNullable> ();
175+
}
176+
}
177+
140178
public class InnerTestDb : SQLiteConnection
141179
{
142180
public InnerTestDb (String path)
@@ -456,5 +494,49 @@ public void SetFastColumnSetters_AllBasicTypes_Works ()
456494

457495
Assert.AreEqual (mapperCount, FastColumnSetter.customSetter.Count);
458496
}
497+
498+
[Test]
499+
public void SetFastColumnSetters_AllBasicTypesNullable_Works ()
500+
{
501+
502+
var mapperCount = FastColumnSetter.customSetter.Count;
503+
504+
var n = 20;
505+
var cq = from i in Enumerable.Range (1, n)
506+
select new AllBasicTypesSetterNullable() {
507+
Id = i,
508+
String = null,
509+
Byte = null,
510+
Short = null,
511+
Int = null,
512+
Long = null,
513+
Float = null,
514+
Double = null,
515+
Decimal = null,
516+
DateTime = null,
517+
TimeSpam = null,
518+
Guid = null,
519+
};
520+
521+
var db = new AllBasicTypesNullableTestDb (TestPath.GetTempFileName ());
522+
db.InsertAll (cq);
523+
524+
var results = db.Table<AllBasicTypesSetterNullable> ().Where (o => o.Id.Equals (10));
525+
Assert.AreEqual (results.Count (), 1);
526+
var data = results.FirstOrDefault ();
527+
Assert.AreEqual (data.String, "10");
528+
Assert.AreEqual (data.Byte, null);
529+
Assert.AreEqual (data.Short, null);
530+
Assert.AreEqual (data.Int, null);
531+
Assert.AreEqual (data.Long, null);
532+
Assert.AreEqual (data.Float, null);
533+
Assert.AreEqual (data.Double, null);
534+
Assert.AreEqual (data.Decimal, null);
535+
Assert.AreEqual (data.TimeSpam, null);
536+
Assert.AreEqual (data.DateTime, null);
537+
Assert.AreEqual (data.Guid, null);
538+
539+
Assert.AreEqual (mapperCount, FastColumnSetter.customSetter.Count);
540+
}
459541
}
460542
}

0 commit comments

Comments
 (0)