Skip to content

Commit 1d4aeba

Browse files
NH-3905 - fixes required in tests for their async counterparts.
1 parent ab9d883 commit 1d4aeba

File tree

8 files changed

+93
-25
lines changed

8 files changed

+93
-25
lines changed

src/AsyncGenerator.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,6 @@
156156
applyChanges: true
157157
analyzation:
158158
methodConversion:
159-
- conversion: Ignore
160-
hasAttributeName: IgnoreAttribute
161159
- conversion: Smart
162160
hasAttributeName: TestAttribute
163161
- conversion: Smart
@@ -250,4 +248,4 @@ typeRules:
250248
name: IsTestCase
251249
- filters:
252250
- hasAttributeName: TestFixtureAttribute
253-
name: HasTestFixtureAttribute
251+
name: HasTestFixtureAttribute

src/NHibernate.Test/Events/Collections/CollectionListeners.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Collections;
22
using System.Collections.Generic;
3+
using System.Threading;
4+
using System.Threading.Tasks;
35
using NHibernate.Event;
46
using NHibernate.Event.Default;
57

@@ -158,6 +160,15 @@ public override void OnInitializeCollection(InitializeCollectionEvent @event)
158160
base.OnInitializeCollection(@event);
159161
AddEvent(@event, this);
160162
}
163+
164+
public override Task OnInitializeCollectionAsync(InitializeCollectionEvent @event, CancellationToken cancellationToken)
165+
{
166+
var result = base.OnInitializeCollectionAsync(@event, cancellationToken);
167+
168+
AddEvent(@event, this);
169+
170+
return result;
171+
}
161172
}
162173

163174
#endregion
@@ -270,4 +281,4 @@ public void OnPreUpdateCollection(PreCollectionUpdateEvent @event)
270281

271282
#endregion
272283
}
273-
}
284+
}

src/NHibernate.Test/Insertordering/InsertOrderingFixture.cs

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
using System.Data;
55
using System.Data.Common;
66
using System.Linq;
7+
using System.Threading;
8+
using System.Threading.Tasks;
79
using NHibernate.AdoNet;
810
using NHibernate.Cfg;
911
using NHibernate.Dialect;
@@ -13,6 +15,8 @@
1315
using NHibernate.SqlTypes;
1416
using NUnit.Framework;
1517

18+
using AsyncTask = System.Threading.Tasks.Task;
19+
1620
namespace NHibernate.Test.Insertordering
1721
{
1822
[TestFixture]
@@ -559,10 +563,26 @@ public override DbCommand PrepareBatchCommand(CommandType type, SqlString sql, S
559563
{
560564
var result = base.PrepareBatchCommand(type, sql, parameterTypes);
561565

566+
PrepareStats(sql);
567+
568+
return result;
569+
}
570+
571+
public override Task<DbCommand> PrepareBatchCommandAsync(CommandType type, SqlString sql, SqlType[] parameterTypes, CancellationToken cancellationToken)
572+
{
573+
var result = base.PrepareBatchCommandAsync(type, sql, parameterTypes, cancellationToken);
574+
575+
PrepareStats(sql);
576+
577+
return result;
578+
}
579+
580+
private static void PrepareStats(SqlString sql)
581+
{
562582
if (!StatsEnabled)
563-
return result;
583+
return;
564584

565-
string sqlstring = sql.ToString();
585+
var sqlstring = sql.ToString();
566586
if (batchSQL == null || !sqlstring.Equals(batchSQL))
567587
{
568588
currentBatch++;
@@ -571,29 +591,50 @@ public override DbCommand PrepareBatchCommand(CommandType type, SqlString sql, S
571591
Console.WriteLine("--------------------------------------------------------");
572592
Console.WriteLine("Preparing statement [" + batchSQL + "]");
573593
}
574-
return result;
575594
}
576595

577596
public override void AddToBatch(IExpectation expectation)
578597
{
579-
if (StatsEnabled)
580-
{
581-
batchSizes[currentBatch]++;
582-
Console.WriteLine("Adding to batch [" + batchSQL + "]");
583-
}
598+
AddStats();
584599
base.AddToBatch(expectation);
585600
}
586601

602+
public override AsyncTask AddToBatchAsync(IExpectation expectation, CancellationToken cancellationToken)
603+
{
604+
AddStats();
605+
return base.AddToBatchAsync(expectation, cancellationToken);
606+
}
607+
608+
private static void AddStats()
609+
{
610+
if (!StatsEnabled)
611+
return;
612+
613+
batchSizes[currentBatch]++;
614+
Console.WriteLine("Adding to batch [" + batchSQL + "]");
615+
}
616+
587617
protected override void DoExecuteBatch(DbCommand ps)
588618
{
589-
if (StatsEnabled)
590-
{
591-
Console.WriteLine("executing batch [" + batchSQL + "]");
592-
Console.WriteLine("--------------------------------------------------------");
593-
}
594-
batchSQL = null;
619+
ExecuteStats();
595620
base.DoExecuteBatch(ps);
596621
}
622+
623+
protected override AsyncTask DoExecuteBatchAsync(DbCommand ps, CancellationToken cancellationToken)
624+
{
625+
ExecuteStats();
626+
return base.DoExecuteBatchAsync(ps, cancellationToken);
627+
}
628+
629+
private static void ExecuteStats()
630+
{
631+
if (!StatsEnabled)
632+
return;
633+
634+
Console.WriteLine("executing batch [" + batchSQL + "]");
635+
Console.WriteLine("--------------------------------------------------------");
636+
batchSQL = null;
637+
}
597638
}
598639

599640
#endregion

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
using System;
2+
using System.Collections.Generic;
13
using System.Linq;
24
using NHibernate.DomainModel.Northwind.Entities;
5+
using NHibernate.Exceptions;
36
using NHibernate.Linq;
47
using NUnit.Framework;
58

@@ -30,8 +33,10 @@ where a.Pregnant
3033
public void CastDowncast()
3134
{
3235
var query = session.Query<Mammal>().Cast<Dog>();
36+
List<Dog> list;
3337
// the list contains at least one Cat then should Throws
34-
Assert.That(() => query.ToList(), Throws.Exception);
38+
// Do not use bare Throws.Exception due to https://github.com/nunit/nunit/issues/1899
39+
Assert.That(() => list = query.ToList(), Throws.InstanceOf<GenericADOException>());
3540
}
3641

3742
[Test]
@@ -47,7 +52,8 @@ public void CastDowncastUsingOfType()
4752
{
4853
var query = session.Query<Animal>().OfType<Mammal>().Cast<Dog>();
4954
// the list contains at least one Cat then should Throws
50-
Assert.That(() => query.ToList(), Throws.Exception);
55+
// Do not use bare Throws.Exception due to https://github.com/nunit/nunit/issues/1899
56+
Assert.That(() => query.ToList(), Throws.InstanceOf<Exception>());
5157
}
5258
}
5359
}

