Skip to content

Commit bf90df4

Browse files
author
Sergey Koshcheyev
committed
Refactoring in tests:
- tests now use second-level cache by default. Nonstrict-read-write concurrency strategy is set to all classes and collections used in a test. - The default cache concurrency strategy can be overridden (TestCase.CacheConcurrencyStrategy property). - TestCase.dialect was made static and renamed to Dialect. Fixed a few minor bugs related to caching. SVN: trunk@2686
1 parent 1976ccd commit bf90df4

35 files changed

+451
-300
lines changed

src/NHibernate.DomainModel/CustomPersister.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ public ISessionFactoryImplementor Factory
387387
get { return factory; }
388388
}
389389

390+
public bool IsInstance(object entity)
391+
{
392+
return entity is Custom;
393+
}
394+
390395
#endregion
391396
}
392397
}

src/NHibernate.Test/CacheTest/QueryCacheFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void QueryCacheWithNullParameters()
4444
// Run a second time, just to test the query cache
4545
object result = s
4646
.CreateQuery("from Simple s where s = :s or s.Name = :name or s.Address = :address")
47-
.SetEntity("s", simple)
47+
.SetEntity("s", s.Load(typeof(Simple), 1L))
4848
.SetString("name", null)
4949
.SetString("address", null)
5050
.SetCacheable(true)

src/NHibernate.Test/FilterTest/DynamicFilterTest.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -489,27 +489,6 @@ protected override IList Mappings
489489
}
490490
}
491491

