Skip to content

Commit e45cc98

Browse files
NH-3386 - Test cases as "fixed" by NH-3961.
1 parent 28fbd7f commit e45cc98

File tree

4 files changed

+102
-0
lines changed

4 files changed

+102
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace NHibernate.Test.NHSpecificTest.NH3386
4+
{
5+
class Entity
6+
{
7+
public virtual Guid Id { get; set; }
8+
public virtual string Name { get; set; }
9+
}
10+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System.Linq;
2+
using NHibernate.Linq;
3+
using NUnit.Framework;
4+
using System;
5+
using NHibernate.SqlCommand;
6+
7+
namespace NHibernate.Test.NHSpecificTest.NH3386
8+
{
9+
[TestFixture]
10+
public class Fixture : BugTestCase
11+
{
12+
protected override bool AppliesTo(Dialect.Dialect dialect)
13+
{
14+
return dialect is Dialect.MsSql2000Dialect;
15+
}
16+
17+
protected override void OnSetUp()
18+
{
19+
using (ISession session = OpenSession())
20+
using (ITransaction transaction = session.BeginTransaction())
21+
{
22+
var e1 = new Entity {Name = "Bob"};
23+
session.Save(e1);
24+
25+
var e2 = new Entity {Name = "Sally"};
26+
session.Save(e2);
27+
28+
session.Flush();
29+
transaction.Commit();
30+
}
31+
}
32+
33+
protected override void OnTearDown()
34+
{
35+
using (ISession session = OpenSession())
36+
using (ITransaction transaction = session.BeginTransaction())
37+
{
38+
session.Delete("from System.Object");
39+
40+
session.Flush();
41+
transaction.Commit();
42+
}
43+
}
44+
45+
[Test]
46+
public void ShouldSupportNonRuntimeExtensionWithoutEntityReference()
47+
{
48+
var sqlInterceptor = new SqlInterceptor();
49+
using (ISession session = OpenSession(sqlInterceptor))
50+
using (session.BeginTransaction())
51+
{
52+
var result = session.Query<Entity>()
53+
.OrderBy(e => SqlServerFunction.NewID());
54+
55+
Assert.DoesNotThrow(() => { result.ToList(); });
56+
Assert.That(sqlInterceptor.Sql.ToString(), Does.Contain(nameof(SqlServerFunction.NewID)).IgnoreCase);
57+
}
58+
}
59+
}
60+
61+
public static class SqlServerFunction
62+
{
63+
[LinqExtensionMethod]
64+
public static Guid NewID()
65+
{
66+
throw new InvalidOperationException("To be translated to SQL only");
67+
}
68+
}
69+
70+
public class SqlInterceptor: EmptyInterceptor
71+
{
72+
public SqlString Sql { get; private set; }
73+
74+
public override SqlString OnPrepareStatement(SqlString sql)
75+
{
76+
Sql = sql;
77+
return base.OnPrepareStatement(sql);
78+
}
79+
}
80+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NHibernate.Test" namespace="NHibernate.Test.NHSpecificTest.NH3386">
3+
4+
<class name="Entity">
5+
<id name="Id" generator="guid.comb" />
6+
<property name="Name" />
7+
</class>
8+
9+
</hibernate-mapping>

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,8 @@
737737
<Compile Include="NHSpecificTest\EntityWithUserTypeCanHaveLinqGenerators\Fixture.cs" />
738738
<Compile Include="NHSpecificTest\EntityWithUserTypeCanHaveLinqGenerators\FooExample.cs" />
739739
<Compile Include="NHSpecificTest\EntityWithUserTypeCanHaveLinqGenerators\IExample.cs" />
740+
<Compile Include="NHSpecificTest\NH3386\Entity.cs" />
741+
<Compile Include="NHSpecificTest\NH3386\Fixture.cs" />
740742
<Compile Include="NHSpecificTest\NH3961\Entity.cs" />
741743
<Compile Include="NHSpecificTest\NH3961\DateParametersComparedTo.cs" />
742744
<Compile Include="NHSpecificTest\NH3950\Entity.cs" />
@@ -3210,6 +3212,7 @@
32103212
<EmbeddedResource Include="NHSpecificTest\NH1291AnonExample\Mappings.hbm.xml" />
32113213
</ItemGroup>
32123214
<ItemGroup>
3215+
<EmbeddedResource Include="NHSpecificTest\NH3386\Mappings.hbm.xml" />
32133216
<EmbeddedResource Include="NHSpecificTest\NH3961\Mappings.hbm.xml" />
32143217
<EmbeddedResource Include="NHSpecificTest\NH3950\Mappings.hbm.xml" />
32153218
<EmbeddedResource Include="NHSpecificTest\NH3952\Mappings.hbm.xml" />

0 commit comments

Comments
 (0)