forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateTimeOffsetQueryFixture.cs
105 lines (90 loc) · 2.93 KB
/
DateTimeOffsetQueryFixture.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
98
99
100
101
102
103
104
105
//------------------------------------------------------------------------------
// <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.Linq;
using NHibernate.Driver;
using NHibernate.Type;
using NUnit.Framework;
using Environment = NHibernate.Cfg.Environment;
using NHibernate.Linq;
namespace NHibernate.Test.NHSpecificTest.Dates
{
using System.Threading.Tasks;
[TestFixture]
public class DateTimeOffsetQueryFixtureAsync : 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 override void Configure(Cfg.Configuration configuration)
{
base.Configure(configuration);
configuration.SetProperty(Environment.ShowSql, "true");
}
protected override void OnSetUp()
{
base.OnSetUp();
var dates1 = new AllDates { Sql_datetimeoffset = new DateTimeOffset(2012, 11, 1, 1, 0, 0, TimeSpan.FromHours(1)) };
var dates2 = new AllDates { Sql_datetimeoffset = new DateTimeOffset(2012, 11, 1, 2, 0, 0, TimeSpan.FromHours(3)) };
using (ISession s = OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
s.Save(dates1);
s.Save(dates2);
tx.Commit();
}
}
protected override void OnTearDown()
{
using (ISession s = OpenSession())
using (ITransaction tx = s.BeginTransaction())
{
s.Delete("from AllDates");
tx.Commit();
}
}
[Test]
public async Task CanQueryWithCastInHqlAsync()
{
using (ISession s = OpenSession())
using (s.BeginTransaction())
{
var datesRecovered = await (s.CreateQuery("select cast(min(Sql_datetimeoffset), datetimeoffset) from AllDates").UniqueResultAsync<DateTimeOffset>());
Assert.That(datesRecovered, Is.EqualTo(new DateTimeOffset(2012, 11, 1, 2, 0, 0, TimeSpan.FromHours(3))));
}
}
[Test(Description = "NH-3357")]
public async Task CanQueryWithAggregateInLinqAsync()
{
using (ISession s = OpenSession())
using (s.BeginTransaction())
{
// The Min() will generate a HqlCast, which requires that the linq
// provider can find a HQL name for datetimeoffset.
var datesRecovered = await ((from allDates in s.Query<AllDates>()
select allDates.Sql_datetimeoffset).MinAsync());
Assert.That(datesRecovered, Is.EqualTo(new DateTimeOffset(2012, 11, 1, 2, 0, 0, TimeSpan.FromHours(3))));
}
}
}
}