Skip to content

Commit d938eef

Browse files
Merge pull request #666 from fredericDelaporte/NH-4058
NH-4058 - Fix Oracle (12c) Managed 32 failing tests.
2 parents 79e65dd + 335e336 commit d938eef

File tree

13 files changed

+134
-16449
lines changed

13 files changed

+134
-16449
lines changed

lib/teamcity/oracle-managed/NHibernate.Test.last-results.xml

Lines changed: 0 additions & 16380 deletions
This file was deleted.

src/NHibernate.Test/DebugSessionFactory.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ namespace NHibernate.Test
3333
/// <remarks>Sessions opened from other sessions are not tracked.</remarks>
3434
public class DebugSessionFactory : ISessionFactoryImplementor
3535
{
36-
public DebugConnectionProvider ConnectionProvider { get; }
36+
/// <summary>
37+
/// The debug connection provider if configured for using it, <see langword="null"/> otherwise.
38+
/// Use <c>ActualFactory.ConnectionProvider</c> if needing unconditionally the connection provider, be
39+
/// it debug or not.
40+
/// </summary>
41+
public DebugConnectionProvider DebugConnectionProvider { get; }
3742
public ISessionFactoryImplementor ActualFactory { get; }
3843

3944
public EventListeners EventListeners => ((SessionFactoryImpl)ActualFactory).EventListeners;
@@ -44,7 +49,7 @@ public class DebugSessionFactory : ISessionFactoryImplementor
4449
public DebugSessionFactory(ISessionFactory actualFactory)
4550
{
4651
ActualFactory = (ISessionFactoryImplementor)actualFactory;
47-
ConnectionProvider = ActualFactory.ConnectionProvider as DebugConnectionProvider;
52+
DebugConnectionProvider = ActualFactory.ConnectionProvider as DebugConnectionProvider;
4853
}
4954

5055
#region Session tracking

src/NHibernate.Test/Legacy/SQLFunctionsTest.cs

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class SQLFunctionsTest : TestCase
2020

2121
protected override IList Mappings
2222
{
23-
get { return new string[] {"Simple.hbm.xml", "Blobber.hbm.xml", "Broken.hbm.xml"}; }
23+
get { return new string[] { "Simple.hbm.xml", "Blobber.hbm.xml", "Broken.hbm.xml" }; }
2424
}
2525

2626
[Test]
@@ -33,7 +33,7 @@ public void DialectSQLFunctions()
3333
.GetEnumerator();
3434

3535
if (Dialect is MySQLDialect
36-
// Added two dialects below for NH
36+
// Added two dialects below for NH
3737
|| Dialect is MsSql2000Dialect
3838
|| Dialect is PostgreSQLDialect)
3939
{
@@ -50,20 +50,20 @@ public void DialectSQLFunctions()
5050

5151
// Test to make sure allocating an specified object operates correctly.
5252
Assert.AreEqual(1,
53-
s.CreateQuery("select new S(s.Count, s.Address) from s in class Simple").List()
54-
.Count);
53+
s.CreateQuery("select new S(s.Count, s.Address) from s in class Simple").List()
54+
.Count);
5555

5656
// Quick check the base dialect functions operate correctly
5757
Assert.AreEqual(1,
58-
s.CreateQuery("select max(s.Count) from s in class Simple").List().Count);
58+
s.CreateQuery("select max(s.Count) from s in class Simple").List().Count);
5959
Assert.AreEqual(1,
60-
s.CreateQuery("select count(*) from s in class Simple").List().Count);
60+
s.CreateQuery("select count(*) from s in class Simple").List().Count);
6161

