Skip to content

Commit d0a61d2

Browse files
Re-generate async
1 parent d636a40 commit d0a61d2

File tree

1 file changed

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

1 file changed

+93
-2
lines changed

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

+93-2
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,60 @@
1010

1111
using System;
1212
using System.Linq;
13+
using NHibernate.Cfg;
1314
using NHibernate.Cfg.MappingSchema;
15+
using NHibernate.Dialect;
1416
using NHibernate.Mapping.ByCode;
1517
using NUnit.Framework;
18+
using Environment = NHibernate.Cfg.Environment;
1619
using NHibernate.Linq;
1720

1821
namespace NHibernate.Test.NHSpecificTest.NH3426
1922
{
2023
using System.Threading.Tasks;
21-
[TestFixture]
24+
/// <summary>
25+
/// Verify that we can convert a GUID column to a string in the standard GUID format inside
26+
/// the database engine.
27+
/// </summary>
28+
[TestFixture(true)]
29+
[TestFixture(false)]
2230
public class FixtureAsync : TestCaseMappingByCode
2331
{
32+
private readonly bool _useBinaryGuid;
33+
34+
public FixtureAsync(bool useBinaryGuid)
35+
{
36+
_useBinaryGuid = useBinaryGuid;
37+
}
38+
39+
protected override bool AppliesTo(Dialect.Dialect dialect)
40+
{
41+
// For SQLite, we run the tests for both storage modes (SQLite specific setting).
42+
if (dialect is SQLiteDialect)
43+
return true;
44+
45+
// For all other dialects, run the tests only once since the storage mode
46+
// is not relevant. (We use the case of _useBinaryGuid==true since this is probably
47+
// what most engines do internally.)
48+
return _useBinaryGuid;
49+
}
50+
51+
protected override void Configure(Configuration configuration)
52+
{
53+
base.Configure(configuration);
54+
55+
if (Dialect is SQLiteDialect)
56+
{
57+
var connStr = configuration.Properties[Environment.ConnectionString];
58+
59+
if (_useBinaryGuid)
60+
connStr += "BinaryGuid=True;";
61+
else
62+
connStr += "BinaryGuid=False;";
63+
64+
configuration.Properties[Environment.ConnectionString] = connStr;
65+
}
66+
}
2467

2568
protected override HbmMapping GetMappings()
2669
{
@@ -68,7 +111,7 @@ public async Task SelectGuidToStringAsync()
68111
.Select(x => new { Id = x.Id.ToString() })
69112
.ToListAsync());
70113

71-
Assert.AreEqual(id.ToUpper(), list[0].Id.ToUpper());
114+
Assert.That(list[0].Id.ToUpper(), Is.EqualTo(id.ToUpper()));
72115
}
73116
}
74117

@@ -110,5 +153,53 @@ public async Task CompareStringColumnWithNullableGuidToStringAsync()
110153
Assert.That(list, Has.Count.EqualTo(1));
111154
}
112155
}
156+
157+
[Test]
158+
public async Task SelectGuidToStringImplicitAsync()
159+
{
160+
if (Dialect is SQLiteDialect && _useBinaryGuid)
161+
Assert.Ignore("Fails with BinaryGuid=True due to GH-2109. (2019-04-09).");
162+
163+
if (Dialect is FirebirdDialect || Dialect is MySQLDialect || Dialect is Oracle8iDialect)
164+
Assert.Ignore("Since strguid() is not applied, it fails on Firebird, MySQL and Oracle " +
165+
"because a simple cast cannot be used for GUID to string conversion on " +
166+
"these dialects. See GH-2109.");
167+
168+
using (var session = OpenSession())
169+
{
170+
// Verify in-db GUID to string conversion when ToString() is applied to the entity that has
171+
// a GUID id column (that is, we deliberately avoid mentioning the Id property). This
172+
// exposes bug GH-2109.
173+
var list = await (session.Query<Entity>()
174+
.Select(x => new { Id = x.ToString() })
175+
.ToListAsync());
176+
177+
Assert.That(list[0].Id.ToUpper(), Is.EqualTo(id.ToUpper()));
178+
}
179+
}
180+
181+
[Test]
182+
public async Task WhereGuidToStringImplicitAsync()
183+
{
184+
if (Dialect is SQLiteDialect && _useBinaryGuid)
185+
Assert.Ignore("Fails with BinaryGuid=True due to GH-2109. (2019-04-09).");
186+
187+
if (Dialect is FirebirdDialect || Dialect is MySQLDialect || Dialect is Oracle8iDialect)
188+
Assert.Ignore("Since strguid() is not applied, it fails on Firebird, MySQL and Oracle " +
189+
"because a simple cast cannot be used for GUID to string conversion on " +
190+
"these dialects. See GH-2109.");
191+
192+
using (var session = OpenSession())
193+
{
194+
// Verify in-db GUID to string conversion when ToString() is applied to the entity that has
195+
// a GUID id column (that is, we deliberately avoid mentioning the Id property). This
196+
// exposes bug GH-2109.
197+
var list = await (session.Query<Entity>()
198+
.Where(x => x.ToString().ToUpper() == id)
199+
.ToListAsync());
200+
201+
Assert.That(list, Has.Count.EqualTo(1));
202+
}
203+
}
113204
}
114205
}

0 commit comments

Comments
 (0)