public void StoreTestWithAbsouluteExpiration() { const string expectedKey = "test2"; const string expectedValue = "test2"; const int expirationSeconds = 2; var startTime = DateTime.Now; var time = startTime.AddSeconds(expirationSeconds); GenerateFakeMemoryContext(); var cache = new SystemRuntimeCacheStorage(); cache.Store(expectedKey, expectedValue, time); var retrieved = cache.Retrieve <string>(expectedKey); Assert.AreEqual(expectedValue, retrieved); var timespan = time - startTime; Thread.Sleep(timespan); var retrieved2 = cache.Retrieve <string>(expectedKey); Assert.IsNull(retrieved2); }
public void StoreTestWithSlidingExpiration() { const string expectedKey = "test2"; const string expectedValue = "test2"; const int expirationSeconds = 2; var timespan = new TimeSpan(0, 0, expirationSeconds); GenerateFakeMemoryContext(); var cache = new SystemRuntimeCacheStorage(); cache.Store(expectedKey, expectedValue, timespan); var retrieved = cache.Retrieve <string>(expectedKey); Assert.AreEqual(expectedValue, retrieved); Thread.Sleep(timespan); var retrieved2 = cache.Retrieve <string>(expectedKey); Assert.IsNull(retrieved2); }
static void Main(string[] args) { IProductRepository productRepository = new ProductRepository(); ICacheStorage cacheStorage = new SystemRuntimeCacheStorage(); IConfigurationRepository configurationRepository = new ConfigFileConfigurationRepository(); IContextService contextService = new ThreadContextService(); IFileService fileService = new DefaultFileService(); ILoggingService loggingService = new Log4NetLoggingService(configurationRepository, contextService); // loggingService = new ConsoleLoggingService(); IEmailService emailService = new EmailService(); var productService = new ProductService(productRepository, cacheStorage, configurationRepository, loggingService); var response = productService.GetProduct(new GetProductRequest { Id = 12 }); if (response.Success) { Console.WriteLine(string.Concat("Product name: ", response.Product.Name)); } else { Console.WriteLine(response.Exception); } Console.ReadKey(); }
public void ContainsKeyTest() { GenerateFakeMemoryContext(); var cache = new SystemRuntimeCacheStorage(); Assert.IsTrue(cache.ContainsKey(TestKey)); }
public void RetrieveTest() { GenerateFakeMemoryContext(); var cache = new SystemRuntimeCacheStorage(); var retrieved = cache.Retrieve <string>(TestKey); Assert.AreEqual(TestValue, retrieved); }
public void ContainsKeyNonExistingTest() { var tmpKey = TestKey + "123"; GenerateFakeMemoryContext(); var cache = new SystemRuntimeCacheStorage(); Assert.IsFalse(cache.ContainsKey(tmpKey)); }
public void RetrieveNonExistingTest() { var tmpKey = TestKey + "123"; GenerateFakeMemoryContext(); var cache = new SystemRuntimeCacheStorage(); var retrieved = cache.Retrieve <string>(tmpKey); Assert.IsNull(retrieved); }
public void RemoveTest() { GenerateFakeMemoryContext(); var cache = new SystemRuntimeCacheStorage(); cache.Remove(TestKey); var retrieved = cache.Retrieve <string>(TestKey); Assert.IsNull(retrieved); }
public void StoreTest() { const string expectedKey = "test2"; const string expectedValue = "test2"; GenerateFakeMemoryContext(); var cache = new SystemRuntimeCacheStorage(); cache.Store(expectedKey, expectedValue); var retrieved = cache.Retrieve <string>(expectedKey); Assert.AreEqual(expectedValue, retrieved); }