6262
if (Dialect is Oracle8iDialect)
6363
{
6464
// Check Oracle Dialect mix of dialect functions - no args (no parenthesis and single arg functions
6565
IList rset = s.CreateQuery("select s.Name, sysdate, trunc(s.Pay), round(s.Pay) from s in class Simple").List();
66-
object[] row = (object[]) rset[0];
66+
object[] row = (object[])rset[0];
6767
Assert.IsNotNull(row[0], "Name string should have been returned");
6868
Assert.IsNotNull(row[1], "Todays Date should have been returned");
6969
Assert.AreEqual(45f, row[2], "trunc(45.8) result was incorrect");
@@ -76,11 +76,6 @@ public void DialectSQLFunctions()
7676
rset = s.CreateQuery("select abs(round(s.Pay)) from s in class Simple").List();
7777
Assert.AreEqual(46f, rset[0], "abs(round(-45.8)) result was incorrect");
7878

79-
rset = s.CreateQuery("select left('abc', 2), right('abc', 2) from s in class Simple").List();
80-
row = (object[]) rset[0];
81-
Assert.AreEqual("ab", row[0], "Left function is broken.");
82-
Assert.AreEqual("bc", row[1], "Right function is broken.");
83-
8479
// Test a larger depth 3 function example - Not a useful combo other than for testing
8580
Assert.AreEqual(1,
8681
s.CreateQuery("select trunc(round(length('A'))) from s in class Simple").List().Count);
@@ -109,14 +104,31 @@ public void DialectSQLFunctions()
109104
s.Close();
110105
}
111106

107+
[Test]
108+
[Ignore("NH-3893 is not fixed")]
109+
public void LeftAndRight()
110+
{
111+
// As of NH-3893, left and right functions are broken. Seemed confused with join keyword, and not
112+
// supported on Hibernate side.
113+
using (var s = OpenSession())
114+
using (var t = s.BeginTransaction())
115+
{
116+
var rset = s.CreateQuery("select left('abc', 2), right('abc', 2) from s in class Simple").List<object[]>();
117+
var row = rset[0];
118+
Assert.AreEqual("ab", row[0], "Left function is broken.");
119+
Assert.AreEqual("bc", row[1], "Right function is broken.");
120+
t.Commit();
121+
}
122+
}
123+
112124
[Test]
113125
public void SetProperties()
114126
{
115127
ISession s = OpenSession();
116128
ITransaction t = s.BeginTransaction();
117129
Simple simple = new Simple();
118130
simple.Name = "Simple 1";
119-
s.Save(simple, (long) 10);
131+
s.Save(simple, (long)10);
120132
IQuery q = s.CreateQuery("from s in class Simple where s.Name=:Name and s.Count=:Count");
121133
q.SetProperties(simple);
122134
Assert.AreEqual(simple, q.List()[0]);
@@ -152,7 +164,7 @@ public void Broken()
152164

153165
s = OpenSession();
154166
t = s.BeginTransaction();
155-
b = (Broken) s.Load(typeof(Broken), b);
167+
b = (Broken)s.Load(typeof(Broken), b);
156168
t.Commit();
157169
s.Close();
158170

@@ -170,19 +182,19 @@ public void NothingToUpdate()
170182
ITransaction t = s.BeginTransaction();
171183
Simple simple = new Simple();
172184
simple.Name = "Simple 1";
173-
s.Save(simple, (long) 10);
185+
s.Save(simple, (long)10);
174186
t.Commit();
175187
s.Close();
176188

177189
s = OpenSession();
178190
t = s.BeginTransaction();
179-
s.Update(simple, (long) 10);
191+
s.Update(simple, (long)10);
180192
t.Commit();
181193
s.Close();
182194

183195
s = OpenSession();
184196
t = s.BeginTransaction();
185-
s.Update(simple, (long) 10);
197+
s.Update(simple, (long)10);
186198
s.Delete(simple);
187199
t.Commit();
188200
s.Close();
@@ -215,7 +227,7 @@ public void CachedQuery()
215227
q.SetString("name", "Simple 1");
216228
Assert.AreEqual(1, q.List().Count);
217229

218-
simple = (Simple) q.List()[0];
230+
simple = (Simple)q.List()[0];
219231

220232
q.SetString("name", "Simple 2");
221233
Assert.AreEqual(0, q.List().Count);
@@ -293,7 +305,7 @@ public void SQLFunctionAsAlias()
293305
t = s.BeginTransaction();
294306
IList result = s.CreateQuery(query).List();
295307
Assert.IsTrue(result[0] is Simple,
296-
"Unexpected result type [" + result[0].GetType().Name + "]");
308+
"Unexpected result type [" + result[0].GetType().Name + "]");
297309
s.Delete(result[0]);
298310
t.Commit();
299311
s.Close();
@@ -381,7 +393,7 @@ public void CachedQueryRegion()
381393
q.SetCacheable(true);
382394
q.SetString("name", "Simple 1");
383395
Assert.AreEqual(1, q.List().Count);
384-
simple = (Simple) q.List()[0];
396+
simple = (Simple)q.List()[0];
385397

