88using BitFaster . Caching . Atomic ;
99using FluentAssertions ;
1010using Xunit ;
11+ using Moq ;
1112
1213namespace BitFaster . Caching . UnitTests . Atomic
1314{
@@ -29,7 +30,7 @@ public void WhenInnerCacheIsNullCtorThrows()
2930 [ Fact ]
3031 public void WhenCreatedCapacityPropertyWrapsInnerCache ( )
3132 {
32- this . cache . Policy . Eviction . Capacity . Should ( ) . Be ( capacity ) ;
33+ this . cache . Policy . Eviction . Value . Capacity . Should ( ) . Be ( capacity ) ;
3334 }
3435
3536 [ Fact ]
@@ -48,21 +49,32 @@ public void WhenItemIsAddedThenLookedUpMetricsAreCorrect()
4849 this . cache . AddOrUpdate ( 1 , 1 ) ;
4950 this . cache . GetOrAdd ( 1 , k => k ) ;
5051
51- this . cache . Metrics . Misses . Should ( ) . Be ( 0 ) ;
52- this . cache . Metrics . Hits . Should ( ) . Be ( 1 ) ;
52+ this . cache . Metrics . Value . Misses . Should ( ) . Be ( 0 ) ;
53+ this . cache . Metrics . Value . Hits . Should ( ) . Be ( 1 ) ;
5354 }
5455
5556 [ Fact ]
5657 public void WhenEventHandlerIsRegisteredItIsFired ( )
5758 {
58- this . cache . Events . ItemRemoved += OnItemRemoved ;
59+ this . cache . Events . Value . ItemRemoved += OnItemRemoved ;
5960
6061 this . cache . AddOrUpdate ( 1 , 1 ) ;
6162 this . cache . TryRemove ( 1 ) ;
6263
6364 this . removedItems . First ( ) . Key . Should ( ) . Be ( 1 ) ;
6465 }
6566
67+ [ Fact ]
68+ public void WhenNoInnerEventsNoOuterEvents ( )
69+ {
70+ var inner = new Mock < ICache < int , AtomicFactory < int , int > > > ( ) ;
71+ inner . SetupGet ( c => c . Events ) . Returns ( Optional < ICacheEvents < int , AtomicFactory < int , int > > > . None ) ;
72+
73+ var cache = new AtomicFactoryCache < int , int > ( inner . Object ) ;
74+
75+ cache . Events . HasValue . Should ( ) . BeFalse ( ) ;
76+ }
77+
6678 [ Fact ]
6779 public void WhenKeyDoesNotExistAddOrUpdateAddsNewItem ( )
6880 {
@@ -114,7 +126,7 @@ public void WhenCacheContainsValuesTrim1RemovesColdestValue()
114126 this . cache . AddOrUpdate ( 1 , 1 ) ;
115127 this . cache . AddOrUpdate ( 2 , 2 ) ;
116128
117- this . cache . Policy . Eviction . Trim ( 1 ) ;
129+ this . cache . Policy . Eviction . Value . Trim ( 1 ) ;
118130
119131 this . cache . TryGet ( 0 , out var value ) . Should ( ) . BeFalse ( ) ;
120132 }
0 commit comments