@@ -31,35 +31,30 @@ public class InvalidationTestsAsync : TestCase
31
31
32
32
protected override void Configure ( Configuration configuration )
33
33
{
34
- base . Configure ( configuration ) ;
35
- configuration . Properties [ Environment . CacheProvider ] = typeof ( HashtableCacheProvider ) . AssemblyQualifiedName ;
36
- configuration . Properties [ Environment . UseQueryCache ] = "true" ;
34
+ configuration . SetProperty ( Environment . CacheProvider , typeof ( HashtableCacheProvider ) . AssemblyQualifiedName ) ;
35
+ configuration . SetProperty ( Environment . UseQueryCache , "true" ) ;
37
36
}
38
37
39
38
[ Test ]
40
39
public async Task InvalidatesEntitiesAsync ( )
41
40
{
41
+ var debugSessionFactory = ( DebugSessionFactory ) Sfi ;
42
+ var sessionFactoryImpl = ( SessionFactoryImpl ) debugSessionFactory . ActualFactory ;
43
+
42
44
var cache = Substitute . For < UpdateTimestampsCache > ( Sfi . Settings , new Dictionary < string , string > ( ) ) ;
43
- ( ( SessionFactoryImpl ) ( Sfi as DebugSessionFactory ) . ActualFactory ) . SetPropertyUsingReflection (
44
- x => x . UpdateTimestampsCache ,
45
- cache ) ;
45
+ sessionFactoryImpl . SetPropertyUsingReflection ( x => x . UpdateTimestampsCache , cache ) ;
46
46
47
47
//"Received" assertions can not be used since the collection is reused and cleared between calls.
48
48
//The received args are cloned and stored
49
49
var preInvalidations = new List < IReadOnlyCollection < string > > ( ) ;
50
50
var invalidations = new List < IReadOnlyCollection < string > > ( ) ;
51
51
52
- await cache . PreInvalidateAsync (
53
- Arg . Do < IReadOnlyCollection < string > > ( x => preInvalidations . Add ( x . ToList ( ) ) ) ,
54
- CancellationToken . None ) ;
55
-
56
- await cache . InvalidateAsync (
57
- Arg . Do < IReadOnlyCollection < string > > ( x => invalidations . Add ( x . ToList ( ) ) ) ,
58
- CancellationToken . None ) ;
52
+ await ( cache . PreInvalidateAsync ( Arg . Do < IReadOnlyCollection < string > > ( x => preInvalidations . Add ( x . ToList ( ) ) ) , CancellationToken . None ) ) ;
53
+ await ( cache . InvalidateAsync ( Arg . Do < IReadOnlyCollection < string > > ( x => invalidations . Add ( x . ToList ( ) ) ) , CancellationToken . None ) ) ;
59
54
60
- using ( ISession session = OpenSession ( ) )
55
+ using ( var session = OpenSession ( ) )
61
56
{
62
- using ( ITransaction tx = session . BeginTransaction ( ) )
57
+ using ( var tx = session . BeginTransaction ( ) )
63
58
{
64
59
foreach ( var i in Enumerable . Range ( 1 , 10 ) )
65
60
{
@@ -70,7 +65,7 @@ await cache.InvalidateAsync(
70
65
await ( tx . CommitAsync ( ) ) ;
71
66
}
72
67
73
- using ( ITransaction tx = session . BeginTransaction ( ) )
68
+ using ( var tx = session . BeginTransaction ( ) )
74
69
{
75
70
foreach ( var i in Enumerable . Range ( 1 , 10 ) )
76
71
{
@@ -81,7 +76,7 @@ await cache.InvalidateAsync(
81
76
await ( tx . CommitAsync ( ) ) ;
82
77
}
83
78
84
- using ( ITransaction tx = session . BeginTransaction ( ) )
79
+ using ( var tx = session . BeginTransaction ( ) )
85
80
{
86
81
foreach ( var i in Enumerable . Range ( 1 , 10 ) )
87
82
{
@@ -94,38 +89,21 @@ await cache.InvalidateAsync(
94
89
}
95
90
96
91
//Should receive one preinvalidation and one invalidation per commit
97
- Assert . That ( preInvalidations . Count , Is . EqualTo ( 3 ) ) ;
98
- Assert . That ( preInvalidations . All ( x => x . Count == 1 && x . First ( ) == "Item" ) , Is . True ) ;
92
+ Assert . That ( preInvalidations , Has . Count . EqualTo ( 3 ) ) ;
93
+ Assert . That ( preInvalidations , Has . All . Count . EqualTo ( 1 ) . And . Contains ( "Item" ) ) ;
99
94
100
- Assert . That ( invalidations . Count , Is . EqualTo ( 3 ) ) ;
101
- Assert . That ( invalidations . All ( x => x . Count == 1 && x . First ( ) == "Item" ) , Is . True ) ;
102
-
103
- }
104
-
105
- public async Task CleanUpAsync ( CancellationToken cancellationToken = default ( CancellationToken ) )
106
- {
107
- using ( ISession s = OpenSession ( ) )
108
- using ( ITransaction tx = s . BeginTransaction ( ) )
109
- {
110
- await ( s . DeleteAsync ( "from Item" , cancellationToken ) ) ;
111
- await ( tx . CommitAsync ( cancellationToken ) ) ;
112
- }
95
+ Assert . That ( invalidations , Has . Count . EqualTo ( 3 ) ) ;
96
+ Assert . That ( invalidations , Has . All . Count . EqualTo ( 1 ) . And . Contains ( "Item" ) ) ;
113
97
}
114
-
115
- public void CleanUp ( )
98
+
99
+ protected override void OnTearDown ( )
116
100
{
117
- using ( ISession s = OpenSession ( ) )
118
- using ( ITransaction tx = s . BeginTransaction ( ) )
101
+ using ( var s = OpenSession ( ) )
102
+ using ( var tx = s . BeginTransaction ( ) )
119
103
{
120
104
s . Delete ( "from Item" ) ;
121
105
tx . Commit ( ) ;
122
106
}
123
107
}
124
-
125
- protected override void OnTearDown ( )
126
- {
127
- CleanUp ( ) ;
128
- base . OnTearDown ( ) ;
129
- }
130
108
}
131
109
}
0 commit comments