386398
q.SetString("name", "Simple 2");
387399
Assert.AreEqual(0, q.List().Count);
@@ -419,7 +431,7 @@ public void SQLFunctions()
419431
ITransaction t = s.BeginTransaction();
420432
Simple simple = new Simple();
421433
simple.Name = "Simple 1";
422-
s.Save(simple, (long) 10);
434+
s.Save(simple, (long)10);
423435

424436
if (Dialect is DB2Dialect)
425437
{
@@ -430,23 +442,23 @@ public void SQLFunctions()
430442

431443
Assert.AreEqual(1, s.CreateQuery("from s in class Simple where upper(s.Name) = 'SIMPLE 1'").List().Count);
432444
Assert.AreEqual(1,
433-
s.CreateQuery(
434-
"from s in class Simple where not( upper(s.Name)='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar')")
435-
.List().Count);
445+
s.CreateQuery(
446+
"from s in class Simple where not( upper(s.Name)='yada' or 1=2 or 'foo'='bar' or not('foo'='foo') or 'foo' like 'bar')")
447+
.List().Count);
436448

437449
if (!(Dialect is MySQLDialect) && !(Dialect is MsSql2000Dialect))
438450
{
439451
// Dialect.MckoiDialect and Dialect.InterbaseDialect also included
440452
// My Sql has a funny concatenation operator
441453
Assert.AreEqual(1,
442-
s.CreateQuery("from s in class Simple where lower(s.Name || ' foo')='simple 1 foo'").List().Count);
454+
s.CreateQuery("from s in class Simple where lower(s.Name || ' foo')='simple 1 foo'").List().Count);
443455
}
444456

445457
if ((Dialect is MsSql2000Dialect))
446458
{
447459
Assert.AreEqual(1,
448-
s.CreateQuery("from s in class Simple where lower( s.Name + ' foo' ) = 'simple 1 foo'").List().
449-
Count);
460+
s.CreateQuery("from s in class Simple where lower( s.Name + ' foo' ) = 'simple 1 foo'").List().
461+
Count);
450462
}
451463