492-
protected override void Configure(Configuration cfg)
493-
{
494-
cfg.SetProperty(Environment.MaxFetchDepth, "1");
495-
// cfg.setProperty( Environment.MAX_FETCH_DEPTH, "2" );
496-
//cfg.SetProperty(Environment.GenerateStatistics, "true");
497-
cfg.SetProperty(Environment.UseQueryCache, "true");
498-
499-
foreach (PersistentClass clazz in cfg.ClassMappings)
500-
{
501-
if (!clazz.IsInherited)
502-
{
503-
cfg.SetCacheConcurrencyStrategy(clazz.MappedClass, "nonstrict-read-write");
504-
}
505-
}
506-
507-
foreach (Mapping.Collection coll in cfg.CollectionMappings)
508-
{
509-
cfg.SetCacheConcurrencyStrategy(coll.Role, "nonstrict-read-write");
510-
}
511-
}
512-
513492
private class TestData
514493
{
515494
public long steveId;

src/NHibernate.Test/Legacy/ABCTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ protected override IList Mappings
2020
[Test]
2121
public void HigherLevelIndexDefinitionInColumnTag()
2222
{
23-
string[] commands = cfg.GenerateSchemaCreationScript(dialect);
23+
string[] commands = cfg.GenerateSchemaCreationScript(Dialect);
2424

2525
Assert.IsTrue(ContainsCommandWithSubstring(commands, "create index indx_a_name"),
2626
"Unable to locate indx_a_name index creation");
@@ -29,7 +29,7 @@ public void HigherLevelIndexDefinitionInColumnTag()
2929
[Test]
3030
public void HigherLevelIndexDefinitionInPropertyTag()
3131
{
32-
string[] commands = cfg.GenerateSchemaCreationScript(dialect);
32+
string[] commands = cfg.GenerateSchemaCreationScript(Dialect);
3333

3434
Assert.IsTrue(ContainsCommandWithSubstring(commands, "create index indx_a_anothername"),
3535
"Unable to locate indx_a_anothername index creation");
@@ -57,7 +57,7 @@ public void Subselect()
5757
t.Commit();
5858
}
5959

60-
if (dialect is FirebirdDialect)
60+
if (Dialect is FirebirdDialect)
6161
{
6262
// Firebird has problems deleting the map contents
6363
ExecuteStatement("delete from Map");

src/NHibernate.Test/Legacy/FooBarTest.cs

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@ public void MoveLazyCollection()
345345
Assert.IsFalse(NHibernateUtil.IsInitialized(baz.FooSet));
346346
Assert.AreEqual(0, baz.FooSet.Count);
347347

348-
// TODO: batching doesn't work in NH yet
349-
//Assert.IsTrue( NHibernateUtil.IsInitialized( baz2.FooSet ) ); //fooSet has batching enabled
348+
Assert.IsTrue( NHibernateUtil.IsInitialized( baz2.FooSet ) ); //FooSet has batching enabled
350349

351350
Assert.AreEqual(1, baz2.FooSet.Count);
352351

@@ -460,7 +459,7 @@ public void Query()
460459

461460
s.CreateQuery("from bar in class Bar, foo in elements(bar.Baz.FooArray)").List();
462461

463-
if (dialect is DB2Dialect)
462+
if (Dialect is DB2Dialect)
464463
{
465464
s.CreateQuery("from foo in class Foo where lower( foo.TheFoo.String ) = 'foo'").List();
466465
s.CreateQuery("from foo in class Foo where lower( (foo.TheFoo.String || 'foo') || 'bar' ) = 'foo'").List();
@@ -473,7 +472,7 @@ public void Query()
473472
.List();
474473
}
475474

476-
if ((dialect is SybaseDialect) || (dialect is MsSql2000Dialect))
475+
if ((Dialect is SybaseDialect) || (Dialect is MsSql2000Dialect))
477476
{
478477
s.CreateQuery("select baz from Baz as baz join baz.FooArray foo group by baz order by sum(foo.Float)").Enumerable();
479478
}
@@ -510,9 +509,9 @@ public void Query()
510509
foo.TheFoo.TheFoo = foo;
511510
foo.String = "fizard";
512511

513-
if (dialect.SupportsSubSelects)
512+
if (Dialect.SupportsSubSelects)
514513
{
515-
if (!(dialect is FirebirdDialect))
514+
if (!(Dialect is FirebirdDialect))
516515
{
517516
list =
518517
s.CreateQuery("from foo in class NHibernate.DomainModel.Foo where ? = some foo.Component.ImportantDates.elements")
@@ -615,7 +614,7 @@ public void Query()
615614
"select foo.TheFoo.TheFoo.TheFoo from foo in class Foo, foo2 in class Foo where"
616615
+ " foo = foo2.TheFoo and not not ( not foo.String='fizard' )"
617616
+ " and foo2.String between 'a' and (foo.TheFoo.String)"
618-
+ (dialect is SQLiteDialect
617+
+ (Dialect is SQLiteDialect
619618
? " and ( foo2.String in ( 'fiz', 'blah') or 1=1 )"
620619
: " and ( foo2.String in ( 'fiz', 'blah', foo.TheFoo.String, foo.String, foo2.String ) )")
621620
).List();
@@ -802,7 +801,7 @@ public void Query()
802801
.List();
803802

804803
s.CreateQuery("from Baz baz inner join baz.CollectionComponent.Nested.Foos foo where foo.String is null").List();
805-
if (dialect.SupportsSubSelects)
804+
if (Dialect.SupportsSubSelects)
806805
{
807806
s.CreateQuery("from Baz baz inner join baz.FooSet where '1' in (from baz.FooSet foo where foo.String is not null)").
808807
List();
@@ -1090,7 +1089,7 @@ public void QueryCollectionOfValues()
10901089
Glarch g = new Glarch();
10911090
gid = s.Save(g);
10921091

1093-
if (dialect.SupportsSubSelects)
1092+
if (Dialect.SupportsSubSelects)
10941093
{
10951094
s.CreateFilter(baz.FooArray, "where size(this.Bytes) > 0").List();
10961095
s.CreateFilter(baz.FooArray, "where 0 in elements(this.Bytes)").List();
@@ -2103,8 +2102,6 @@ public void FindByCriteria()
21032102
s.Flush();
21042103
s.Close();
21052104

2106-
//TODO: some HSQLDialect specific code here
2107-
21082105
s = OpenSession();
21092106
list = s.CreateCriteria(typeof(Foo))
21102107
.Add(Expression.Expression.Eq("Integer", f.Integer))
@@ -2264,8 +2261,6 @@ public void AssociationId()
22642261
stuf.Foo = bar;
22652262
stuf.Id = 1234;
22662263

2267-
//TODO: http://jira.nhibernate.org:8080/browse/NH-88
2268-
//stuf.setProperty(TimeZone.getDefault() );
22692264
s.Save(more);
22702265
t.Commit();
22712266
}
@@ -2348,9 +2343,6 @@ public void AssociationId()
23482343
stuff.MoreStuff = more;
23492344
s.Load(stuff, stuff);
23502345

2351-
// TODO: figure out what to do with TimeZone
2352-
// http://jira.nhibernate.org:8080/browse/NH-88
2353-
//Assert.IsTrue( stuff.getProperty().equals( TimeZone.getDefault() ) );
23542346
Assert.AreEqual("More Stuff", stuff.MoreStuff.Name);
23552347
s.Delete("from ms in class MoreStuff");
23562348
s.Delete("from foo in class Foo");
@@ -2399,7 +2391,7 @@ public void CompositeKeyPathExpressions()
23992391
hql = "from fum1 in class Fum where fum1.Fo.FumString is not null order by fum1.Fo.FumString";
24002392
s.CreateQuery(hql).List();
24012393

2402-
if (dialect.SupportsSubSelects)
2394+
if (Dialect.SupportsSubSelects)
24032395
{
24042396
hql = "from fum1 in class Fum where size(fum1.Friends) = 0";
24052397
s.CreateQuery(hql).List();
@@ -2465,15 +2457,9 @@ public void CollectionsInSelect()
24652457
Assert.AreEqual(baz.Name, r.Name);
24662458
Assert.AreEqual(1, r.Count);
24672459

2468-
// TODO: figure out a better way
2469-
// in hibernate this is hard coded as 696969696969696938l which is very dependant upon
2470-
// how the test are run because it is calculated on a global static variable...
2471-
// maybe a better way to test this would be to assume that the first
2472-
//Assert.AreEqual( 696969696969696969L, r.Amount );
2473-
24742460
s.CreateQuery("select max( elements(bar.Baz.FooArray) ) from Bar as bar").List();
24752461
// the following test is disable for databases with no subselects... also for Interbase (not sure why) - comment from h2.0.3
2476-
if (dialect.SupportsSubSelects)
2462+
if (Dialect.SupportsSubSelects)
24772463
{
24782464
s.CreateQuery("select count(*) from Baz as baz where 1 in indices(baz.FooArray)").List();
24792465
s.CreateQuery("select count(*) from Bar as bar where 'abc' in elements(bar.Baz.FooArray)").List();
@@ -2491,7 +2477,7 @@ public void CollectionsInSelect()
24912477
.List();
24922478

24932479
// TODO: figure out why this is throwing an ORA-1722 error
2494-
if (!(dialect is Oracle9Dialect))
2480+
if (!(Dialect is Oracle9Dialect))
24952481
{
24962482
s.CreateQuery(
24972483
"select count(*) from Bar as bar left outer join bar.Component.Glarch.ProxyArray as pg where 1 in (from g in bar.Component.Glarch.ProxyArray)")
@@ -2615,7 +2601,9 @@ public void NewFlushing()
26152601
IList newList = new ArrayList();
26162602
newList.Add("value");
26172603
baz.StringList = newList;
2618-
enumer = s.CreateQuery("from foo in class Foo").Enumerable().GetEnumerator(); //no flush
2604+
2605+
s.CreateQuery("from foo in class Foo").Enumerable().GetEnumerator(); //no flush
2606+
26192607
baz.StringList = null;
26202608
enumer = s.CreateQuery("select baz.StringList.elements from baz in class Baz").Enumerable().GetEnumerator();
26212609
Assert.IsFalse(enumer.MoveNext());
@@ -2669,7 +2657,7 @@ public void PersistCollections()
26692657
IList list;
26702658

26712659
// disable this for dbs with no subselects
2672-
if (dialect.SupportsSubSelects)
2660+
if (Dialect.SupportsSubSelects)
26732661
{
26742662
list =
26752663
s.CreateQuery(
@@ -2832,10 +2820,10 @@ public void PersistCollections()
28322820
s.Delete(baz.TopGlarchez['H']);
28332821

28342822
IDbCommand cmd = s.Connection.CreateCommand();
2835-
cmd.CommandText = "update " + dialect.QuoteForTableName("glarchez") + " set baz_map_id=null where baz_map_index='a'";
2823+
cmd.CommandText = "update " + Dialect.QuoteForTableName("glarchez") + " set baz_map_id=null where baz_map_index='a'";
28362824
int rows = cmd.ExecuteNonQuery();
28372825
Assert.AreEqual(1, rows);
2838-
Assert.AreEqual(1, s.Delete("from bar in class NHibernate.DomainModel.Bar"));
2826+
Assert.AreEqual(2, s.Delete("from bar in class NHibernate.DomainModel.Bar"));
28392827
FooProxy[] arr = baz.FooArray;
28402828
Assert.AreEqual(4, arr.Length);
28412829
Assert.AreEqual(foo.Key, arr[1].Key);
@@ -3154,7 +3142,7 @@ public void CollectionOfSelf()
31543142
Assert.IsTrue(bar.Abstracts.Contains(bar), "collection contains self");
31553143
Assert.AreSame(bar, bar.TheFoo, "association to self");
31563144

3157-
if (dialect is MySQLDialect)
3145+
if (Dialect is MySQLDialect)
31583146
{
31593147
// Break the self-reference cycle to avoid error when deleting the row
31603148
bar.TheFoo = null;
@@ -3866,7 +3854,7 @@ public void RecursiveLoad()
38663854

38673855
private bool DialectSupportsCountDistinct
38683856
{
3869-
get { return !(dialect is SQLiteDialect); }
3857+
get { return !(Dialect is SQLiteDialect); }
38703858
}
38713859

38723860
[Test]
@@ -4746,7 +4734,7 @@ public void Refresh()
47464734
s.Flush();
47474735

47484736
IDbCommand cmd = s.Connection.CreateCommand();
4749-
cmd.CommandText = "update " + dialect.QuoteForTableName("foos") + " set long_ = -3";
4737+
cmd.CommandText = "update " + Dialect.QuoteForTableName("foos") + " set long_ = -3";
47504738
cmd.ExecuteNonQuery();
47514739

47524740
s.Refresh(foo);
@@ -4770,10 +4758,10 @@ public void RefreshTransient()
47704758

47714759
s = OpenSession();
47724760
IDbCommand cmd = s.Connection.CreateCommand();
4773-
cmd.CommandText = "update " + dialect.QuoteForTableName("foos") + " set long_ = -3";
4761+
cmd.CommandText = "update " + Dialect.QuoteForTableName("foos") + " set long_ = -3";
47744762
cmd.ExecuteNonQuery();
47754763
s.Refresh(foo);
4776-
Assert.AreEqual((long) -3, foo.Long);
4764+
Assert.AreEqual(-3L, foo.Long);
47774765
s.Delete(foo);
47784766
s.Flush();
47794767
s.Close();
@@ -4795,7 +4783,7 @@ public void AutoFlush()
47954783
s = OpenSession();
47964784
foo = (FooProxy) s.Load(typeof(Foo), foo.Key);
47974785

4798-
if (dialect.SupportsSubSelects)
4786+
if (Dialect.SupportsSubSelects)
47994787
{
48004788
foo.Bytes = GetBytes("osama");
48014789
Assert.AreEqual(1,
@@ -4919,7 +4907,7 @@ public void AutoFlushCollections()
49194907
GetEnumerator();
49204908
Assert.IsTrue(e.MoveNext());
49214909

4922-
if (dialect.SupportsSubSelects && !(dialect is FirebirdDialect))
4910+
if (Dialect.SupportsSubSelects && !(Dialect is FirebirdDialect))
49234911
{
49244912
baz.FooArray[0] = null;
49254913
e = s.CreateQuery("from baz in class NHibernate.DomainModel.Baz where ? in baz.FooArray.elements")
@@ -5510,4 +5498,4 @@ public void ParameterInOrderByClause()
55105498

55115499
#endregion
55125500
}
5513-
}
5501+
}

src/NHibernate.Test/Legacy/FumTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ public void CompositeKeyPathExpressions()
605605
{
606606
s.CreateQuery("select fum1.Fo from fum1 in class Fum where fum1.Fo.FumString is not null").List();
607607
s.CreateQuery("from fum1 in class Fum where fum1.Fo.FumString is not null order by fum1.Fo.FumString").List();
608-
if (dialect.SupportsSubSelects)
608+
if (Dialect.SupportsSubSelects)
609609
{
610610
s.CreateQuery("from fum1 in class Fum where exists elements(fum1.Friends)").List();
611611
s.CreateQuery("from fum1 in class Fum where size(fum1.Friends) = 0").List();

src/NHibernate.Test/Legacy/MasterDetailTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public void SelfManyToOne()
229229
m = (Master) enumer.Current;
230230
Assert.AreSame(m, m.OtherMaster);
231231

232-
if (dialect is MySQLDialect)
232+
if (Dialect is MySQLDialect)
233233
{
234234
m.OtherMaster = null;
235235
s.Flush();
@@ -283,7 +283,7 @@ public void ExampleTest()
283283
.UniqueResult();
284284
Assert.IsNull(m2);
285285

286-
if (dialect is MySQLDialect)
286+
if (Dialect is MySQLDialect)
287287
{
288288
m1.OtherMaster = null;
289289
s.Flush();
@@ -355,7 +355,7 @@ public void CollectionQuery()
355355
ISession s = OpenSession();
356356
ITransaction t = s.BeginTransaction();
357357

358-
if (dialect.SupportsSubSelects)
358+
if (Dialect.SupportsSubSelects)
359359
{
360360
s.CreateQuery("FROM m IN CLASS Master WHERE NOT EXISTS ( FROM d in m.Details.elements WHERE NOT d.I=5 )").Enumerable
361361
();
@@ -390,7 +390,7 @@ public void MasterDetail()
390390
master.AddDetail(d1);
391391
master.AddDetail(d2);
392392

393-
if (dialect.SupportsSubSelects)
393+
if (Dialect.SupportsSubSelects)
394394
{
395395
string hql = "from d in class NHibernate.DomainModel.Detail, m in class NHibernate.DomainModel.Master " +
396396
"where m = d.Master and m.Outgoing.size = 0 and m.Incoming.size = 0";
@@ -640,7 +640,7 @@ public void Serialization()
640640
d2.Master = (m);
641641
m.AddDetail(d1);
642642
m.AddDetail(d2);
643-
if ((dialect is SybaseDialect) || (dialect is MsSql2000Dialect))
643+
if ((Dialect is SybaseDialect) || (Dialect is MsSql2000Dialect))
644644
{
645645
s.Save(d1);
646646
}
@@ -732,7 +732,7 @@ public void UpdateLazyCollections()
732732
d2.Master = m;
733733
m.AddDetail(d1);
734734
m.AddDetail(d2);
735-
if ((dialect is SybaseDialect) || (dialect is MsSql2000Dialect))
735+
if ((Dialect is SybaseDialect) || (Dialect is MsSql2000Dialect))
736736
{
737737
s.Save(d1);
738738
s.Save(d2);

0 commit comments

Comments
 (0)