forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateTimeOffsetFixture.cs
97 lines (82 loc) · 2.73 KB
/
DateTimeOffsetFixture.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by AsyncGenerator.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;
using NHibernate.Driver;
using NHibernate.Type;
using NHibernate.Util;
using NUnit.Framework;
namespace NHibernate.Test.NHSpecificTest.Dates
{
using System.Threading.Tasks;
using System.Threading;
[TestFixture]
public class DateTimeOffsetFixtureAsync : FixtureBaseAsync
{
protected override string[] Mappings
{
get { return new[] { "NHSpecificTest.Dates.Mappings.DateTimeOffset.hbm.xml" }; }
}
protected override bool AppliesTo(Engine.ISessionFactoryImplementor factory)
{
// Cannot handle DbType.DateTimeOffset via ODBC.
if (factory.ConnectionProvider.Driver is OdbcDriver)
return false;
return base.AppliesTo(factory);
}
protected override DbType? AppliesTo()
{
return DbType.DateTimeOffset;
}
protected virtual long DateAccuracyInTicks => Dialect.TimestampResolutionInTicks;
[Test]
public async Task SavingAndRetrievingTestAsync()
{
var NowOS = DateTimeOffsetType.Round(DateTimeOffset.Now, DateAccuracyInTicks);
AllDates dates = new AllDates { Sql_datetimeoffset = NowOS };
using (ISession s = OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
await (s.SaveAsync(dates));
await (tx.CommitAsync());
}
using (ISession s = OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
var datesRecovered = await (s.CreateQuery("from AllDates").UniqueResultAsync<AllDates>());
Assert.That(datesRecovered.Sql_datetimeoffset, Is.EqualTo(NowOS));
}
using (ISession s = OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
var datesRecovered = await (s.CreateQuery("from AllDates").UniqueResultAsync<AllDates>());
await (s.DeleteAsync(datesRecovered));
await (tx.CommitAsync());
}
}
[Test]
public async Task NextAsync()
{
var type = NHibernateUtil.DateTimeOffset;
var current = DateTimeOffset.Now.AddTicks(-1);
object next = await (type.NextAsync(current, null, CancellationToken.None));
Assert.That(next, Is.TypeOf<DateTimeOffset>().And.Property("Ticks").GreaterThan(current.Ticks));
}
[Test]
public async Task SeedAsync()
{
var type = NHibernateUtil.DateTimeOffset;
Assert.That(await (type.SeedAsync(null, CancellationToken.None)), Is.TypeOf<DateTimeOffset>());
}
}
}