@@ -63,22 +63,20 @@ public void GetFilters_CachesFilterFromFactory()
63
63
new [ ] { new DefaultFilterProvider ( ) } ) ;
64
64
var filterDescriptors = controllerContext . ActionDescriptor . FilterDescriptors ;
65
65
66
- // Act - 1
66
+ // Act & Assert
67
67
var filters = controllerActionInvokerCache . GetState ( controllerContext ) . Filters ;
68
-
69
- // Assert - 1
70
68
Assert . Equal ( 2 , filters . Length ) ;
71
- var request1Filter1 = Assert . IsType < TestFilter > ( filters [ 0 ] ) ; // Created by factory
69
+ var cachedFactoryCreatedFilter = Assert . IsType < TestFilter > ( filters [ 0 ] ) ; // Created by factory
72
70
Assert . Same ( staticFilter , filters [ 1 ] ) ; // Cached and the same statically created filter instance
73
71
74
- // Act - 2
75
- filters = controllerActionInvokerCache . GetState ( controllerContext ) . Filters ;
72
+ for ( var i = 0 ; i < 5 ; i ++ )
73
+ {
74
+ filters = controllerActionInvokerCache . GetState ( controllerContext ) . Filters ;
76
75
77
- // Assert - 2
78
- Assert . Collection (
79
- filters ,
80
- f => Assert . Same ( request1Filter1 , f ) , // Cached
81
- f => Assert . Same ( staticFilter , f ) ) ; // Cached and the same statically created filter instance
76
+ var currentFactoryCreatedFilter = filters [ 0 ] ;
77
+ Assert . Same ( currentFactoryCreatedFilter , cachedFactoryCreatedFilter ) ; // Cached
78
+ Assert . Same ( staticFilter , filters [ 1 ] ) ; // Cached
79
+ }
82
80
}
83
81
84
82
[ Fact ]
@@ -96,22 +94,18 @@ public void GetFilters_DoesNotCacheFiltersWithIsReusableFalse()
96
94
new [ ] { new DefaultFilterProvider ( ) } ) ;
97
95
var filterDescriptors = controllerContext . ActionDescriptor . FilterDescriptors ;
98
96
99
- // Act - 1
100
- var filters = controllerActionInvokerCache . GetState ( controllerContext ) . Filters ;
97
+ // Act & Assert
98
+ IFilterMetadata previousFactoryCreatedFilter = null ;
99
+ for ( var i = 0 ; i < 5 ; i ++ )
100
+ {
101
+ var filters = controllerActionInvokerCache . GetState ( controllerContext ) . Filters ;
101
102
102
- // Assert - 1
103
- Assert . Equal ( 2 , filters . Length ) ;
104
- var request1Filter1 = Assert . IsType < TestFilter > ( filters [ 0 ] ) ; // Created by factory
105
- Assert . Same ( staticFilter , filters [ 1 ] ) ; // Cached and the same statically created filter instance
103
+ var currentFactoryCreatedFilter = filters [ 0 ] ;
104
+ Assert . NotSame ( currentFactoryCreatedFilter , previousFactoryCreatedFilter ) ; // Never Cached
105
+ Assert . Same ( staticFilter , filters [ 1 ] ) ; // Cached
106
106
107
- // Act - 2
108
- filters = controllerActionInvokerCache . GetState ( controllerContext ) . Filters ;
109
-
110
- // Assert - 2
111
- Assert . Collection (
112
- filters ,
113
- f => Assert . NotSame ( request1Filter1 , f ) , // Created by factory again
114
- f => Assert . Same ( staticFilter , f ) ) ; // Cached and the same statically created filter instance
107
+ previousFactoryCreatedFilter = currentFactoryCreatedFilter ;
108
+ }
115
109
}
116
110
117
111
[ Fact ]
0 commit comments