src/NHibernate.Test/Linq/QueryTimeoutTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System.Data.Common;
22
using System.Linq;
3+
using System.Threading;
4+
using System.Threading.Tasks;
35
using NHibernate.AdoNet;
46
using NHibernate.Cfg;
57
using NHibernate.Dialect;
@@ -105,6 +107,12 @@ public override DbDataReader ExecuteReader(DbCommand cmd)
105107
LastCommandTimeout = cmd.CommandTimeout;
106108
return base.ExecuteReader(cmd);
107109
}
110+
111+
public override Task<DbDataReader> ExecuteReaderAsync(DbCommand cmd, CancellationToken cancellationToken)
112+
{
113+
LastCommandTimeout = cmd.CommandTimeout;
114+
return base.ExecuteReaderAsync(cmd, cancellationToken);
115+
}
108116
}
109117

110118

src/NHibernate.Test/MappingByCode/IntegrationTests/NH3269/FixtureNonPublicProperty.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NHibernate.Cfg.MappingSchema;
1+
using System;
2+
using NHibernate.Cfg.MappingSchema;
23
using NHibernate.Mapping.ByCode;
34
using NUnit.Framework;
45

@@ -16,7 +17,8 @@ public void ShouldThrowExceptionWhenTryingToSaveInherited1WithDuplicateName()
1617
var e1 = new Inherited1 { Name = "Bob" };
1718
session.Save(e1);
1819

19-
Assert.That(() => { transaction.Commit(); }, Throws.Exception);
20+
// Do not use bare Throws.Exception due to https://github.com/nunit/nunit/issues/1899
21+
Assert.That(() => { transaction.Commit(); }, Throws.InstanceOf<Exception>());
2022
}
2123
}
2224

src/NHibernate.Test/MappingByCode/IntegrationTests/NH3269/FixturePublicProperty.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NHibernate.Cfg.MappingSchema;
1+
using System;
2+
using NHibernate.Cfg.MappingSchema;
23
using NHibernate.Mapping.ByCode;
34
using NUnit.Framework;
45

@@ -16,7 +17,8 @@ public void ShouldThrowExceptionWhenTryingToSaveInherited1WithDuplicateName()
1617
var e1 = new Inherited1 { Name = "Bob" };
1718
session.Save(e1);
1819

19-
Assert.That(() => { transaction.Commit(); }, Throws.Exception);
20+
// Do not use bare Throws.Exception due to https://github.com/nunit/nunit/issues/1899
21+
Assert.That(() => { transaction.Commit(); }, Throws.InstanceOf<Exception>());
2022
}
2123
}
2224

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void WhenParameterListIsNullUsingQueryThenTrowsArgumentException()
4747
using (var s = OpenSession())
4848
{
4949
var query = s.CreateQuery("from AnEntity a where a.id in (:myList)");
50-
Assert.That(() => query.SetParameterList("myList", null), Throws.Exception.InstanceOf<ArgumentNullException>());
50+
Assert.That(() => query.SetParameterList("myList", null), Throws.InstanceOf<ArgumentNullException>());
5151
}
5252
}
5353

0 commit comments

Comments
 (0)