Exemplo n.º 1
0
        public void UpdateSizes_EmptyWithOneUpdate()
        {
            MockRepository mockRepository;
            Mock <IMultiInstancePerformanceCounterCategory> multiInstancePerformanceCounterCategoryMock;
            Mock <NumberOfItems64PerformanceCounter>        numberOfItems64PerformanceCounterMock;
            const string cacheName = "foo";
            const long   cacheSize = 42;
            Queue <long> queue;

            mockRepository = new MockRepository(MockBehavior.Strict);
            numberOfItems64PerformanceCounterMock = mockRepository.Create <NumberOfItems64PerformanceCounter>();
            numberOfItems64PerformanceCounterMock.Setup(pc => pc.SetValue(0));
            numberOfItems64PerformanceCounterMock.Setup(pc => pc.SetValue(cacheSize));
            numberOfItems64PerformanceCounterMock.Setup(pc => pc.Dispose());
            multiInstancePerformanceCounterCategoryMock = mockRepository.Create <IMultiInstancePerformanceCounterCategory>();
            multiInstancePerformanceCounterCategoryMock.Setup(mipcc => mipcc.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.SizeCounterName, cacheName))
            .Returns(numberOfItems64PerformanceCounterMock.Object);

            queue = new Queue <long>();
            queue.Enqueue(cacheSize);

            using (AsynchronousLoggingCacheMetricReporter metricRepository = new AsynchronousLoggingCacheMetricReporter(multiInstancePerformanceCounterCategoryMock.Object, false))
            {
                metricRepository.AddSizeCallback(cacheName, queue.Dequeue);

                AsynchronousLoggingCacheMetricReporter.UpdateSizes(metricRepository);

                Assert.That(metricRepository,
                            Has.Property("SizeCounters").Property("Keys").EquivalentTo(new[] { cacheName }));
                Assert.That(metricRepository, Has.Property("HitRateCounters").Empty);
            }

            mockRepository.VerifyAll();
        }
Exemplo n.º 2
0
        public void UpdateSizes_Empty()
        {
            Mock <IMultiInstancePerformanceCounterCategory> multiInstancePerformanceCounterCategoryMock;

            multiInstancePerformanceCounterCategoryMock = new Mock <IMultiInstancePerformanceCounterCategory>();

            using (AsynchronousLoggingCacheMetricReporter metricRepository = new AsynchronousLoggingCacheMetricReporter(multiInstancePerformanceCounterCategoryMock.Object, true))
            {
                AsynchronousLoggingCacheMetricReporter.UpdateSizes(metricRepository);

                Assert.That(metricRepository, Has.Property("SizeCounters").Empty);
                Assert.That(metricRepository, Has.Property("HitRateCounters").Empty);
            }
        }