Skip to content

Commit 72459f8

Browse files
committed
Expand NH-3426 tests to expose nhibernateGH-2110 (and nhibernateGH-2109).
The cases for nhibernateGH-2109 are marked as ignored for now, as that is not a regression.
1 parent c628337 commit 72459f8

File tree

1 file changed

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

1 file changed

+82
-2
lines changed

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

Lines changed: 82 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,43 @@ 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+
using (var session = OpenSession())
151+
{
152+
// Verify in-db GUID to string conversion when ToString() is applied to the entity that has
153+
// a GUID id column (that is, we deliberately avoid mentioning the Id property). This
154+
// exposes bug GH-2109.
155+
var list = session.Query<Entity>()
156+
.Select(x => new { Id = x.ToString() })
157+
.ToList();
158+
159+
Assert.That(list[0].Id.ToUpper(), Is.EqualTo(id.ToUpper()));
160+
}
161+
}
162+
163+
[Test]
164+
public void WhereGuidToStringImplicit()
165+
{
166+
if (Dialect is SQLiteDialect && _useBinaryGuid)
167+
Assert.Ignore("Fails with BinaryGuid=True due to GH-2109. (2019-04-09).");
168+
169+
using (var session = OpenSession())
170+
{
171+
// Verify in-db GUID to string conversion when ToString() is applied to the entity that has
172+
// a GUID id column (that is, we deliberately avoid mentioning the Id property). This
173+
// exposes bug GH-2109.
174+
var list = session.Query<Entity>()
175+
.Where(x => x.ToString().ToUpper() == id)
176+
.ToList();
177+
178+
Assert.That(list, Has.Count.EqualTo(1));
179+
}
180+
}
101181
}
102182
}

0 commit comments

Comments
 (0)