452464
/*
@@ -461,46 +473,46 @@ public void SQLFunctions()
461473
other.Name = "Simple 2";
462474
other.Count = 12;
463475
simple.Other = other;
464-
s.Save(other, (long) 20);
476+
s.Save(other, (long)20);
465477
Assert.AreEqual(1, s.CreateQuery("from s in class Simple where upper( s.Other.Name )='SIMPLE 2'").List().Count);
466478
Assert.AreEqual(0, s.CreateQuery("from s in class Simple where not (upper(s.Other.Name)='SIMPLE 2')").List().Count);
467479
Assert.AreEqual(1,
468-
s.CreateQuery(
469-
"select distinct s from s in class Simple where ( ( s.Other.Count + 3) = (15*2)/2 and s.Count = 69) or ( (s.Other.Count + 2) / 7 ) = 2")
470-
.List().Count);
480+
s.CreateQuery(
481+
"select distinct s from s in class Simple where ( ( s.Other.Count + 3) = (15*2)/2 and s.Count = 69) or ( (s.Other.Count + 2) / 7 ) = 2")
482+
.List().Count);
471483
Assert.AreEqual(1,
472-
s.CreateQuery(
473-
"select s from s in class Simple where ( ( s.Other.Count + 3) = (15*2)/2 and s.Count = 69) or ( (s.Other.Count + 2) / 7 ) = 2 order by s.Other.Count")
474-
.List().Count);
484+
s.CreateQuery(
485+
"select s from s in class Simple where ( ( s.Other.Count + 3) = (15*2)/2 and s.Count = 69) or ( (s.Other.Count + 2) / 7 ) = 2 order by s.Other.Count")
486+
.List().Count);
475487

476488
Simple min = new Simple();
477489
min.Count = -1;
478490

479-
s.Save(min, (long) 30);
491+
s.Save(min, (long)30);
480492

481493
if (Dialect.SupportsSubSelects && TestDialect.SupportsOperatorSome)
482494
{
483495
Assert.AreEqual(2,
484-
s.CreateQuery(
485-
"from s in class Simple where s.Count > ( select min(sim.Count) from sim in class NHibernate.DomainModel.Simple )")
486-
.List().Count);
496+
s.CreateQuery(
497+
"from s in class Simple where s.Count > ( select min(sim.Count) from sim in class NHibernate.DomainModel.Simple )")
498+
.List().Count);
487499
t.Commit();
488500
t = s.BeginTransaction();
489501
Assert.AreEqual(2,
490-
s.CreateQuery(
491-
"from s in class Simple where s = some( select sim from sim in class NHibernate.DomainModel.Simple where sim.Count>=0) and s.Count >= 0")
492-
.List().Count);
502+
s.CreateQuery(
503+
"from s in class Simple where s = some( select sim from sim in class NHibernate.DomainModel.Simple where sim.Count>=0) and s.Count >= 0")
504+
.List().Count);
493505
Assert.AreEqual(1,
494-
s.CreateQuery(
495-
"from s in class Simple where s = some( select sim from sim in class NHibernate.DomainModel.Simple where sim.Other.Count=s.Other.Count ) and s.Other.Count > 0")
496-
.List().Count);
506+
s.CreateQuery(
507+
"from s in class Simple where s = some( select sim from sim in class NHibernate.DomainModel.Simple where sim.Other.Count=s.Other.Count ) and s.Other.Count > 0")
508+
.List().Count);
497509
}
498510

499511
IEnumerator enumer =
500512
s.CreateQuery("select sum(s.Count) from s in class Simple group by s.Count having sum(s.Count) > 10 ").Enumerable()
501513
.GetEnumerator();
502514
Assert.IsTrue(enumer.MoveNext());
503-
Assert.AreEqual(12, (Int64) enumer.Current); // changed cast from Int32 to Int64 (H3.2)
515+
Assert.AreEqual(12, (Int64)enumer.Current); // changed cast from Int32 to Int64 (H3.2)
504516
Assert.IsFalse(enumer.MoveNext());
505517

506518
if (Dialect.SupportsSubSelects)
@@ -568,7 +580,7 @@ public void SQLFunctions()
568580
list.Add("Simple 1");
569581
list.Add("foo");
570582
q.SetParameterList("name_list", list);
571-
q.SetParameter("count", (int) -1);
583+
q.SetParameter("count", (int)-1);
572584
Assert.AreEqual(1, q.List().Count);
573585

574586
s.Delete(other);

src/NHibernate.Test/Linq/ByMethod/GroupByTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,8 @@ public void GroupByComputedValueInObjectArrayWithJoinInRightSideOfCase()
781781
Assert.Ignore("SQL Server seems unable to match complex group by and select list arguments when running over ODBC.");
782782
if (Dialect is MsSqlCeDialect)
783783
Assert.Ignore("SQL Server CE does not support complex group by expressions.");
784+
if (Dialect is Oracle8iDialect)
785+
Assert.Ignore("ORA-12704: character set mismatch. Due to NHibernate creating Unicode string types as NVarchar2 but querying them as Varchar2.");
784786

785787
var orderGroups = db.OrderLines.GroupBy(o => new[] { o.Order.Customer.CustomerId == null ? "unknown" : o.Order.Customer.CompanyName }).Select(g => new { Key = g.Key, Count = g.Count() }).ToList();
786788
Assert.AreEqual(2155, orderGroups.Sum(g => g.Count));

src/NHibernate.Test/Linq/MiscellaneousTextFixture.cs

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Linq;
33
using System.Linq.Expressions;
4+
using NHibernate.Dialect;
45
using NHibernate.Linq;
56
using NHibernate.DomainModel.Northwind.Entities;
67
using NUnit.Framework;
@@ -86,16 +87,17 @@ public void ReferenceToOuter()
8687
"the second, third and fourth pages of products")]
8788
public void TriplePageSelection()
8889
{
89-
IQueryable<Product> q = (
90-
from p in db.Products
91-
where p.ProductId > 1
92-
orderby p.ProductId
93-
select p
94-
);
90+
var q =
91+
from p in db.Products
92+
where p.ProductId > 1
93+
orderby p.ProductId
94+
select p;
9595

96-
IQueryable<Product> page2 = q.Skip(5).Take(5);
97-
IQueryable<Product> page3 = q.Skip(10).Take(5);
98-
IQueryable<Product> page4 = q.Skip(15).Take(5);
96+
// ToList required otherwise the First call alters the paging and test something else than paging three pages,
97+
// contrary o the test above description.
98+
var page2 = q.Skip(5).Take(5).ToList();
99+
var page3 = q.Skip(10).Take(5).ToList();
100+
var page4 = q.Skip(15).Take(5).ToList();
99101

100102
var firstResultOnPage2 = page2.First();
101103
var firstResultOnPage3 = page3.First();
@@ -106,7 +108,30 @@ select p
106108
Assert.AreNotEqual(firstResultOnPage2.ProductId, firstResultOnPage4.ProductId);
107109
}
108110

109-
[Test]
111+
[Category("Paging")]
112+
[Test(Description = "NH-4061 - This sample uses a where clause and the Skip and Take operators to select " +
113+
"the second, third and fourth pages of products, but then add a First causing the Take to be pointless.")]
114+
public void TriplePageSelectionWithFirst()
115+
{
116+
if (Dialect is Oracle8iDialect)
117+
Assert.Ignore("Not fixed: NH-4061 - Pointless Take calls screw Oracle dialect paging.");
118+
119+
var q =
120+
from p in db.Products
121+
where p.ProductId > 1
122+
orderby p.ProductId
123+
select p;
124+
125+
var firstResultOnPage2 = q.Skip(5).Take(5).First();
126+
var firstResultOnPage3 = q.Skip(10).Take(5).First();
127+
var firstResultOnPage4 = q.Skip(15).Take(5).First();
128+
129+
Assert.AreNotEqual(firstResultOnPage2.ProductId, firstResultOnPage3.ProductId);
130+
Assert.AreNotEqual(firstResultOnPage3.ProductId, firstResultOnPage4.ProductId);
131+
Assert.AreNotEqual(firstResultOnPage2.ProductId, firstResultOnPage4.ProductId);
132+
}
133+
134+
[Test]
110135
public void SelectFromObject()
111136
{
112137
using (var s = OpenSession())

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.Generic;
22
using NHibernate.Criterion;
3+
using NHibernate.Dialect;
34
using NUnit.Framework;
45

56
namespace NHibernate.Test.NHSpecificTest.NH1792
@@ -79,6 +80,11 @@ public void PageWithDetachedCriteriaSubqueryWithOrderBy()
7980
[Test]
8081
public void PageWithRawSqlSubqueryWithOrderBy()
8182
{
83+
// Theoretically, the ordering of elements in a "where col in (elements)" should not change anything.
84+
// That is not the case for SQL Server, but Oracle just refuses any ordering there.
85+
if (Dialect is Oracle8iDialect)
86+
Assert.Ignore("Oracle does not support pointless order by");
87+
8288
using (ISession session = OpenSession())
8389
{
8490
string top = "";

src/NHibernate.Test/NHSpecificTest/NH1985/SampleTest.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
using System;
2-
using System.Data.Common;
31
using NHibernate.Connection;
2+
using NHibernate.Dialect;
43
using NUnit.Framework;
54

65
namespace NHibernate.Test.NHSpecificTest.NH1985
76
{
87
[TestFixture]
98
public class SampleTest : BugTestCase
109
{
10+
protected override bool AppliesTo(Dialect.Dialect dialect)
11+
{
12+
// Test written with raw SQL queries, not compatible with all databases.
13+
return dialect is MsSql2000Dialect;
14+
}
15+
1116
protected override void OnSetUp()
1217
{
1318
if (0 == ExecuteStatement("INSERT INTO DomainClass (Id, Label) VALUES (1, 'TEST record');"))

0 commit comments

Comments
 (0)