File tree Expand file tree Collapse file tree 8 files changed +173
-6
lines changed
Async/NHSpecificTest/GH1515 Expand file tree Collapse file tree 8 files changed +173
-6
lines changed Original file line number Diff line number Diff line change
1
+ //------------------------------------------------------------------------------
2
+ // <auto-generated>
3
+ // This code was generated by AsyncGenerator.
4
+ //
5
+ // Changes to this file may cause incorrect behavior and will be lost if
6
+ // the code is regenerated.
7
+ // </auto-generated>
8
+ //------------------------------------------------------------------------------
9
+
10
+
11
+ using NHibernate . Collection ;
12
+ using NSubstitute ;
13
+ using NUnit . Framework ;
14
+
15
+ namespace NHibernate . Test . NHSpecificTest . GH1515
16
+ {
17
+ using System . Threading . Tasks ;
18
+ using System . Threading ;
19
+ [ TestFixture ]
20
+ public class FixtureAsync
21
+ {
22
+
23
+ [ Test ]
24
+ public async Task IntializeForwaredToLazyCollectionAsync ( )
25
+ {
26
+ var collection = Substitute . For < ILazyInitializedCollection > ( ) ;
27
+
28
+ await ( NHibernateUtil . InitializeAsync ( collection ) ) ;
29
+
30
+ await ( collection . Received ( ) . ForceInitializationAsync ( CancellationToken . None ) ) ;
31
+ }
32
+
33
+ [ Test ]
34
+ public async Task IntializeForwaredToPersistentCollectionAsync ( )
35
+ {
36
+ var collection = Substitute . For < IPersistentCollection > ( ) ;
37
+
38
+ await ( NHibernateUtil . InitializeAsync ( collection ) ) ;
39
+
40
+ await ( collection . Received ( ) . ForceInitializationAsync ( CancellationToken . None ) ) ;
41
+ }
42
+
43
+
44
+ }
45
+ }
Original file line number Diff line number Diff line change
1
+ using NHibernate . Collection ;
2
+ using NSubstitute ;
3
+ using NUnit . Framework ;
4
+
5
+ namespace NHibernate . Test . NHSpecificTest . GH1515
6
+ {
7
+ [ TestFixture ]
8
+ public class Fixture
9
+ {
10
+ [ Test ]
11
+ public void IsInitializedCallsWasInitializedFromLazyCollection ( )
12
+ {
13
+ var collection = Substitute . For < ILazyInitializedCollection > ( ) ;
14
+
15
+ NHibernateUtil . IsInitialized ( collection ) ;
16
+
17
+ var assertRes = collection . Received ( ) . WasInitialized ;
18
+ }
19
+
20
+ [ Test ]
21
+ public void IntializeForwaredToLazyCollection ( )
22
+ {
23
+ var collection = Substitute . For < ILazyInitializedCollection > ( ) ;
24
+
25
+ NHibernateUtil . Initialize ( collection ) ;
26
+
27
+ collection . Received ( ) . ForceInitialization ( ) ;
28
+ }
29
+
30
+ [ Test ]
31
+ public void IsInitializedCallsWasInitializedFromPersistentCollection ( )
32
+ {
33
+ var collection = Substitute . For < IPersistentCollection > ( ) ;
34
+
35
+ NHibernateUtil . IsInitialized ( collection ) ;
36
+
37
+ var assertRes = collection . Received ( ) . WasInitialized ;
38
+ }
39
+
40
+ [ Test ]
41
+ public void IntializeForwaredToPersistentCollection ( )
42
+ {
43
+ var collection = Substitute . For < IPersistentCollection > ( ) ;
44
+
45
+ NHibernateUtil . Initialize ( collection ) ;
46
+
47
+ collection . Received ( ) . ForceInitialization ( ) ;
48
+ }
49
+
50
+
51
+ }
52
+ }
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ namespace NHibernate.Collection
24
24
{
25
25
using System . Threading . Tasks ;
26
26
using System . Threading ;
27
- public abstract partial class AbstractPersistentCollection : IPersistentCollection
27
+ public abstract partial class AbstractPersistentCollection : IPersistentCollection , ILazyInitializedCollection
28
28
{
29
29
30
30
/// <summary>
Original file line number Diff line number Diff line change
1
+ //------------------------------------------------------------------------------
2
+ // <auto-generated>
3
+ // This code was generated by AsyncGenerator.
4
+ //
5
+ // Changes to this file may cause incorrect behavior and will be lost if
6
+ // the code is regenerated.
7
+ // </auto-generated>
8
+ //------------------------------------------------------------------------------
9
+
10
+
11
+ namespace NHibernate . Collection
12
+ {
13
+ using System . Threading . Tasks ;
14
+ using System . Threading ;
15
+ public partial interface ILazyInitializedCollection
16
+ {
17
+
18
+ /// <summary>
19
+ /// Force immediate initialization.
20
+ /// </summary>
21
+ /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param>
22
+ Task ForceInitializationAsync ( CancellationToken cancellationToken ) ;
23
+
24
+ }
25
+ }
Original file line number Diff line number Diff line change @@ -48,11 +48,17 @@ public static partial class NHibernateUtil
48
48
{
49
49
return ( ( INHibernateProxy ) proxy ) . HibernateLazyInitializer . InitializeAsync ( cancellationToken ) ;
50
50
}
51
- else if ( proxy is IPersistentCollection coll )
51
+ else if ( proxy is ILazyInitializedCollection coll )
52
52
{
53
53
return coll . ForceInitializationAsync ( cancellationToken ) ;
54
54
}
55
+ // 6.0 TODO: remove once IPersistentCollection derives from ILazyInitializedCollection
56
+ else if ( proxy is IPersistentCollection persistent )
57
+ {
58
+ return persistent . ForceInitializationAsync ( cancellationToken ) ;
59
+ }
55
60
return Task . CompletedTask ;
61
+
56
62
}
57
63
catch ( Exception ex )
58
64
{
Original file line number Diff line number Diff line change @@ -15,8 +15,9 @@ namespace NHibernate.Collection
15
15
/// <summary>
16
16
/// Base class for implementing <see cref="IPersistentCollection"/>.
17
17
/// </summary>
18
+ // 6.0 TODO: remove ILazyInitializedCollection once IPersistentCollection derives from it
18
19
[ Serializable ]
19
- public abstract partial class AbstractPersistentCollection : IPersistentCollection
20
+ public abstract partial class AbstractPersistentCollection : IPersistentCollection , ILazyInitializedCollection
20
21
{
21
22
protected internal static readonly object Unknown = new object ( ) ; //place holder
22
23
protected internal static readonly object NotFound = new object ( ) ; //place holder
Original file line number Diff line number Diff line change
1
+ namespace NHibernate . Collection
2
+ {
3
+ /// <summary>
4
+ /// This interface allows to check if a lazy collection is already initialized and to force its initialization.
5
+ /// </summary>
6
+ /// <remarks>
7
+ /// This interface is provided to allow implementing lazy initialized collections which do not implement
8
+ /// <see cref="IPersistentCollection" />.
9
+ /// That is e.g. needed for NHibernate.Envers which can't load its collections as PersistentCollections.
10
+ /// </remarks>
11
+ // 6.0 TODO: set as ancestor of IPersistentCollection
12
+ public partial interface ILazyInitializedCollection
13
+ {
14
+ /// <summary>
15
+ /// Return <see langword="true"/> if the proxy has already been initialized.
16
+ /// If <see langword="false"/>, accessing the collection or calling <see cref="ForceInitialization" />
17
+ /// initializes the collection.
18
+ /// </summary>
19
+ bool WasInitialized { get ; }
20
+
21
+ /// <summary>
22
+ /// Force immediate initialization.
23
+ /// </summary>
24
+ void ForceInitialization ( ) ;
25
+
26
+ }
27
+ }
Original file line number Diff line number Diff line change @@ -382,10 +382,16 @@ public static void Initialize(object proxy)
382
382
{
383
383
( ( INHibernateProxy ) proxy ) . HibernateLazyInitializer . Initialize ( ) ;
384
384
}
385
- else if ( proxy is IPersistentCollection coll )
385
+ else if ( proxy is ILazyInitializedCollection coll )
386
386
{
387
387
coll . ForceInitialization ( ) ;
388
388
}
389
+ // 6.0 TODO: remove once IPersistentCollection derives from ILazyInitializedCollection
390
+ else if ( proxy is IPersistentCollection persistent )
391
+ {
392
+ persistent . ForceInitialization ( ) ;
393
+ }
394
+
389
395
}
390
396
391
397
/// <summary>
@@ -399,9 +405,14 @@ public static bool IsInitialized(object proxy)
399
405
{
400
406
return ! ( ( INHibernateProxy ) proxy ) . HibernateLazyInitializer . IsUninitialized ;
401
407
}
402
- else if ( proxy is IPersistentCollection )
408
+ else if ( proxy is ILazyInitializedCollection coll )
409
+ {
410
+ return coll . WasInitialized ;
411
+ }
412
+ // 6.0 TODO: remove once IPersistentCollection derives from ILazyInitializedCollection
413
+ else if ( proxy is IPersistentCollection persistent )
403
414
{
404
- return ( ( IPersistentCollection ) proxy ) . WasInitialized ;
415
+ return persistent . WasInitialized ;
405
416
}
406
417
else
407
418
{
You can’t perform that action at this time.
0 commit comments