public void GetPerformance(int iterations) { // Given const string key = "GetPerformance_Key"; const string value = "GetPerformance_Value"; _cache.Set(key, value); _cache.Get(key); // When var stopwatch = new Stopwatch(); for (var i = 0; i < iterations; ++i) { stopwatch.Start(); _cache.Get(key); stopwatch.Stop(); } // Then var avg = stopwatch.Elapsed.TotalMilliseconds / iterations; Console.WriteLine(@"MemoryCacheImpl.Get()"); Console.WriteLine(@" Iteration count: {0}", iterations); Console.WriteLine(@" Operation time : {0:N4} sec", avg); Console.WriteLine(@" Operation/sec : {0:N4}", 1000 / avg); }
public void ShouldThrowExceptionWhenKeyIsNullOrEmpty(string key) { Assert.Throws <ArgumentNullException>(() => _cache.Contains(key)); Assert.Throws <ArgumentNullException>(() => _cache.Get(key)); Assert.Throws <ArgumentNullException>(() => _cache.Set(key, "value")); Assert.Throws <ArgumentNullException>(() => _cache.Remove(key)); }