|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Data; |
| 4 | +using System.IO; |
| 5 | +using NUnit.Framework; |
| 6 | +using ServiceStack.OrmLite.Sqlite; |
| 7 | +using ServiceStack.DataAnnotations; |
| 8 | + |
| 9 | +namespace ServiceStack.OrmLite.Tests.UseCase |
| 10 | +{ |
| 11 | + [TestFixture] |
| 12 | + public class NullableDateTimeOffset |
| 13 | + { |
| 14 | + [TestFixtureSetUp] |
| 15 | + public void TestFixtureSetUp() |
| 16 | + { |
| 17 | + //Inject your database provider here |
| 18 | + OrmLiteConfig.DialectProvider = new SqliteOrmLiteDialectProvider(); |
| 19 | + } |
| 20 | + |
| 21 | + public class Record |
| 22 | + { |
| 23 | + [AutoIncrement] |
| 24 | + public long Id { get; set; } |
| 25 | + |
| 26 | + public DateTimeOffset CreatedDate { get; set; } |
| 27 | + |
| 28 | + public DateTimeOffset? ModifiedDate { get; set; } |
| 29 | + } |
| 30 | + |
| 31 | + [Test] |
| 32 | + public void Can_Insert_RecordWithNullable_DateTimeOffset() |
| 33 | + { |
| 34 | + var path = Config.SqliteFileDb; |
| 35 | + if (File.Exists(path)) |
| 36 | + File.Delete(path); |
| 37 | + |
| 38 | + using (IDbConnection db = path.OpenDbConnection()) |
| 39 | + { |
| 40 | + db.CreateTable<OrmLite.Tests.UseCase.NullableDateTimeOffset.Record>(true); |
| 41 | + |
| 42 | + Assert.DoesNotThrow(() => db.Insert(new OrmLite.Tests.UseCase.NullableDateTimeOffset.Record() { Id = 1, CreatedDate = DateTime.Now })); |
| 43 | + } |
| 44 | + |
| 45 | + File.Delete(path); |
| 46 | + } |
| 47 | + |
| 48 | + [Test] |
| 49 | + public void Can_Update_RecordWithNullable_DateTimeOffset() |
| 50 | + { |
| 51 | + var path = Config.SqliteFileDb; |
| 52 | + if (File.Exists(path)) |
| 53 | + File.Delete(path); |
| 54 | + |
| 55 | + using (IDbConnection db = path.OpenDbConnection()) |
| 56 | + { |
| 57 | + db.CreateTable<OrmLite.Tests.UseCase.NullableDateTimeOffset.Record>(true); |
| 58 | + |
| 59 | + db.Insert(new OrmLite.Tests.UseCase.NullableDateTimeOffset.Record() {Id = 1, CreatedDate = DateTime.Now }); |
| 60 | + |
| 61 | + var record = db.LoadSingleById<OrmLite.Tests.UseCase.NullableDateTimeOffset.Record>(1); |
| 62 | + record.ModifiedDate = DateTimeOffset.Now; |
| 63 | + |
| 64 | + Assert.DoesNotThrow(() => db.Update(record)); |
| 65 | + } |
| 66 | + |
| 67 | + File.Delete(path); |
| 68 | + } |
| 69 | + |
| 70 | + [Test] |
| 71 | + public void Can_UpdateWithNull_RecordWithNullable_DateTimeOffset() |
| 72 | + { |
| 73 | + var path = Config.SqliteFileDb; |
| 74 | + if (File.Exists(path)) |
| 75 | + File.Delete(path); |
| 76 | + |
| 77 | + using (IDbConnection db = path.OpenDbConnection()) |
| 78 | + { |
| 79 | + db.CreateTable<OrmLite.Tests.UseCase.NullableDateTimeOffset.Record>(true); |
| 80 | + |
| 81 | + db.Insert(new OrmLite.Tests.UseCase.NullableDateTimeOffset.Record() { Id = 1, CreatedDate = DateTime.Now, ModifiedDate = DateTimeOffset.Now }); |
| 82 | + |
| 83 | + var record = db.LoadSingleById<OrmLite.Tests.UseCase.NullableDateTimeOffset.Record>(1); |
| 84 | + record.ModifiedDate = null; |
| 85 | + |
| 86 | + Assert.DoesNotThrow(() => db.Update(record)); |
| 87 | + } |
| 88 | + |
| 89 | + File.Delete(path); |
| 90 | + } |
| 91 | + } |
| 92 | +} |
0 commit comments