public void Test_CanGetRegisteredCacheClients_SameType(int additionalRuleCount) { Mock <ICacheClientExtended> fallbackClientMocker = new Mock <ICacheClientExtended>(MockBehavior.Loose); DefaultRoutedCacheClient cacheClient = new DefaultRoutedCacheClient(fallbackClientMocker.Object); for (int i = 0; i < additionalRuleCount; i++) { cacheClient.PushClientWithRule(new KeyStartsWithStringCacheClientRule(new MockCacheClient1(), StringComparison.InvariantCultureIgnoreCase, $":test{i}")); } IDictionary <string, ICacheClient> cacheClients = cacheClient .GetRegisteredClients(); IDictionary <string, ICacheClient> cacheClientsFromExt = cacheClient .GetRegisteredCacheClients(); CollectionAssert.AreEquivalent(cacheClients, cacheClientsFromExt); Assert.AreEqual(additionalRuleCount + 1, cacheClients.Count); Assert.AreEqual(additionalRuleCount, cacheClients.Count(r => r.Key.StartsWith("mockCacheClient1"))); }
public void Test_CorrectlyDisposed_WithImplicityAutoDisposeSettings() { Mock <ICacheClient> sessionClientMocker = new Mock <ICacheClient>(MockBehavior.Strict); Mock <ICacheClient> fallbackClientMocker = new Mock <ICacheClient>(MockBehavior.Strict); sessionClientMocker.Setup(c => c.Dispose()); fallbackClientMocker.Setup(c => c.Dispose()); ICacheClient sessionClient = sessionClientMocker.Object; ICacheClient fallbackClient = fallbackClientMocker.Object; IRoutedCacheClient routedCacheClient = new DefaultRoutedCacheClient(fallbackClient); routedCacheClient.PushClientWithRule(new KeyStartsWithStringCacheClientRule(sessionClient, StringComparison.InvariantCultureIgnoreCase, SessionKeyPrefix)); routedCacheClient.Dispose(); sessionClientMocker.Verify(c => c.Dispose(), Times.Once); fallbackClientMocker.Verify(c => c.Dispose(), Times.Once); sessionClientMocker.VerifyNoOtherCalls(); fallbackClientMocker.VerifyNoOtherCalls(); Assert_AllMethodsThrowObjectDisposedException(routedCacheClient); }
private IRoutedCacheClient CreateRoutedCacheClient(ICacheClient fallbackClient, params IRoutedCacheClientRule[] rules) { IRoutedCacheClient routedCacheClient = new DefaultRoutedCacheClient(fallbackClient); foreach (IRoutedCacheClientRule rule in rules) { routedCacheClient.PushClientWithRule(rule); } return(routedCacheClient); }
public override void Configure(Container container) { //Configure cache client - we're just going to use // another memory cache client instance for session storage ICacheClient fallbackCacheClient = new MemoryCacheClient(); ICacheClient sessionCacheClient = new MemoryCacheClient(); IRoutedCacheClient routedCacheClient = new DefaultRoutedCacheClient(fallbackCacheClient); routedCacheClient.PushServiceStackSessionCacheClient(sessionCacheClient); container.Register <ICacheClient>(routedCacheClient); container.Register <ICacheClientExtended>(routedCacheClient); //Register session feature Plugins.Add(new SessionFeature()); }