public void UpdateHits_EmptyWithMultipleUpdates() { MockRepository mockRepository; Mock <IMultiInstancePerformanceCounterCategory> multiInstancePerformanceCounterCategoryMock; Mock <PercentageRatePerformanceCounter> hitRatePerformanceCounterMock; Mock <NumberOfItems64PerformanceCounter> totalHitsPerformanceCounterMock; Mock <NumberOfItems64PerformanceCounter> totalMissesPerformanceCounterMock; const string cacheName = "foo"; const long hits1 = 42; const long misses1 = 54; const long hits2 = 420; const long misses2 = 540; Queue <HitsAndMisses> queue; mockRepository = new MockRepository(MockBehavior.Strict); hitRatePerformanceCounterMock = mockRepository.Create <PercentageRatePerformanceCounter>(); hitRatePerformanceCounterMock.Setup(pc => pc.Zero()); hitRatePerformanceCounterMock.Setup(pc => pc.AddHits(hits1)); hitRatePerformanceCounterMock.Setup(pc => pc.AddHits(hits2)); hitRatePerformanceCounterMock.Setup(pc => pc.AddMisses(misses1)); hitRatePerformanceCounterMock.Setup(pc => pc.AddMisses(misses2)); hitRatePerformanceCounterMock.Setup(pc => pc.Dispose()); totalHitsPerformanceCounterMock = mockRepository.Create <NumberOfItems64PerformanceCounter>(); totalHitsPerformanceCounterMock.Setup(pc => pc.SetValue(0)); totalHitsPerformanceCounterMock.Setup(pc => pc.IncrementBy(hits1)); totalHitsPerformanceCounterMock.Setup(pc => pc.IncrementBy(hits2)); totalHitsPerformanceCounterMock.Setup(pc => pc.Dispose()); totalMissesPerformanceCounterMock = mockRepository.Create <NumberOfItems64PerformanceCounter>(); totalMissesPerformanceCounterMock.Setup(pc => pc.SetValue(0)); totalMissesPerformanceCounterMock.Setup(pc => pc.IncrementBy(misses1)); totalMissesPerformanceCounterMock.Setup(pc => pc.IncrementBy(misses2)); totalMissesPerformanceCounterMock.Setup(pc => pc.Dispose()); multiInstancePerformanceCounterCategoryMock = mockRepository.Create <IMultiInstancePerformanceCounterCategory>(); multiInstancePerformanceCounterCategoryMock.Setup(mipcc => mipcc.GetPerformanceCounter <PercentageRatePerformanceCounter>(CachePerformanceCounters.HitRateCounterName, cacheName)) .Returns(hitRatePerformanceCounterMock.Object); multiInstancePerformanceCounterCategoryMock.Setup(mipcc => mipcc.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.TotalHitsCounterName, cacheName)) .Returns(totalHitsPerformanceCounterMock.Object); multiInstancePerformanceCounterCategoryMock.Setup(mipcc => mipcc.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.TotalMissesCounterName, cacheName)) .Returns(totalMissesPerformanceCounterMock.Object); queue = new Queue <HitsAndMisses>(); queue.Enqueue(new HitsAndMisses(hits1, misses1)); queue.Enqueue(new HitsAndMisses(hits2, misses2)); using (AsynchronousLoggingCacheMetricReporter metricRepository = new AsynchronousLoggingCacheMetricReporter(multiInstancePerformanceCounterCategoryMock.Object, false, true)) { metricRepository.AddHitsAndMissesCallback(cacheName, queue.Dequeue); AsynchronousLoggingCacheMetricReporter.UpdateHitRates(metricRepository); AsynchronousLoggingCacheMetricReporter.UpdateHitRates(metricRepository); Assert.That(metricRepository, Has.Property("SizeCounters").Empty); Assert.That(metricRepository, Has.Property("HitRateCounters").Property("Keys").EquivalentTo(new[] { cacheName })); Assert.That(metricRepository, Has.Property("TotalHitsCounters").Property("Keys").EquivalentTo(new[] { cacheName })); Assert.That(metricRepository, Has.Property("TotalMissesCounters").Property("Keys").EquivalentTo(new[] { cacheName })); } mockRepository.VerifyAll(); }
public void UpdateHits_Empty() { Mock <IMultiInstancePerformanceCounterCategory> multiInstancePerformanceCounterCategoryMock; multiInstancePerformanceCounterCategoryMock = new Mock <IMultiInstancePerformanceCounterCategory>(); using (AsynchronousLoggingCacheMetricReporter metricRepository = new AsynchronousLoggingCacheMetricReporter(multiInstancePerformanceCounterCategoryMock.Object, false)) { AsynchronousLoggingCacheMetricReporter.UpdateHitRates(metricRepository); Assert.That(metricRepository, Has.Property("SizeCounters").Empty); Assert.That(metricRepository, Has.Property("HitRateCounters").Empty); } }