Skip to content

Commit b1b243b

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 b1b243b

File tree

1 file changed

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

1 file changed

+92
-2
lines changed

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

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,56 @@
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;
68

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

1355
protected override HbmMapping GetMappings()
1456
{
@@ -56,7 +98,7 @@ public void SelectGuidToString()
5698
.Select(x => new { Id = x.Id.ToString() })
5799
.ToList();
58100

59-
Assert.AreEqual(id.ToUpper(), list[0].Id.ToUpper());
101+
Assert.That(list[0].Id.ToUpper(), Is.EqualTo(id.ToUpper()));
60102
}
61103
}
62104

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

0 commit comments

Comments
 (0)