Skip to content

Commit 404368b

Browse files
committed
Expand NH-3426 tests to expose GH-2110 (and GH-2109).
The cases for GH-2109 are marked as ignored for now, as that is not a regression.
1 parent 5a20d47 commit 404368b

File tree

1 file changed

+93
-2
lines changed
  • src/NHibernate.Test/NHSpecificTest/NH3426

1 file changed

+93
-2
lines changed

src/NHibernate.Test/NHSpecificTest/NH3426/Fixture.cs

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,57 @@
11
using System;
22
using System.Linq;
3+
using NHibernate.Cfg;
34
using NHibernate.Cfg.MappingSchema;
5+
using NHibernate.Dialect;
46
using NHibernate.Mapping.ByCode;
57
using NUnit.Framework;
8+
using Environment = NHibernate.Cfg.Environment;
69

710
namespace NHibernate.Test.NHSpecificTest.NH3426
811
{
9-
[TestFixture]
12+
/// <summary>
13+
/// Verify that we can convert a GUID column to a string in the standard GUID format inside
14+
/// the database engine.
15+
/// </summary>
16+
[TestFixture(true)]
17+
[TestFixture(false)]
1018
public class Fixture : TestCaseMappingByCode
1119
{
20+
private readonly bool _useBinaryGuid;
21+
22+
public Fixture(bool useBinaryGuid)
23+
{
24+
_useBinaryGuid = useBinaryGuid;
25+
}
26+
27+
protected override bool AppliesTo(Dialect.Dialect dialect)
28+
{
29+
// For SQLite, we run the tests for both storage modes (SQLite specific setting).
30+
if (dialect is SQLiteDialect)
31+
return true;
32+
33+
// For all other dialects, run the tests only once since the storage mode
34+
// is not relevant. (We use the case of _useBinaryGuid==true since this is probably
35+
// what most engines do internally.)
36+
return _useBinaryGuid;
37+
}
38+
39+
protected override void Configure(Configuration configuration)
40+
{
41+
base.Configure(configuration);
42+
43+
if (Dialect is SQLiteDialect)
44+
{
45+
var connStr = configuration.Properties[Environment.ConnectionString];
46+
47+
if (_useBinaryGuid)
48+
connStr += "BinaryGuid=True;";
49+
else
50+
connStr += "BinaryGuid=False;";
51+
52+
configuration.Properties[Environment.ConnectionString] = connStr;
53+
}
54+
}
1255

1356
protected override HbmMapping GetMappings()
1457
{
@@ -56,7 +99,7 @@ public void SelectGuidToString()
5699
.Select(x => new { Id = x.Id.ToString() })
57100
.ToList();
58101

59-
Assert.AreEqual(id.ToUpper(), list[0].Id.ToUpper());
102+
Assert.That(list[0].Id.ToUpper(), Is.EqualTo(id.ToUpper()));
60103
}
61104
}
62105

@@ -98,5 +141,53 @@ public void CompareStringColumnWithNullableGuidToString()
98141
Assert.That(list, Has.Count.EqualTo(1));
99142
}
100143
}
144+
145+
[Test]
146+
public void SelectGuidToStringImplicit()
147+
{
148+
if (Dialect is SQLiteDialect && _useBinaryGuid)
149+
Assert.Ignore("Fails with BinaryGuid=True due to GH-2109. (2019-04-09).");
150+
151+
if (Dialect is FirebirdDialect || Dialect is MySQLDialect || Dialect is Oracle8iDialect)
152+
Assert.Ignore("Since strguid() is not applied, it fails on Firebird, MySQL and Oracle " +
153+
"because a simple cast cannot be used for GUID to string conversion on " +
154+
"these dialects. See GH-2109.");
155+
156+
using (var session = OpenSession())
157+
{
158+
// Verify in-db GUID to string conversion when ToString() is applied to the entity that has
159+
// a GUID id column (that is, we deliberately avoid mentioning the Id property). This
160+
// exposes bug GH-2109.
161+
var list = session.Query<Entity>()
162+
.Select(x => new { Id = x.ToString() })
163+
.ToList();
164+
165+
Assert.That(list[0].Id.ToUpper(), Is.EqualTo(id.ToUpper()));
166+
}
167+
}
168+
169+
[Test]
170+
public void WhereGuidToStringImplicit()
171+
{
172+
if (Dialect is SQLiteDialect && _useBinaryGuid)
173+
Assert.Ignore("Fails with BinaryGuid=True due to GH-2109. (2019-04-09).");
174+
175+
if (Dialect is FirebirdDialect || Dialect is MySQLDialect || Dialect is Oracle8iDialect)
176+
Assert.Ignore("Since strguid() is not applied, it fails on Firebird, MySQL and Oracle " +
177+
"because a simple cast cannot be used for GUID to string conversion on " +
178+
"these dialects. See GH-2109.");
179+
180+
using (var session = OpenSession())
181+
{
182+
// Verify in-db GUID to string conversion when ToString() is applied to the entity that has
183+
// a GUID id column (that is, we deliberately avoid mentioning the Id property). This
184+
// exposes bug GH-2109.
185+
var list = session.Query<Entity>()
186+
.Where(x => x.ToString().ToUpper() == id)
187+
.ToList();
188+
189+
Assert.That(list, Has.Count.EqualTo(1));
190+
}
191+
}
101192
}
102193
}

0 commit comments

Comments
 (0)