Skip to content

Commit 1af6a7d

Browse files
committed
Add test for issue #171
1 parent 60177a3 commit 1af6a7d

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// Copyright (C) 2021 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
4+
5+
using System;
6+
using System.Linq;
7+
using System.Threading.Tasks;
8+
using NUnit.Framework;
9+
using Xtensive.Orm.Configuration;
10+
using Xtensive.Orm.Tests.Issues.IssueGithub0171_ReadDateTimeOffsetFromPackedTupleModel;
11+
12+
namespace Xtensive.Orm.Tests.Issues.IssueGithub0171_ReadDateTimeOffsetFromPackedTupleModel
13+
{
14+
[HierarchyRoot]
15+
public class Cargo : Entity
16+
{
17+
[Field, Key]
18+
public int Id { get; private set; }
19+
20+
[Field]
21+
public DateTimeOffset DateTimeOffsetField { get; set; }
22+
23+
[Field]
24+
public DateTime DateTimeField { get; set; }
25+
26+
[Field, Association(PairTo = nameof(CargoLoad.Cargo))]
27+
public EntitySet<CargoLoad> Loads { get; private set; }
28+
29+
public Cargo(Session session)
30+
: base(session)
31+
{
32+
}
33+
}
34+
35+
[HierarchyRoot]
36+
public class CargoLoad: Entity
37+
{
38+
[Field, Key]
39+
public int Id { get; private set; }
40+
41+
[Field]
42+
public Cargo Cargo { get; private set; }
43+
44+
public CargoLoad(Session session, Cargo cargo)
45+
: base(session)
46+
{
47+
Cargo = cargo;
48+
}
49+
}
50+
}
51+
52+
namespace Xtensive.Orm.Tests.Issues
53+
{
54+
public class IssueGithub0171_ReadDateTimeOffsetFromPackedTuple : AutoBuildTest
55+
{
56+
protected override DomainConfiguration BuildConfiguration()
57+
{
58+
var config = base.BuildConfiguration();
59+
config.Types.Register(typeof(Cargo));
60+
config.Types.Register(typeof(CargoLoad));
61+
config.UpgradeMode = DomainUpgradeMode.Recreate;
62+
return config;
63+
}
64+
65+
[Test]
66+
public void DateTimeOffsetCase()
67+
{
68+
// NRE on within PackedFieldAccessor.GetValue<T>
69+
using (var session = Domain.OpenSession())
70+
using (var tx = session.OpenTransaction()) {
71+
var cargo3 = new Cargo(session);
72+
var cargoLoad = new CargoLoad(session, null);
73+
74+
var query = session.Query.All<CargoLoad>()
75+
.LeftJoin(session.Query.All<Cargo>(),
76+
cl => cl.Cargo,
77+
c => c,
78+
(cl, c) => new { CargoLoad = cl, Cargo = c })
79+
.Select(t => t.Cargo.DateTimeOffsetField)
80+
.ToArray();
81+
}
82+
}
83+
84+
[Test]
85+
public void DateTimeCase()
86+
{
87+
//Works fine.
88+
using (var session = Domain.OpenSession())
89+
using (var tx = session.OpenTransaction()) {
90+
var cargo3 = new Cargo(session);
91+
var cargoLoad = new CargoLoad(session, null);
92+
93+
var query = session.Query.All<CargoLoad>()
94+
.LeftJoin(session.Query.All<Cargo>(),
95+
cl => cl.Cargo,
96+
c => c,
97+
(cl, c) => new { CargoLoad = cl, Cargo = c })
98+
.Select(t => t.Cargo.DateTimeField)
99+
.ToArray();
100+
}
101+
}
102+
}
103+
}

0 commit comments

Comments
 (0)