public void AddHitsAndMissesCallback_Mutliple()
        {
            MockRepository mockRepository;
            Mock <IMultiInstancePerformanceCounterCategory> multiInstancePerformanceCounterCategoryMock;
            Mock <PercentageRatePerformanceCounter>         percentageRatePerformanceCounterMock;
            Mock <NumberOfItems64PerformanceCounter>        totalHitsPerformanceCounterMock;
            Mock <NumberOfItems64PerformanceCounter>        totalMissesPerformanceCounterMock;
            const string cacheName1 = "test1";
            const string cacheName2 = "test2";

            mockRepository = new MockRepository(MockBehavior.Strict);
            percentageRatePerformanceCounterMock = mockRepository.Create <PercentageRatePerformanceCounter>();
            percentageRatePerformanceCounterMock.Setup(pc => pc.Zero());
            percentageRatePerformanceCounterMock.Setup(pc => pc.Dispose());
            totalHitsPerformanceCounterMock = mockRepository.Create <NumberOfItems64PerformanceCounter>();
            totalHitsPerformanceCounterMock.Setup(pc => pc.SetValue(0));
            totalHitsPerformanceCounterMock.Setup(pc => pc.Dispose());
            totalMissesPerformanceCounterMock = mockRepository.Create <NumberOfItems64PerformanceCounter>();
            totalMissesPerformanceCounterMock.Setup(pc => pc.SetValue(0));
            totalMissesPerformanceCounterMock.Setup(pc => pc.Dispose());
            multiInstancePerformanceCounterCategoryMock = mockRepository.Create <IMultiInstancePerformanceCounterCategory>();
            multiInstancePerformanceCounterCategoryMock.Setup(mipcc => mipcc.GetPerformanceCounter <PercentageRatePerformanceCounter>(CachePerformanceCounters.HitRateCounterName, cacheName1))
            .Returns(percentageRatePerformanceCounterMock.Object);
            multiInstancePerformanceCounterCategoryMock.Setup(mipcc => mipcc.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.TotalHitsCounterName, cacheName1))
            .Returns(totalHitsPerformanceCounterMock.Object);
            multiInstancePerformanceCounterCategoryMock.Setup(mipcc => mipcc.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.TotalMissesCounterName, cacheName1))
            .Returns(totalMissesPerformanceCounterMock.Object);
            multiInstancePerformanceCounterCategoryMock.Setup(mipcc => mipcc.GetPerformanceCounter <PercentageRatePerformanceCounter>(CachePerformanceCounters.HitRateCounterName, cacheName2))
            .Returns(percentageRatePerformanceCounterMock.Object);
            multiInstancePerformanceCounterCategoryMock.Setup(mipcc => mipcc.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.TotalHitsCounterName, cacheName2))
            .Returns(totalHitsPerformanceCounterMock.Object);
            multiInstancePerformanceCounterCategoryMock.Setup(mipcc => mipcc.GetPerformanceCounter <NumberOfItems64PerformanceCounter>(CachePerformanceCounters.TotalMissesCounterName, cacheName2))
            .Returns(totalMissesPerformanceCounterMock.Object);

            using (PerformanceCounterLoggingCacheMetricReporter metricReporter =
                       new Mock <PerformanceCounterLoggingCacheMetricReporter>(multiInstancePerformanceCounterCategoryMock.Object).Object)
            {
                metricReporter.AddHitsAndMissesCallback(cacheName1, () => new HitsAndMisses(1, 2));
                metricReporter.AddHitsAndMissesCallback(cacheName2, () => new HitsAndMisses(3, 4));

                Assert.That(metricReporter, Has.Property("HitsAndMissesCallbacks").Property("Keys").EquivalentTo(new[] { cacheName1, cacheName2 }));
                Assert.That(metricReporter, Has.Property("SizeCallbacks").Empty);
            }
        }
        public void AddHitsAndMissesCallback_NullFunc()
        {
            IMultiInstancePerformanceCounterCategory multiInstancePerformanceCounterCategory;

            multiInstancePerformanceCounterCategory = new Mock <IMultiInstancePerformanceCounterCategory>().Object;
            using (PerformanceCounterLoggingCacheMetricReporter metricReporter =
                       new Mock <PerformanceCounterLoggingCacheMetricReporter>(multiInstancePerformanceCounterCategory).Object)
            {
                Assert.That(
                    () => metricReporter.AddHitsAndMissesCallback("test", null),
                    Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("getHitsAndMisses"));
            }
        }
        public void AddHitsAndMissesCallback_InvalidName(string name)
        {
            IMultiInstancePerformanceCounterCategory multiInstancePerformanceCounterCategory;

            multiInstancePerformanceCounterCategory = new Mock <IMultiInstancePerformanceCounterCategory>().Object;
            using (PerformanceCounterLoggingCacheMetricReporter metricReporter =
                       new Mock <PerformanceCounterLoggingCacheMetricReporter>(multiInstancePerformanceCounterCategory).Object)
            {
                Assert.That(
                    () => metricReporter.AddHitsAndMissesCallback(name, () => new HitsAndMisses(1, 1)),
                    Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("name"));
            }
        }