1
1
using System . Collections ;
2
2
using System . Collections . Generic ;
3
3
using System . Linq ;
4
- using System . Text ;
5
- using System . Threading . Tasks ;
6
4
using NHibernate . Cache ;
7
5
using NHibernate . Cfg ;
8
6
using NHibernate . Impl ;
9
7
using NHibernate . Test . SecondLevelCacheTests ;
10
8
using NSubstitute ;
11
9
using NUnit . Framework ;
12
- using Environment = System . Environment ;
13
10
14
11
namespace NHibernate . Test . SecondLevelCacheTest
15
12
{
@@ -23,8 +20,8 @@ public class InvalidationTests : TestCase
23
20
protected override void Configure ( Configuration configuration )
24
21
{
25
22
base . Configure ( configuration ) ;
26
- configuration . Properties [ Cfg . Environment . CacheProvider ] = typeof ( HashtableCacheProvider ) . AssemblyQualifiedName ;
27
- configuration . Properties [ Cfg . Environment . UseQueryCache ] = "true" ;
23
+ configuration . Properties [ Environment . CacheProvider ] = typeof ( HashtableCacheProvider ) . AssemblyQualifiedName ;
24
+ configuration . Properties [ Environment . UseQueryCache ] = "true" ;
28
25
}
29
26
30
27
[ Test ]
@@ -35,7 +32,18 @@ public void InvalidatesEntities()
35
32
x => x . UpdateTimestampsCache ,
36
33
cache ) ;
37
34
38
- var items = new List < Item > ( ) ;
35
+ //"Received" assertions can not be used since the collection is reused and cleared between calls.
36
+ //The received args are cloned and stored
37
+ var preInvalidations = new List < IReadOnlyCollection < string > > ( ) ;
38
+ var invalidations = new List < IReadOnlyCollection < string > > ( ) ;
39
+
40
+ cache
41
+ . When ( x=> x . PreInvalidate ( Arg . Any < IReadOnlyCollection < string > > ( ) ) )
42
+ . Do ( x=> preInvalidations . Add ( ( ( IReadOnlyCollection < string > ) x [ 0 ] ) . ToList ( ) ) ) ;
43
+ cache
44
+ . When ( x => x . Invalidate ( Arg . Any < IReadOnlyCollection < string > > ( ) ) )
45
+ . Do ( x => invalidations . Add ( ( ( IReadOnlyCollection < string > ) x [ 0 ] ) . ToList ( ) ) ) ;
46
+
39
47
using ( ISession session = OpenSession ( ) )
40
48
{
41
49
using ( ITransaction tx = session . BeginTransaction ( ) )
@@ -73,8 +81,17 @@ public void InvalidatesEntities()
73
81
}
74
82
75
83
//Should receive one preinvalidation and one invalidation per commit
76
- cache . Received ( 3 ) . PreInvalidate ( Arg . Is < IReadOnlyCollection < object > > ( x => x . Count == 1 && ( string ) x . First ( ) == "Item" ) ) ;
77
- cache . Received ( 3 ) . Invalidate ( Arg . Is < IReadOnlyCollection < object > > ( x => x . Count == 1 && ( string ) x . First ( ) == "Item" ) ) ;
84
+ Assert . That ( preInvalidations . Count , Is . EqualTo ( 3 ) ) ;
85
+ Assert . That ( preInvalidations . All ( x => x . Count == 1 && x . First ( ) == "Item" ) , Is . True ) ;
86
+
87
+ Assert . That ( invalidations . Count , Is . EqualTo ( 3 ) ) ;
88
+ Assert . That ( invalidations . All ( x => x . Count == 1 && x . First ( ) == "Item" ) , Is . True ) ;
89
+
90
+ }
91
+
92
+ private bool IsRight ( HashSet < string > x )
93
+ {
94
+ return x . Count == 1 && x . First ( ) == "Item" ;
78
95
}
79
96
80
97
public void CleanUp ( )
0 commit comments